Network Router
Controlling the flow of execution between agents in a Network.
The defaultRouter
option in createNetwork
defines how agents are coordinated within a Network. It can be either a Function Router or a Routing Agent.
Function Router
A function router is provided to the defaultRouter
option in createNetwork
.
Example
Parameters
The original input provided to the network.
The network instance, including its state and history.
See Network.State
for more details.
The list of future agents to be called. (internal read-only value)
The number of agent calls that have been made.
The result from the previously called agent.
See InferenceResult
for more details.
Return Values
Return Type | Description |
---|---|
Agent | Single agent to execute next |
Agent[] | Multiple agents to execute in sequence |
RoutingAgent | Delegate routing decision to another routing agent |
undefined | Stop network execution |
createRoutingAgent()
Creates a new routing agent that can be used as a defaultRouter
in a network.
Example
Parameters
The name of the routing agent.
Optional description of the routing agent’s purpose.
Optional model to use for routing decisions. If not provided, uses the network’s defaultModel
.
Returns
Returns a RoutingAgent
instance that can be used as a network’s defaultRouter
.