new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

LangChain · Agents · all subjects

agents/middleware/steering

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Steering middleware for human-in-the-loop approval

Steering middleware lets you place humans at specific decision points—before destructive writes, expensive API calls, or anything requiring judgment—without restructuring your agent. The agent pauses and waits; a human approves, edits, or rejects; execution continues. This is provided by HumanInTheLoopMiddleware.

Backward transitions with 'go back' tools

Workflow flexibility can be added using special tools that return Command(update={'current_step': earlier_step_name}). For example, go_back_to_warranty and go_back_to_classification allow users to correct information and restart collection from a previous step. This pattern works best when backward transitions are infrequent and between specific steps.

Router pattern advantages

The router pattern provides several advantages: parallel execution (query multiple sources simultaneously, reducing latency), specialized agents (each vertical has focused tools and prompts optimized for its domain), selective routing (not every query needs every source—the router intelligently selects relevant verticals), targeted sub-questions (each agent receives a question tailored to its domain, improving result quality), and clean synthesis (results from multiple sources are combined into a single, coherent response).

Router vs Subagents pattern

Use the router pattern when you need specialized preprocessing, custom routing logic, or want explicit control over parallel execution. Use the subagents pattern when you want the LLM to decide which agents to call dynamically. The subagents pattern can also route to multiple agents but with less explicit control.

Router pattern overview

The router pattern is a multi-agent architecture where a routing step classifies input and directs it to specialized agents, with results synthesized into a combined response. The router pattern excels when an organization's knowledge lives across distinct verticals (separate knowledge domains that each require their own agent with specialized tools and prompts).

StateGraph workflow nodes for router

A router workflow has four main nodes: Classify (analyze the query and determine which agents to invoke with what sub-questions), Route (fan out to selected agents in parallel using Send), Query agents (each agent receives a simple AgentInput and returns an AgentOutput), and Synthesize (combine collected results into a coherent response).

Parallel execution with Send

The route_to_agents function maps classifications to Send objects. Each Send specifies the target node and the state to pass. Send objects enable parallel execution where multiple agents execute simultaneously. Each agent node receives a simple AgentInput with just a query field—not the full router state. This keeps the interface clean and explicit.

add_conditional_edges for parallel execution

The add_conditional_edges call connects the classify node to the agent nodes through the route_to_agents function. When route_to_agents returns multiple Send objects, those nodes execute in parallel. Syntax: .add_conditional_edges("classify", route_to_agents, ["github", "notion", "slack"])

Synthesis phase execution

After all agents complete, the synthesize_results function iterates over the collected results. LangGraph handles waiting for all parallel branches to complete automatically. The function references the original query to ensure the answer addresses what the user asked, and combines information from all sources without redundancy.

Router pattern three phases

The router pattern has three phases: decompose (analyze the query and generate targeted sub-questions for relevant sources), route (execute queries in parallel using Send), and synthesize (combine results from all sources without redundancy into a coherent answer).

Multi-source knowledge base router example scenario

The example demonstrates a realistic enterprise scenario coordinating three specialists: a GitHub agent that searches code, issues, and pull requests; a Notion agent that searches internal documentation and wikis; and a Slack agent that searches relevant threads and discussions. When a user asks 'How do I authenticate API requests?', the router decomposes the query into source-specific sub-questions, routes them to relevant agents in parallel, and synthesizes results into a coherent answer.

Give your agent this brain