TheDocumentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
ReflexionAgent implements the Reflexion framework to improve through self-reflection. It follows a process of acting on tasks, evaluating its performance, generating self-reflections, and using these reflections to improve future responses.
Based on the research paper: Reflexion: Language Agents with Verbal Reinforcement Learning (Shinn et al., 2023).
The agent consists of three specialized sub-agents:
- Actor: Generates initial responses to tasks
- Evaluator: Critically assesses responses against quality criteria
- Reflector: Generates self-reflections to improve future responses
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_name | str | "reflexion-agent" | Name of the agent |
system_prompt | str | REFLEXION_PROMPT | System prompt for the agent |
model_name | str | "openai/o1" | Model name for generating responses |
max_loops | int | 3 | Maximum number of reflection iterations per task |
memory_capacity | int | 100 | Maximum capacity of long-term memory |
Methods
act
Generates a response to the given task using the actor agent.evaluate
Evaluates the quality of a response to a task. Returns an evaluation string and a score between 0 and 1.reflect
Generates a self-reflection based on the task, response, and evaluation.refine
Refines the original response based on evaluation and reflection.step
Processes a single task through one iteration of the Reflexion process. Returns a dictionary containing task, response, evaluation, reflection, score, and iteration number.run
Executes the full Reflexion process for a list of tasks.Example
Memory System
The agent includes aReflexionMemory system that maintains both short-term and long-term memories of past experiences, reflections, and feedback.
- Short-term memory for recent interactions
- Long-term memory for important reflections and patterns
- Automatic memory management with capacity limits
- Relevance-based memory retrieval
- Similarity-based deduplication
Best Practices
- Task Clarity: Provide clear, specific tasks to get the best results
- Iteration Count: Adjust
max_loopsbased on task complexity (more complex tasks benefit from more iterations) - Memory Management: Monitor memory usage and adjust
memory_capacityas needed - Model Selection: Choose an appropriate model based on your specific use case