Documentation Index
Fetch the complete documentation index at: https://openpipe-art-austin-megatron-models.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
LangGraph Integration
ARTβs LangGraph integration enables you to build sophisticated, multi-step AI agents that learn and improve through reinforcement training. By combining LangGraphβs powerful agent framework with ARTβs training capabilities, you can create agents that reason, use tools, and adapt their behavior over time.Installation
To use ART with LangGraph, install ART with the required extras:langgraph extra includes the LangGraph integration dependencies, while backend provides the training backend components.
Why Use ART with LangGraph?
LangGraph provides an excellent framework for building various types of agents - from ReAct-style reasoning agents to complex multi-agent workflows with supervisor patterns and parallel execution. However, getting these agents to perform optimally often requires extensive prompt engineering and manual tuning. ARTβs integration with LangGraph addresses this by:- Automatic behavior improvement: Train your agents to get better at multi-step reasoning without manual prompt tuning
- Tool usage optimization: Learn when and how to use tools more effectively through reinforcement learning
- Adaptive decision making: Agents learn to make better choices about which actions to take in different situations
- Scalable training: Train on diverse scenarios to build robust, generalizable agent behaviors
Key Features
- Seamless integration: Drop-in replacement for LangGraphβs LLM initialization
- Automatic logging: Captures all agent interactions for training data generation
- Multi-step trajectory support: Handles complex agent workflows with tool calls and reasoning steps
- RULER compatibility: Use ARTβs general-purpose reward function to train agents without hand-crafted rewards
Code Examples
Here are easily readable code snippets demonstrating the LangGraph integration functionality:Basic Setup and Initialization
Defining Tools for Your Agent
Creating and Running a LangGraph ReAct Agent
Trajectory Tracking and Scoring
Training Loop with LangGraph Integration
Correctness Evaluation
Key Components Summary
- LangGraph ReAct Agent: Uses
create_react_agent()with custom tools and chat model - Tool Definition: Custom tools decorated with
@toolfor specific functionality - Trajectory Tracking: Custom trajectory class extends
art.Trajectory - Training Integration: Uses
wrap_rollout()andart.gather_trajectory_groups() - Evaluation: Automated correctness judging with retry logic
- Configuration: Flexible training parameters and agent limits
Complete Email Agent Example
Hereβs a complete, runnable example that demonstrates training a LangGraph email search agent:- Set up the environment with model, backend, and data structures
- Define custom tools for email search and retrieval
- Create a LangGraph ReAct agent with proper configuration
- Implement trajectory tracking with custom reward scoring
- Run the full training loop with proper error handling
- Use wrap_rollout to automatically capture agent interactions
search_emails, read_email) with your actual email API integration, and provide real training scenarios in the training_scenarios list.
Troubleshooting
Common Issues
Empty trajectories or no training data captured:- Ensure youβre using
init_chat_model(model.get_inference_name())in your rollout function - Verify your rollout function actually executes the agent and makes LLM calls
- Check that
init_chat_model()is called before creating your LangGraph agent
- Install ART with the correct extras:
uv pip install -U openpipe-art[backend,langgraph]>=0.4.9 - Ensure you have the required LangGraph dependencies
- Verify you have trajectory data with
await art.gather_trajectory_groups(...) - Check that the model is properly registered with
await model.register(backend)
Best Practices
Agent Design
- Clear tool descriptions: Ensure your tool functions have descriptive docstrings
- Error handling: Include proper error handling in your tools for robust training
- Final answer pattern: Use a dedicated tool for returning final answers to users
Training Data
- Diverse scenarios: Create varied training scenarios that cover different use cases
- Realistic complexity: Include both simple and complex multi-step tasks
- Edge cases: Add scenarios that test error handling and edge cases
Performance Optimization
- Tool efficiency: Optimize tool execution time since it affects training speed
- Batch generation: Generate multiple trajectories efficiently using async patterns
- Resource management: Monitor memory usage during long training runs