This project demonstrates a multi-agent orchestration framework built with LangGraph and LangChain. It simulates a chat environment where a user can interact with two distinct LLMs--Llama-3.2-1B and Qwen2.5-0.5B--managing conversation history, routing, and state persistence.
The system is modeled as a StateGraph where input is processed, routed to specific models (or both in parallel), and the results are aggregated back to the user.
Figure 1: Generated graph structure showing the flow between input, LLM inference, and response printing.
The agent intelligently routes queries based on wake words.
- "Hey Qwen..." -> Routes only to the Qwen model.
- "Hey Llama..." -> Routes only to the Llama model.
- Standard Input -> Routes to the default active model(s).
A Parallel Mode allows the user to broadcast a single message to both models simultaneously to compare their responses side-by-side.
The system handles the complexity of "multi-party" chat within standard User/AI message roles by normalizing message content. It supports two history modes:
- Shared History (Default): Both models see the full conversation context, including what the other model said.
- Isolated History: Models only see messages specifically targeted at them.
Uses SqliteSaver to checkpoint the graph state after every step. If the program crashes or is stopped, the conversation can be resumed exactly where it left off by using the same thread ID.
This project uses uv for package management, but pip works as well.
pip install -r requirements.txtRun the main script to download models (first run only) and start the chat loop:
python langgraph_simple_agent.pyTo resume a specific conversation thread:
python langgraph_simple_agent.py --thread-id "my-conversation-1"While in the chat loop, you can type these commands instead of a message to change the agent's behavior:
| Command | Action |
|---|---|
v / verbose |
Turn on verbose node tracing (shows internal state transitions). |
quiet |
Turn off verbose tracing. |
p / parallel |
Toggle Parallel Mode (Run both models on next input). |
s / shared |
Toggle Shared History (Allow models to see each other's replies). |
q / quit |
Save state and exit the program. |
langgraph_simple_agent.py: Main application logic, graph definition, and node functions.checkpoints.sqlite: SQLite database storing conversation history and state snapshots.lg_graph.png: Automatically generated visualization of the LangGraph structure.