Pools
Learn how pools enable multi-agent collaboration and intelligent task routing.
A Pool coordinates multiple agents so they can work together on a task. It brings structure to multi-agent workflows by deciding how agents interact and how information flows between them.
-
Each Agent focuses on a specific skill or responsibility and contributes its part of the work.
-
A shared State lets all agents access and update the same context, allowing them to build on each other’s progress.
-
The Router decides which agent should act next, using either round-robin or intelligent LLM-based routing.
Creating a Pool
Use create_pool() function to coordinate multiple agents. The agents parameter accepts a list of all the agents you want to include in the pool.
from peargent import create_agent, create_pool
from peargent.models import groq
# researcher agent and write agent
# Create pool
pool = create_pool(
agents=[researcher, writer],
)
# Run the pool along with user input
result = pool.run("Research and write about quantum computing")How a Pool Works
A Pool can be thought of as a controller that organizes multiple agents, maintains a shared State for them to collaborate through, and uses a Router to decide which agent should act next.
User Input Added to State
The user’s message is written into the shared State so every agent can access it.
Router Selects the Next Agent
The Router determines which agent should act next.
Agent Executes and Updates State
The selected agent processes the task, produces an output, and writes its result back into the State.
Output Becomes Input for the Next Agent
Each agent’s output is available in the State, allowing the next agent to build on prior work.
Process Repeats Until Completion
The cycle continues until the workflow is complete or the maximum number of iterations is reached.
Model Selection
By default, the pool uses the model of the first agent. You can also provide a default_model for the pool. Any agent without an explicitly set model will use this default_model.
from peargent import create_pool
from peargent.models import openai
# researcher agent, analyst agent and writer agent
# Create pool
pool = create_pool(
agents=[researcher, analyst, writer],
default_model=openai("gpt-5")
)All the available models are listed in Models.
Routing the Agents
By default, pools use round-robin routing, where Agents take turns in order. You can also plug in a custom router to make more intelligent decisions based on the task.
For all routing options, including round-robin, LLM-based routing, and custom router functions, see the Routers .
from peargent import create_pool
pool = create_pool(
agents=[researcher, analyst, writer],
)
article = pool.run("Write an article about renewable energy trends")
# Executes: researcher → analyst → writerMax Iterations
A pool runs for a fixed number of iterations, where each iteration represents one agent being routed, executed, and updating the state. Pools use a default limit of 5 iterations, but you can change this using the max_iter parameter.
from peargent import create_pool
pool = create_pool(
agents=[researcher, analyst, writer],
max_iter=10
)
article = pool.run("Write an article about renewable energy trends")
# Executes: researcher → analyst → writer → researcher → analyst → writer → ...Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
agents | list[Agent] | List of agents in the pool | Yes |
default_model | Model | Default model for agents without one | No |
router | RouterFn | RoutingAgent | Custom router function or routing agent (default: round-robin) | No |
max_iter | int | Maximum agent executions (default: 5) | No |
default_state | State | Custom initial state object | No |
history | HistoryConfig | Shared conversation history across all agents | No |
tracing | bool | Enable tracing for all agents (default: False) | No |
For advanced configuration like history and tracing, see the Advanced Features.