import { createRoutingAgent, createNetwork } from "@inngest/agent-kit";const routingAgent = createRoutingAgent({ name: "Custom routing agent", description: "Selects agents based on the current state and request", lifecycle: { onRoute: ({ result, network }) => { // Get the agent names from the result const agentNames = result.output .filter((m) => m.type === "text") .map((m) => m.content as string); // Validate that the agents exist return agentNames.filter((name) => network.agents.has(name)); }, },});// classifier and writer Agents definition...const network = createNetwork({ agents: [classifier, writer], router: routingAgent,});
Called after each inference to determine the next agent(s) to call.
Arguments:
{ result: InferenceResult; // The result from the routing agent's inference agent: RoutingAgent; // The routing agent instance network: Network; // The network instance}
Returns:string[] - Array of agent names to call next, or undefined to stop execution