/ examples / reflection / 01_agent_reflection_config.py
01_agent_reflection_config.py
 1  """
 2  ReflectionConfig Example
 3  
 4  Demonstrates using ReflectionConfig for fine-grained control.
 5  """
 6  import os
 7  from praisonaiagents import Agent, ReflectionConfig
 8  
 9  # Ensure API key is set from environment
10  assert os.getenv("OPENAI_API_KEY"), "OPENAI_API_KEY must be set"
11  
12  # Custom reflection configuration
13  agent = Agent(
14      instructions="You are a helpful math tutor.",
15      reflection=ReflectionConfig(
16          min_iterations=1,
17          max_iterations=3,
18          llm=None,  # Use same LLM as main agent
19          prompt=None,  # Use default reflection prompt
20      ),
21  )
22  
23  # More iterations for complex tasks
24  agent_thorough = Agent(
25      instructions="You are a research assistant.",
26      reflection=ReflectionConfig(
27          min_iterations=2,
28          max_iterations=5,
29      ),
30  )
31  
32  if __name__ == "__main__":
33      print("Testing ReflectionConfig...")
34      
35      print(f"Agent min_reflect: {agent.min_reflect}")
36      print(f"Agent max_reflect: {agent.max_reflect}")
37      print(f"Thorough agent max_reflect: {agent_thorough.max_reflect}")
38      
39      result = agent.chat("What is the derivative of x^2?")
40      print(f"Result: {result}")
41      
42      print("\nReflectionConfig tests passed!")