# Agents constructor

**URL:** <https://discourse.julialang.org/t/agents-constructor/115941>\
**Category:** New to Julia\
**Tags:** agents, agentsjl\
**Created:** [June 20, 2024, 6:19pm UTC](https://discourse.julialang.org/t/agents-constructor/115941 "2024-06-20T18:19:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_sanchez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martin_sanchez/32/207525_2.png) [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Post date:** [June 20, 2024, 6:19pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/1 "2024-06-20T18:19:30Z")

</div>

Hi, I have two questions:  
On the first hand, quite recent videos explaining the use showed a use of the @agents macro as

```julia
@agents NameAgentType GridAgent{2} begin
      someField
  end

```

And when I do this with this syntaxis it actually works. The docs instead say the way to go is

```julia
@agent struct YourAgentType{X}(AgentTypeToInherit) [<: OptionalSupertype]
    extra_property::X
    other_extra_property_with_default::Bool = true
    const other_extra_const_property::Int
    # etc...
end

```

And it says that it supports Julia mutable struct declaration but when I run

```julia
@agent mutable struct Client(NoSpaceAgent) 
    fieldA::Float64
end

```

It shows an error:

```julia
ERROR: LoadError: MethodError: no method matching namify(::Nothing)

Closest candidates are:
  namify(::Expr)
   @ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:132
  namify(::Symbol)
   @ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:131

Stacktrace:
 [1] compute_base_fields(base_type_spec::Nothing)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:404
 [2] _agent(struct_repr::Expr)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:206
 [3] var"@agent"( __source__ ::LineNumberNode, __module__ ::Module, struct_repr::Any)
   @ Agents ~/.julia/packages/Agents/gV8cz/src/core/agents.jl:200
in expression starting at /home/msanchezr/RevAIsor/ABM/sim.jl:44

```

Though it apparently works when I remove the “mutable” it haunts me that it supports a documented synthax but not one it says it does.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [June 20, 2024, 6:31pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/2 "2024-06-20T18:31:36Z")

</div>

You’re looking at mismatched versions here between the tutorial, the docs, and your installed version. It looks like the tutorial is using v5, which matches what you currently have installed. But you’re looking at the docs for v6. Use the dropdown on the bottom left of the docs to pick the version you’re using — it might be: [https://juliadynamics.github.io/Agents.jl/v5.17/tutorial/](https://juliadynamics.github.io/Agents.jl/v5.17/tutorial/).

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 20, 2024, 8:19pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/3 "2024-06-20T20:19:32Z")

</div>

> [@martin\_sanchez](#):
>
> And it says that it supports any declaration (for example mutable structu)

I guess saying it supports “any” declaration is probably not an accurate statement, as it doesn’t apply to `mutable`. Because it is already added by de facto. All `@agent` created types are `mutable` already, so you are trying to add an extra `mutable` and that doesn’t work. This should clarified in the docs (if it isn’t already?).

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 20, 2024, 8:20pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/4 "2024-06-20T20:20:12Z")

</div>

as for your first question, we allowed (internally) the first version you posted to work for backwards compatibility. It is not supported in any official sense and may be removed in future versions without any warning.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 20, 2024, 8:35pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/5 "2024-06-20T20:35:26Z")

</div>

@martin_sanchez this post here and the one you just opened about DynamicalSystems.jl are pretty much the same problem: attempting to use too old versions that use InteractiveDynamics.jl. Can I ask, where did you find the advice to use this? Probably some outdated tutorial that exists somewhere and needs to be deleted.

---

<div class="post-metadata">

**Author:** ![martin\_sanchez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martin_sanchez/32/207525_2.png) [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Post date:** [June 20, 2024, 9:55pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/6 "2024-06-20T21:55:07Z")

</div>

Yes, it seems like it. This one uses the outdated construction method:  
https://www.youtube.com/embed/Qx19RfaYubI?feature=oembed&wmode=opaque&list=PLHOMZ3TUd5FpgtOabDhCpQE3nwIsMh_DB

And this one uses InteractiveDynamics:

[![](https://global.discourse-cdn.com/julialang/original/3X/e/5/e588f871d3735912ae4a1e78742baa43d3989d25.jpeg "Agents.jl | George Datseris | Julia User Group Munich - Share&Code") ](https://www.youtube.com/watch?v=DJSHXXjkwLY)

---

<div class="post-metadata">

**Author:** ![martin\_sanchez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martin_sanchez/32/207525_2.png) [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Post date:** [June 20, 2024, 9:57pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/7 "2024-06-20T21:57:34Z")

</div>

Thanks. I currently have v6.0.15, but already read that this way of calling the macro can be delted without warning in future versions.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 21, 2024, 7:41am UTC](https://discourse.julialang.org/t/agents-constructor/115941/8 "2024-06-21T07:41:20Z")

</div>

Oh well, I can’t affect either of these videos.

Videos cannot be updated to newer versions. My advice would be to not use videos to learn code. At least, not for the packages of JuliaDynamics. The documentation is as good as it can possible get, and always up to date. Start there!

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 21, 2024, 2:09pm UTC](https://discourse.julialang.org/t/agents-constructor/115941/10 "2024-06-21T14:09:07Z")

</div>

every documentation page has an edit button at the top right. It is super easy to contribute to documentation.
