# Type parametrisation and the @agent macro

**URL:** <https://discourse.julialang.org/t/type-parametrisation-and-the-agent-macro/114846>\
**Category:** New to Julia\
**Tags:** agents, agentsjl\
**Created:** [May 28, 2024, 3:02pm UTC](https://discourse.julialang.org/t/type-parametrisation-and-the-agent-macro/114846 "2024-05-28T15:02:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefkuypers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefkuypers/32/19185_2.png) [@stefkuypers](https://discourse.julialang.org/u/stefkuypers)\
**Post date:** [May 28, 2024, 3:02pm UTC](https://discourse.julialang.org/t/type-parametrisation-and-the-agent-macro/114846/1 "2024-05-28T15:02:16Z")

</div>

Is it possible to use type parametrisation with the @agent macro?

This is what I’d like to do:

```julia
@agent struct AnAgent(NoSpaceAgent){C} <: AbstractAgent{C <: FixedDecimal}
  balance::C
end
```

But this syntax clearly does not work since I get the following 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/8JW8b/src/core/agents.jl:405
 [2] _agent(struct_repr::Expr)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/core/agents.jl:206
 [3] var"@agent"( __source__ ::LineNumberNode, __module__ ::Module, struct_repr::Any)
   @ Agents ~/.julia/packages/Agents/8JW8b/src/core/agents.jl:200
in expression starting at REPL[2]:1
```

I admit I have not really looked at how macros work exactly. I do know it has to do with how the macro functions though but is there a way to make type parametrisation work here?

---

<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:** [May 28, 2024, 3:14pm UTC](https://discourse.julialang.org/t/type-parametrisation-and-the-agent-macro/114846/2 "2024-05-28T15:14:22Z")

</div>

Yes, put the `C` before the parenthesis, see here for the full syntax:

> **[API · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/api/#Agents.%40agent)**
>
> Documentation for Agents.jl.

Notice that you should not put the `C` into the `AbstractAgent` supertype, as it doesn’t have parametric types itself. You can define your own supertype `abstract type MySuperAgent{C} <: AbstractAgent` instead.
