> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agenticenv.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiple Agents

> Run several agents in one process

**The problem:** You need more than one agent in the same process — different system prompts or roles.

**The solution:** Create one `NewAgent` per role, each with its own distinct [`WithName`](/getting-started/configuration).

```go theme={null}
cfg := &temporal.TemporalConfig{
    Host: "localhost", Port: 7233, Namespace: "default",
    TaskQueue: "my-app",
}

a1, _ := agent.NewAgent(
    agent.WithName("math-agent"),
    temporal.WithTemporalConfig(cfg),
    agent.WithLLMClient(llmClient),
)
defer a1.Close()

a2, _ := agent.NewAgent(
    agent.WithName("writing-agent"),
    temporal.WithTemporalConfig(cfg),
    agent.WithLLMClient(llmClient),
)
defer a2.Close()
```

Use the **same** options on `NewAgent` and `NewAgentWorker` for a given agent so client and worker pair correctly.

### Restate

Same process: set a distinct `Endpoint.ListenAddress` per agent.

```go theme={null}
a1, _ := agent.NewAgent(
    agent.WithName("math-agent"),
    restate.WithRestateConfig(&restate.RestateConfig{
        Ingress: restate.IngressConfig{URL: "http://localhost:8080"},
        Endpoint: restate.EndpointConfig{
            ListenAddress: ":9081",
            AdminURL:      "http://localhost:9070",
        },
    }),
    agent.WithLLMClient(llmClient),
)
defer a1.Close()

a2, _ := agent.NewAgent(
    agent.WithName("writing-agent"),
    restate.WithRestateConfig(&restate.RestateConfig{
        Ingress: restate.IngressConfig{URL: "http://localhost:8080"},
        Endpoint: restate.EndpointConfig{
            ListenAddress: ":9082",
            AdminURL:      "http://localhost:9070",
        },
    }),
    agent.WithLLMClient(llmClient),
)
defer a2.Close()
```

See [Restate runtime](/runtimes/restate) and the [Multiple Agents](/examples/multiple-agents) example.

Register specialists on the main agent with [`WithSubAgents`](/features/sub-agents). Sub-agent names must differ from the root agent name.

## Same process, concurrent runs

### Single agent, multiple requests

A single `Agent` instance handles **concurrent `Run` and `Stream` calls** from different goroutines. Each call gets its own unique Temporal workflow (or in-process goroutine) — no serialisation, no queuing.

```go theme={null}
var wg sync.WaitGroup
for _, prompt := range prompts {
    wg.Add(1)
    go func(p string) {
        defer wg.Done()
        agentRun, _ := a.Run(ctx, p, nil)
        result, _ := agentRun.Get(ctx)
        fmt.Println(result.Content)
    }(prompt)
}
wg.Wait()
```

Use this when one agent definition serves many parallel requests — a single `Agent` object is all you need.

Example: [Concurrent Runs](/examples/concurrent-runs).

### Multiple agents, concurrent runs

```go theme={null}
var wg sync.WaitGroup
wg.Add(2)
go func() {
    defer wg.Done()
    agentRun, _ := a1.Run(ctx, "What is 7 times 8?", nil)
    result, _ := agentRun.Get(ctx)
    fmt.Println(result.Content)
}()
go func() {
    defer wg.Done()
    agentRun, _ := a2.Run(ctx, "Write a haiku about rain.", nil)
    result, _ := agentRun.Get(ctx)
    fmt.Println(result.Content)
}()
wg.Wait()
```

Example: [Multiple Agents](/examples/multiple-agents).

## Shared vs separate resources

| Resource | Per agent or shared |
| - | - |
| LLM client | Can share one client across agents — use [`WithLLMSampling`](/getting-started/configuration) for per-agent overrides |
| Temporal config | Can reuse the same `TemporalConfig` across agents |
| Restate in one process | Give each agent its own `ListenAddress` |
| Conversation store | Shared backend OK — isolate by conversation ID |
| Memory store | Shared backend OK — isolate by scope (user, tenant, agent name) |
| Tool registries | **Per agent** — each `Agent` has its own registries |

## Distributed execution with multiple agents

When splitting client and worker:

1. Create one `NewAgentWorker` **per agent**
2. Pass matching options to each worker and its corresponding `NewAgent`
3. Use Redis conversation when any agent uses remote workers

See [Distributed Execution](/advanced/distributed-execution).

## In-process runtime

Multiple in-process agents (no Temporal/Restate) are also supported — omit Temporal and Restate options on each `NewAgent`. Each agent runs its loop inside your Go process. Use this for development and single-process deployments.

See [In-Process runtime](/runtimes/in-process).

## Examples

<CardGroup cols={2}>
  <Card title="Concurrent Runs" icon="bolt" href="/examples/concurrent-runs" horizontal>
    Fan-out on a single Agent instance
  </Card>

  <Card title="Multiple Agents" icon="play" href="/examples/multiple-agents" horizontal>
    Several agents in one process
  </Card>
</CardGroup>

## Related

<CardGroup cols={2}>
  <Card title="Sub-agents" icon="sitemap" href="/features/sub-agents" horizontal>
    Orchestrator + specialist pattern
  </Card>

  <Card title="Distributed Execution" icon="server" href="/advanced/distributed-execution" horizontal>
    Client and worker pairing
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.