liveBook · Manning

Branch

As explained in Building Reliable AI Systems

Conditional routing is the technique of directing execution to different agents or workflow paths according to the current request or state.

Conditional routing directs a request to the agents needed for its intent. Semantic analysis can identify multiple needs, letting a workflow invoke one agent or coordinate several rather than relying on brittle keyword matching. section 8.1.3

A request with two needs

A customer asks whether similar boots are available in waterproof material, then asks about the return policy. The workflow can route the product need to search and the policy question to Q&A. section 8.0

async def analyze_intent(query: str) -> dict:
    """AI-powered intent analysis using function calling for reliability"""

    intent_llm = ChatOpenAI(model="gpt-5.4-mini”)

    tools = [{    #1
        "type": "function",
        "function": {
            "name": "analyze_intent", 
            "description": "Analyze customer intent",
            "parameters": {
                "type": "object",
                "properties": {
                    "search_needed": {"type": "boolean"},
                    "qa_needed": {"type": "boolean"},
                    "reasoning": {"type": "string"}
                },
                "required": ["search_needed", "qa_needed", "reasoning"]
            }
        }
    }]
    messages = [{"role": "user", "content": f"Analyze this customer query:
        {query}"}]
    response = await intent_llm.ainvoke(messages, tools=tools,
        tool_choice="required")

    if hasattr(response, 'tool_calls') and response.tool_calls:
        args = response.tool_calls[0]["args"]
        return args

    return {"search_needed": True, "qa_needed": False, "reasoning":
       "Fallback"}   #2

The intent-analysis function uses structured function calling to produce search-needed and Q&A-needed flags, plus reasoning. section 8.1.3

def route_based_on_intent(state: ConversationState) -> str:
    """Route to appropriate agents based on analyzed intent"""

    analysis = state["intent_analysis"]

    if analysis["search_needed"] and analysis["qa_needed"]:
        return "both_needed"      #1
    elif analysis["search_needed"]:   #1
        return "search_agent"    #1
    elif analysis["qa_needed"]:    #1
        return "policy_agent"    #1
    else: #1
        return "search_agent"   #2

workflow.add_conditional_edges(    #3
    "analyze_intent",   #3
    route_based_on_intent,  #3
    {   #3
        "both_needed": "search_agent",    #3
        "search_agent": "search_agent",  #3
        "policy_agent": "policy_agent" #3
    }   #3
)  #3

A routing function maps those flags to a search agent, a policy agent, or a combined path, then connects the choices with LangGraph conditional edges. section 8.1.3

How Building Reliable AI Systems covers it

How deep it goes
Explains semantic intent analysis and conditional-edge decisions, but leaves routing evaluation unspecified.
Examples
Uses combined product-search and return-policy questions to illustrate routing multiple needs.
What you can do after
Apply it via LangGraph to map analyzed search and Q&A needs to specialized-agent nodes.
How it connects
Connects LangGraph conditional edges with intent analysis, shared state, and specialized agents.

Also explained in

Compare how 6 books explain branch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.