Files

52 lines
1.2 KiB
Plaintext

# LangGraph Notes
## What is LangGraph?
LangGraph is a library for building stateful, multi-actor applications with LLMs. It extends LangChain's capabilities by providing:
- State management for complex workflows
- Support for cycles in agent workflows
- Built-in persistence for long-running applications
- Integration with LangChain tools and models
## Key Concepts
### State
State in LangGraph is represented as a dictionary that flows through the graph nodes. Each node can modify the state.
### Nodes
Nodes are individual processing units that can be:
- LLM calls
- Tool calls
- Custom functions
### Edges
Edges connect nodes and can be:
- Direct connections
- Conditional routing based on state
## Example Usage
```python
from langgraph.graph import StateGraph, END
# Define state
class AgentState:
messages: List
next_action: str
# Build graph
graph = StateGraph(AgentState)
graph.add_node("agent", call_llm)
graph.add_node("tool", call_tool)
graph.add_edge("agent", "tool")
graph.add_edge("tool", "agent")
graph.add_edge("agent", END)
```
## Benefits
- More control over agent behavior
- Better for complex, multi-step reasoning
- Native support for human-in-the-loop workflows
- Easy to add memory and state persistence