liveBook · Manning

Graph-based workflow

As explained in AI Agents and Applications

A graph structure is a workflow organization in which nodes and edges define execution order and data flow, potentially including dynamic branches.

A graph-based workflow organizes a multi-step application around nodes, edges, and shared state. Nodes perform tasks, edges define execution order and data flow, and state carries information between steps. This structure becomes useful when a process must branch, remember intermediate results, or repeat work instead of following one rigid chain. section 5.2 section 5.3

Build the workflow incrementally:

  • Define a state structure containing the question, intermediate search data, evaluations, control flags, and final output. section 5.5.3
  • Convert each responsibility into a node function that reads the current state and returns updates. section 5.5.3
  • Register nodes and connect them to establish execution order and data flow. section 5.5.3
  • Add conditional edges that route execution according to intermediate results, such as relevance evaluation. section 5.5.3
  • Compile the graph, invoke it with an initial state, and read the resulting output. section 5.5.3

Adaptive research assistant

A research workflow selects an assistant, generates search queries, performs searches, summarizes results, evaluates relevance, and writes a report. If fewer than half the summaries are relevant, a conditional route regenerates queries; after three iterations, the workflow proceeds to report writing. section 5.5.3

Listing 5.2 State type of the LangGraph-based research assistant
from typing import List, Dict, Any, TypedDict, Optional

class AssistantInfo(TypedDict):  #1
    assistant_type: str
    assistant_instructions: str
    user_question: str

class SearchQuery(TypedDict):  #1
    search_query: str
    user_question: str

class SearchResult(TypedDict):  #1
    result_url: str
    search_query: str
    user_question: str
    is_fallback: Optional[bool]

class SearchSummary(TypedDict):  #1
    summary: str
    result_url: str
    user_question: str
    is_fallback: Optional[bool]

class ResearchReport(TypedDict):  #1
    report: str

class ResearchState(TypedDict):  #2
    user_question: str
    assistant_info: Optional[AssistantInfo]
    search_queries: Optional[List[SearchQuery]]
    search_results: Optional[List[SearchResult]]
    search_summaries: Optional[List[SearchSummary]]
    research_summary: Optional[str]
    final_report: Optional[str]
    used_fallback_search: Optional[bool]
    relevance_evaluation: Optional[Dict[str, Any]]
    should_regenerate_queries: Optional[bool]
    iteration_count: Optional[int]

Inspect the typed state used to pass questions, search data, evaluations, control flags, and report fields through the workflow. section 5.5.3

How AI Agents and Applications covers it

How deep it goes
Defines state, node functions, edges, conditional routing, compilation, and execution, stopping short of framework internals.
Examples
Uses a research assistant with relevance-based query regeneration and a router connecting travel and accommodation agents.
What you can do after
Build it from scratch by defining typed state, implementing node functions, routing conditionally, compiling the graph, and invoking it.
How it connects
Connects LangGraph with LangChain, state management, conditional branching, cyclical workflows, and multi-agent systems.

Related concepts

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