Overview
Agents are the core building blocks of evolveRL. Each agent is an autonomous entity that can:
Process and respond to messages using an LLM backend
Maintain and evolve its own prompt template
Track its performance score
Save and load its configuration
Agent Configuration
Agents are configured using the AgentConfig class:
from evolverl.agent import Agent, AgentConfig
from evolverl.llm import LLMConfig
# Create agent config
config = AgentConfig(
llm_config = LLMConfig(
model_name = "gpt-4o-mini" ,
model_type = "openai"
),
prompt_template = "You are a helpful AI assistant..." ,
score = 0 # Initial score
)
# Create agent
agent = Agent(config)
Configuration Options
Configuration for the LLM backend Name of the LLM model to use (e.g., “gpt-4o-mini”, “claude-3-5-sonnet”)
Type of LLM provider (“openai” or “anthropic”)
Maximum tokens in model responses
Temperature for response generation (0.0 - 1.0)
The system prompt template that guides agent behavior
Performance score (0-1000) from evaluations
Using Agents
Basic Message Exchange
# Create and configure agent
agent = Agent(AgentConfig(LLMConfig()))
agent.set_default_prompt( "You are a helpful AI assistant." )
# Send a message
response = await agent.send_message( "What is the capital of France?" )
print (response)
Saving and Loading
# Save configuration
agent.save_config( "agent_config.json" )
# Load configuration
new_agent = Agent()
new_agent.load_config( "agent_config.json" )
Agent Types
In the evolution process, there are three main types of agents:
1. Variant Agents
These are the agents being evolved. They compete against each other and improve through generations.
# Create base variant
base_agent = Agent(AgentConfig(llm_config))
base_agent.set_default_prompt( "Base prompt template..." )
# Create mutations
variants = await evolution.mutate_agents(base_agent, count = 5 )
2. Adversary Agents
Generate challenging test cases to evaluate variant agents.
# Create adversary
adversary = await evolution.build_adversary(
domain = "mathematics" ,
description = "Generate tricky math problems"
)
3. Judge Agents
Evaluate the performance of variant agents.
# Create judge
judge = await evolution.build_judge(
domain = "mathematics" ,
description = "Evaluate solution quality"
)
# Get score
score = await evolution.get_agent_score(chat_history, judge)
Best Practices
Prompt Templates : Use clear, structured prompt templates with placeholders for dynamic content
Score Tracking : Regularly update agent scores based on performance
Configuration Management : Save agent configurations after significant improvements
Error Handling : Handle LLM API errors gracefully
Testing : Validate agent behavior across different scenarios