A modular LangGraph team that answers a task by routing work through specialist agents.
The supervisor decides who works next. A researcher gathers notes, a writer drafts the answer, and a reviewer approves it or sends it back for revision.
START → supervisor → researcher → writer → reviewer → finish → END
↑ |
└──── revise (optional)┘
- Python 3.10+
- A Metis or OpenAI-compatible API key
pip install -r requirements.txtCopy the example env file (or edit the existing .env) and put a real API key in it:
copy .env.example .envMETIS_API_KEY=
OPENAI_API_KEY=
OPENAI_BASE_URL=https://api.metisai.ir/openai/v1
LLM_MODEL=gpt-4o-mini
LLM_TEMPERATURE=0
MAX_REVISIONS=2
RECURSION_LIMIT=25
Set METIS_API_KEY or OPENAI_API_KEY. A placeholder such as your-metis-api-key will not work.
The default API base URL is https://api.metisai.ir/openai/v1. Override it with OPENAI_BASE_URL or METIS_BASE_URL if you use another endpoint.
One-shot:
python main.py "Explain how LangGraph supervisor agents work"Interactive session:
python main.pyType a task, or exit / quit to leave.
Hide node progress logs:
python main.py --quiet "Summarize the difference between agents and workflows"- Supervisor reads shared state and picks the next worker:
researcher,writer,reviewer, orfinish. - Researcher collects structured notes for the task.
- Writer turns those notes (and any review feedback) into a draft.
- Reviewer approves the draft or requests changes.
- Finish delivers
final_answer.
If structured routing fails, the supervisor falls back to simple rules (research first, then write, then review). Revisions stop after MAX_REVISIONS (default 2) so the graph cannot loop forever.
config/ Env-based settings
models/ Shared AgentState and Pydantic schemas
prompts/ System and user prompts
agents/ One module per worker
graph/ Graph wiring, routing, and run_task
utils/ LLM factory and logging
main.py CLI entry point
Call the team from code:
from graph.runner import run_task
result = run_task("What is a LangGraph state graph?")
print(result["final_answer"])| Variable | Default | Purpose |
|---|---|---|
METIS_API_KEY |
— | Preferred API key |
OPENAI_API_KEY |
— | Fallback API key |
OPENAI_BASE_URL / METIS_BASE_URL |
https://api.metisai.ir/openai/v1 |
OpenAI-compatible endpoint |
LLM_MODEL |
gpt-4o-mini |
Chat model |
LLM_TEMPERATURE |
0 |
Sampling temperature |
MAX_REVISIONS |
2 |
Reviewer rewrite limit |
RECURSION_LIMIT |
25 |
LangGraph step limit |
- Add a node in
agents/. - Register it in
graph/builder.py. - Teach the supervisor the new name in
models/schemas.pyandprompts/templates.py. - Update
graph/routing.pyso the supervisor can send work there.