This project is a hands-on LangGraph learning repo. It contains small Python examples that build from basic graph concepts into memory, human-in-the-loop workflows, tool calling, and multi-agent systems. The later examples show practical patterns such as reducers, message state, summarization, checkpointing, dynamic parallelism, subgraphs, and routing work across multiple agents.
quick_start.py is a self-contained introductory example. It builds a minimal LangGraph agent backed by Claude that can add, multiply, and divide numbers using tool calls. Run it from the repository root:
python quick_start.pyThe RAG/ folder contains the part 6 LangGraph + LlamaIndex example. It builds a retrieval-augmented agent that reads source documents from RAG/data/, stores a local LlamaIndex vector index in RAG/storage/, and exposes retrieval through a LangGraph tool.
Setup from the repository root:
pip install -r requirement.txtAdd your OpenAI key to RAG/.env:
OPENAI_API_KEY=your_api_key_hereRun the interactive RAG agent from inside the RAG directory:
cd RAG
python main.pySee RAG/Readme.md for full instructions, including the smoke test and how to rebuild the persisted index after changing documents.
-
Before: Summarization kept only the last two messages, which could split apart an assistant tool call and its tool response.
messages_to_delete = [ RemoveMessage(id=m.id) for m in state["messages"][:-2] ]
-
After: Summarization keeps the latest complete user turn, preserving tool-call message order.
last_human_index = 0 for i, message in enumerate(state["messages"]): if isinstance(message, HumanMessage): last_human_index = i messages_to_delete = [ RemoveMessage(id=m.id) for m in state["messages"][:last_human_index] ]
-
Error:
messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. -
Cause:
summarize_nodekept only the last two messages after summarization. In conversations that used tools, this could leave aToolMessagein state without the precedingAIMessagethat created the tool call. -
Solution: Summarization now deletes messages before the latest user turn instead of keeping a fixed number of messages. This preserves valid message groups such as
HumanMessage -> AIMessage(tool_calls) -> ToolMessage -> AIMessage.
-
Before: The graph tried to route to
initiate_researchas if it were a registered node.def should_continue_to_research(state: ResearchGraphState): if state.get("human_analyst_feedback"): return "create_analysts" return "initiate_research" outer_builder.add_conditional_edges( "human_feedback", should_continue_to_research, {"create_analysts": "create_analysts", "initiate_research": "initiate_research"} )
-
After: The graph routes through
route_after_human_feedback, which either regenerates analysts or sends work to the interview subgraphs.def route_after_human_feedback(state: ResearchGraphState): if state.get("human_analyst_feedback"): return "create_analysts" return initiate_research(state) outer_builder.add_conditional_edges( "human_feedback", route_after_human_feedback, ["create_analysts", "interview"] )
-
Error:
At 'human_feedback' node, 'should_continue_to_research' branch found unknown target 'initiate_research'. -
Cause:
initiate_researchwas used as a branch target, but it is a routing function that returnsSend(...)objects. It was not registered as a graph node. -
Solution:
human_feedbacknow routes throughroute_after_human_feedback. That router either loops back tocreate_analystswhen feedback exists, or callsinitiate_research(state)to launch parallel interview subgraphs.
-
Before: The script always waited for keyboard input, even when stdin was unavailable.
feedback = input("\nProvide feedback to refine analysts (or press Enter to approve): ")
-
After: The script asks for feedback only in an interactive terminal and auto-approves otherwise.
if sys.stdin.isatty(): feedback = input("\nProvide feedback to refine analysts (or press Enter to approve): ") else: feedback = "" print("\nNo interactive input available; approving generated analysts.")
-
Error:
EOFError: EOF when reading a line. -
Cause: The script always called
input()for human analyst feedback. This fails when the file is run from a non-interactive command session. -
Solution: The script now checks
sys.stdin.isatty(). If interactive input is unavailable, it automatically approves the generated analysts and continues.
-
Before: The analyst question node could produce tool calls, but those calls were not routed to
ToolNode.response = interview_llm.invoke(messages)
-
After: Only the expert answer node can produce tool calls, and those calls are routed through
ToolNodebefore the next model call.response = llm.invoke(messages)
-
Error:
An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. -
Cause:
generate_question()used the tool-bound interview model, so the analyst node could emit anAIMessagewithtool_calls. The graph then routed that message directly togenerate_answer()instead ofinterview_tools, so no matchingToolMessagewas created. -
Solution:
generate_question()now uses the plain LLM. Tool calls are reserved forgenerate_answer(), whose route sends tool-calling messages throughToolNodebefore the model sees the conversation again.