liveBook · Manning

State

As explained in AI Agents and Applications

State is the structured information representing a workflow's progress, intermediate results, failures, and contextual values across processing steps.

A research assistant may select an assistant, generate queries, search, summarize results, and write a report. If those steps only pass output to the next step, it is hard to see what happened earlier or decide whether to search again. State makes the workflow’s information explicit: it travels between steps and is updated as work progresses. section 5.5.1 section 5.2

In LangGraph, a state object defines the data available across the graph. A Python TypedDict can give fields clear types. For a research workflow, those fields can include the user question, selected assistant, search queries, search results, summaries, final report, fallback-search flag, relevance evaluation, and iteration count. The initial state supplies the required fields before the compiled graph runs. section 5.4 section 5.5.3

State has two jobs during execution:

  • Carry results forward. A node reads the current state and returns updates—for example, reading user_question and returning search_queries. section 5.4.3
  • Support decisions. A conditional edge reads the runtime state to choose the next node; too few search results can trigger query refinement instead of summarization. section 5.4.3

Search again or write the report?

After summarizing search results, a relevance evaluator can record whether the queries should be regenerated. If fewer than half the summaries are relevant, the graph loops back to query generation; otherwise it continues toward the report. An iteration count limits that loop to three attempts. These fields turn intermediate quality checks into an explicit routing decision. section 5.5.3

Listing 5.5 Running the graph
app = graph.compile()  #1

initial_state = {  #2
    "user_question": " What can you tell me about Astorga's roman spas?",
    "assistant_info": None,
    "search_queries": None,
    "search_results": None,
    "search_summaries": None,
    "research_summary": None,
    "final_report": None,
    "used_fallback_search": False,
    "relevance_evaluation": None,
    "should_regenerate_queries": None,
    "iteration_count": 0
}

result = app.invoke(initial_state)  #3

final_report = result["final_report"]  #4

The running-graph listing shows the initial state supplied to app.invoke: the question, empty intermediate fields, and control values such as used_fallback_search and iteration_count. section 5.5.3

Explicit state also helps when a workflow fails: intermediate values make it easier to identify where a linear chain went wrong. In a multi-agent workflow, current_agent and agent_history can record handoffs. State is related to, but broader than, chatbot conversation memory: memory tracks earlier turns for coherent replies, while workflow state also carries processing results and routing values. section 5.5.1 section 12.4 section 1.1.2

How AI Agents and Applications covers it

How deep it goes
Works through typed fields, node updates, initialization, and conditional routing, without detailing state storage internals.
Examples
Uses a web research assistant’s initial state, search results, relevance checks, and iteration count.
What it assumes
Introduces graph state through nodes and edges while using Python functions and TypedDict for the implementation.
What you can do after
Build it from scratch with LangGraph StateGraph, typed state, node updates, and state-based routing.
How it connects
Connects Python TypedDict, LangGraph nodes, conditional edges, and multi-agent handoffs.

Also explained in

Compare how 39 books explain state →

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.