liveBook · Manning

Agent orchestration

As explained in Build an Advanced RAG Application (From Scratch)

An orchestration pattern coordinates multiple processing components and branches their execution into an end-to-end workflow.

Orchestration coordinates routing, retrieval, web search, and response generation into one end-to-end enterprise RAG workflow. A handler interprets the router result, bypasses retrieval for direct answers, branches to web search, or queries the route-specific vector collection. section 7.2.2

A practical orchestration flow performs these steps:

  • Route the query and extract its action, reason, and optional short answer. section 7.2.2
  • Return a router-provided answer immediately when available. section 7.2.2
  • Send WEB_SEARCH requests to web search, then format the results as a response. section 7.2.2
  • Embed internal-document queries, retrieve three points asynchronously from the mapped Qdrant collection, and generate a cited answer. section 7.2.2

Representative routing

An OpenAI Assistant question selects OPENAI_QUERY; Uber gross bookings selects 10K_DOCUMENT_QUERY; current open-source LLM trends select WEB_SEARCH. section 7.2.2

async def handle_query(user_query: str) -> str:
    route_result = route_query(user_query)                      #A
    action = route_result["action"]
    reason = route_result["reason"]
    short_answer = route_result.get("answer", "")
 
    print(f"Route: {action}")
    print(f"Reason: {reason}")
 
    if short_answer:                                            #B
        return short_answer
 
    if action == "WEB_SEARCH":                              #C
        search_results = search_web(user_query)
        return rag_formatted_response(user_query, search_results)
 
    return await retrieve_and_response(user_query, action)      #D

Inspect the central async handler that connects routing, short answers, web search, retrieval, and response generation. section 7.2.2

How Build an Advanced RAG Application (From Scratch) covers it

How deep it goes
Descends to Python control flow, route dispatch, embeddings, Qdrant retrieval, and formatted response generation.
Examples
Uses OpenAI documentation, 10-K financial queries, web-search questions, and representative routing tests.
What it assumes
Assumes familiarity with routing, embeddings, vector search, asynchronous calls, and response generation patterns.
What you can do after
Build it from scratch by connecting a router to web search, vector retrieval, and cited response generation.
How it connects
Connects query routing, embeddings, vector search, retrieval-augmented generation, and response generation.

Also explained in

Compare how 19 books explain agent orchestration →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an Advanced RAG Application (From Scratch). The section links point to the parts of the book it draws on.