# How to trace positions of agents

**URL:** https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340
**Category:** Modelling & Simulations
**Tags:** agents, agentsjl
**Created:** [January 30, 2026, 10:36am UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340 "2026-01-30T10:36:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ahcvankampen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahcvankampen/32/219110_2.png) [@ahcvankampen](https://discourse.julialang.org/u/ahcvankampen)
#### Post date: [January 30, 2026, 10:36am UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/1 "2026-01-30T10:36:11Z")

</div>

Hi,  
I have a multiagent model and want to extract agent data from this model. In one of the tutorial examples we have something like:

adata = [(cd4, count), (cd8, count), (dc, count)]  
fig, ax, abmobs = abmplot(ln\_model; plotkwargs…, adata, mdata)

But…I don’t want to count, but follow the positions of all individual agents (cd4, cd8, and dc) over time. How can I accomplish this?  
Thanks,  
Antoine

---

<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: [January 30, 2026, 11:13am UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/2 "2026-01-30T11:13:04Z")

</div>

hi, It is not clear to me whether e.g., `cd4` is an individual agent or an agent _type_ for which you want the mean position. the answer depends on that.

---

<div class="post-metadata">

### Author: ![ahcvankampen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahcvankampen/32/219110_2.png) [@ahcvankampen](https://discourse.julialang.org/u/ahcvankampen)
#### Post date: [January 30, 2026, 11:23am UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/3 "2026-01-30T11:23:16Z")

</div>

It is the same as shown in the predator prey example : [Predator-prey dynamics · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/examples/predator_prey/)  
with  
adata = [(sheep, count), (wolf, count)]

Thus, it are individual agents.

---

<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: [January 30, 2026, 11:41am UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/4 "2026-01-30T11:41:26Z")

</div>

I am sorry but you are confusing me. The predator prey model counts how many agents of _TYPE_ sheep there are, and of type wolf. Then you claim it is individual agents. Can you please tell me what **you** would like to achieve by answering my original question directly?

To answer in advance what I think you want:

```julia-auto
agent_ids = [1, 2, 3] # IDs of agents to track pos of
mdata = [
    model -> model[id].pos for id in agent_ids
]

```

which wil lcollect the position of agents with specified IDs only.

---

<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: [January 30, 2026, 12:15pm UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/5 "2026-01-30T12:15:38Z")

</div>

(note how you should _not_ use `adata` in this case as you are not aggregating over agents, you just need specific agents instead)

---

<div class="post-metadata">

### Author: ![ahcvankampen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahcvankampen/32/219110_2.png) [@ahcvankampen](https://discourse.julialang.org/u/ahcvankampen)
#### Post date: [January 30, 2026, 12:23pm UTC](https://discourse.julialang.org/t/how-to-trace-positions-of-agents/135340/6 "2026-01-30T12:23:39Z")

</div>

Hi Datseris, thanks. I noticed.

Indeed the trick was to do this on the model level. Tracing the x position of one agent:  
mdata = [x → x[1].pos[1]]
