Networks
Combine one or more agents into a Network
Networks are Systems of Agents. Use Networks to create complex, stateful workflows with one or more Agents.
A network contains three components:
- The Agents that the network can access
- State, including past messages and a key value store
- A Router, which chooses whether to quit or the next agent to run in the loop
It also has an optional default model, which will be used when your Agents have no model provided, and a setting to cap the number of model calls via maxIter
.
Here’s a simple example:
Similar to agents, you call run()
on a network with some user input. The network then runs a core loop to call one or more agents to find a suitable answer.
How Networks work
Networks can be thought of as while loops with memory that call Agents and Tools until the Router determines that there is no more work to be done.
Create the Network of Agents
You create a network with a list of available Agents. Each Agent can use a different model and inference provider.
Provide the staring prompt
You give the network a user prompt by calling run()
.
Core execution loop
The network runs its core loop:
Call the Network router
The Router decides the first Agent to run with your input.
Run the Agent
Call the Agent with your input. This also runs the agent’s lifecycles, and any Tools that the model decides to call.
Store the result
Stores the result in the network’s State. State can be accessed by the Router or other Agent’s Tools in future loops.
Call the the Router again ↩️
Return to the top of the loop and calls the Router with the new State. The Router can decide to quit or run another Agent.