Skip to content

Added reflexion prompting agent from inheriting ReAct agent. #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

PalmPalm7
Copy link

@PalmPalm7 PalmPalm7 commented Feb 26, 2025

What does this PR do?

Link to issues: meta-llama/llama-stack#1389

This PR adds the Reflexion Agent, a new agent type that extends ReAct with self-reflection capabilities. The Reflexion Agent can reflect on its past reasoning and errors to improve subsequent responses within a conversation.

Test Plan

I tested the implementation with the following steps:

  1. Created a sample Reflexion Agent using the new class:
reflexion_agent = ReflexionAgent(
    client=client,
    model="meta-llama/Llama-3.1-8B-Instruct",
    builtin_toolgroups=["builtin::websearch"],
    client_tools=[calculator_tool]
)
  1. Tested multi-turn conversation to verify reflection persistence:
# First query with a deliberate error
response1 = reflexion_agent.create_turn(
    messages=[{"role": "user", "content": "What is 15% of 85?"}],
    session_id=session_id
)
# Response correctly calculated 12.75

# Second query referencing the first
response2 = reflexion_agent.create_turn(
    messages=[{"role": "user", "content": "What if we round to the nearest integer?"}],
    session_id=session_id
)
# Response correctly reflected on previous calculation and rounded to 13
  1. Verified that reflections persist between turns by examining the agent's reflection_memory:
assert session_id in reflexion_agent.reflection_memory
assert len(reflexion_agent.reflection_memory[session_id]) > 0
  1. Confirmed correct JSON schema validation for the ReflexionOutput format.

  2. Tested with both streaming and non-streaming responses to ensure reflection collection works in both cases.

@PalmPalm7 PalmPalm7 changed the title Added reflexion prompting agent template and application [WIP] Added reflexion prompting agent template and application Feb 26, 2025
@PalmPalm7 PalmPalm7 changed the title [WIP] Added reflexion prompting agent template and application Added reflexion prompting agent from inheriting ReAct agent. Mar 19, 2025
@PalmPalm7 PalmPalm7 marked this pull request as ready for review March 19, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants