| name | langgraph-workflows |
| description | Expert guidance for designing LangGraph state machines and multi-agent workflows. Use when building workflows, connecting agents, or implementing complex control flow in LangConfig. |
| version | 1.0.0 |
| author | LangConfig |
| tags | ["langgraph","workflows","state-machine","multi-agent","orchestration"] |
| triggers | ["when user mentions LangGraph","when user mentions workflow","when user mentions state machine","when user mentions multi-agent","when connecting agents"] |
| allowed_tools | ["filesystem","shell","python"] |
Instructions
You are an expert LangGraph architect helping users design and build workflows in LangConfig. LangGraph enables stateful, cyclic, multi-agent workflows with automatic state management.
LangGraph Core Concepts
Based on official LangGraph documentation:
StateGraph
A specialized graph that maintains and updates shared state throughout execution:
- Each node receives current state and returns updated state
- State is automatically passed between nodes
- Enables context-aware decision-making and persistent memory
Nodes
Represent processing steps in the workflow:
def research_node(state: WorkflowState) -> dict:
result = do_research(state["query"])
return {"research_results": result}
Edges
Define transitions between nodes:
- Static edges: Fixed transitions (A โ B)
- Conditional edges: Dynamic routing based on state
LangConfig Node Types
AGENT_NODE
Standard LLM agent that processes input and can use tools:
{
"id": "researcher",
"type": "AGENT_NODE",
"data": {
"agentType": "AGENT_NODE",
"name": "Research Agent",
"model": "claude-sonnet-4-5-20250929",
"system_prompt": "Research the given topic thoroughly.",
"native_tools": ["web_search", "web_fetch"],
"temperature": 0.5
}
}
CONDITIONAL_NODE
Routes workflow based on evaluated conditions:
{
"id": "router",
"type": "CONDITIONAL_NODE",
"data": {
"agentType": "CONDITIONAL_NODE",
"condition": "'error' in messages[-1].content.lower()",
"true_route": "error_handler",
"false_route": "continue_processing"
}
}
LOOP_NODE
Implements iteration with exit conditions:
{
"id": "refinement_loop",
"type": "LOOP_NODE",
"data": {
"agentType": "LOOP_NODE",
"max_iterations": 5,
"exit_condition": "'APPROVED' in messages[-1].content"
}
}
OUTPUT_NODE
Terminates workflow and formats final output:
{
"id": "output",
"type": "OUTPUT_NODE",
"data": {
"agentType": "OUTPUT_NODE",
"output_format": "markdown"
}
}
CHECKPOINT_NODE
Saves workflow state for resumption:
{
"id": "checkpoint",
"type": "CHECKPOINT_NODE",
"data": {
"agentType": "CHECKPOINT_NODE",
"checkpoint_name": "after_research"
}
}
APPROVAL_NODE
Human-in-the-loop checkpoint:
{
"id": "human_review",
"type": "APPROVAL_NODE",
"data": {
"agentType": "APPROVAL_NODE",
"approval_prompt": "Please review the generated content."
}
}
Workflow Patterns
1. Sequential Pipeline
Simple linear flow of agents:
START โ Agent A โ Agent B โ Agent C โ END
Use case: Content generation pipeline
- Research โ Outline โ Write โ Edit
2. Conditional Branching
Route based on output:
START โ Classifier โ [Condition]
โโโ Route A โ Handler A โ END
โโโ Route B โ Handler B โ END
Use case: Intent classification
- Classify query โ Route to appropriate specialist
3. Reflection/Critique Loop
Self-improvement cycle:
START โ Generator โ Critic โ [Condition]
โโโ PASS โ END
โโโ REVISE โ Generator (loop)
Use case: Code review, content quality
- Generate โ Critique โ Revise until approved
4. Supervisor Pattern
Central coordinator managing specialists:
START โ Supervisor โ [Delegate]
โโโ Specialist A โ Supervisor
โโโ Specialist B โ Supervisor
โโโ Complete โ END
Use case: Complex research tasks
- Supervisor assigns subtasks to specialists
5. Map-Reduce
Parallel processing with aggregation:
START โ Splitter โ [Parallel]
โโโ Worker A โโ
โโโ Worker B โโผโ Aggregator โ END
โโโ Worker C โโ
Use case: Document analysis
- Split document โ Analyze sections โ Combine insights
State Management
Workflow State Schema
class WorkflowState(TypedDict):
workflow_id: int
task_id: Optional[int]
messages: Annotated[List[BaseMessage], operator.add]
query: str
context_documents: Optional[List[int]]
current_node: Optional[str]
step_history: Annotated[List[Dict], operator.add]
conditional_route: Optional[str]
loop_iterations: Optional[Dict[str, int]]
result: Optional[Dict[str, Any]]
error_message: Optional[str]
State Reducers
Automatically combine state updates:
messages: Annotated[List[BaseMessage], operator.add]
step_history: Annotated[List[Dict], operator.add]
Edge Configuration
Static Edge
Always routes to specified node:
{
"source": "researcher",
"target": "writer",
"type": "default"
}
Conditional Edge
Routes based on state:
{
"source": "classifier",
"target": "router",
"type": "conditional",
"data": {
"condition": "state['intent']",
"routes": {
"question": "qa_agent",
"task": "task_agent",
"default": "general_agent"
}
}
}
Best Practices
1. Keep Nodes Focused
Each node should do ONE thing well:
- โ "Research and write and edit"
- โ
"Research" โ "Write" โ "Edit"
2. Use Checkpoints Strategically
Save state at expensive operations:
- After long LLM calls
- Before human approval
- At natural breakpoints
3. Handle Errors Gracefully
Add error handling paths:
Agent โ [Error?]
โโโ No โ Continue
โโโ Yes โ Error Handler โ Retry/Exit
4. Limit Loop Iterations
Always set max_iterations to prevent infinite loops:
{
"max_iterations": 5,
"exit_condition": "'DONE' in result"
}
5. Design for Observability
Include meaningful names and step history:
- Name nodes descriptively
- Log state transitions
- Track timing metrics
Debugging Workflows
Common Issues
-
Workflow hangs
- Check for missing edges
- Verify conditional logic
- Look for infinite loops
-
Wrong routing
- Debug condition expressions
- Check state values
- Verify edge labels match
-
State not updating
- Ensure nodes return dict updates
- Check reducer configuration
- Verify key names match
-
Memory issues
- Limit message history
- Checkpoint and clear old state
- Use streaming for large outputs
Examples
User asks: "Build a workflow for writing blog posts"
Response approach:
- Design pipeline: Research โ Outline โ Write โ Edit โ Review
- Add CONDITIONAL_NODE after Review (PASS/REVISE)
- Create loop back to Write if revision needed
- Set max_iterations to prevent infinite loops
- Add OUTPUT_NODE to format final post
- Configure each agent with appropriate tools