Dynamic agent configuration
A single agent needs to switch prompts or available tools based on the current workflow state.
AI Agents · Const
Handoffs use tools and state updates to change an agent's behavior or route execution to another agent. They can be implemented with middleware in one agent or with multiple agent subgraphs.
A handoff is implemented as a tool-driven state transition: the tool returns a Command that updates state and changes the next step or agent. For subgraph handoffs, Command.PARENT routes to another agent node, while the triggering AIMessage and an acknowledging ToolMessage keep the conversation history valid.
new Command({ goto, update })A Command that updates state and triggers routing to a new step or agent.
import { Command } from "@langchain/langgraph";
const handoff = new Command({
goto: "specialist",
update: { active_agent: "specialist" },
});Creates a command that updates workflow state and routes execution to a specialist node.
A single agent needs to switch prompts or available tools based on the current workflow state.
A request must move from one specialist agent to another.
A workflow uses distinct graph-based agents and needs explicit control over the messages passed between them.
CommandCommand.PARENTToolMessageAIMessagehandoffsmiddlewareagent subgraphs