haive.agents.reasoning_and_critique.reflexion.agent¶

Reflexion agent.

Composes ReactAgent (draft/revise with optional tools) and SimpleAgent (reflection/grading with structured output) in an iterative improvement loop.

Graph: START -> draft_answer -> reflect_answer -> [should_continue] -> revise_answer -> reflect_answer -> … -> finish_answer -> END

The drafter and reflector are real haive agents (ReactAgent, SimpleAgent) that use our tested infrastructure for LLM calls, tool use, and structured output.

Classes¶

ReflexionAgent

Reflexion: iterative draft-reflect-revise using ReactAgent + SimpleAgent.

Functions¶

create_reflexion_agent([tools, model])

Factory for ReflexionAgent.

Module Contents¶

class haive.agents.reasoning_and_critique.reflexion.agent.ReflexionAgent¶

Bases: haive.agents.base.agent.Agent

Reflexion: iterative draft-reflect-revise using ReactAgent + SimpleAgent.

  • Drafter: ReactAgent with optional tools for initial answer + revisions

  • Reflector: SimpleAgent with structured output (Reflection model)

  • Loop: draft -> reflect -> revise -> reflect -> … until max_iterations

build_graph()¶

Build the Reflexion graph.

Flow: START -> draft_answer -> reflect_answer -> [revise_answer | finish_answer]

v v

reflect_answer END

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

compile(**kwargs)¶

Compile: build agents lazily, use BaseGraph.to_langgraph().

Return type:

Any

get_answer(result)¶

Extract the final answer from a run result.

Parameters:

result (dict)

Return type:

str

run(input_data, **kwargs)¶

Run reflexion. Accepts a string query or a dict with ‘input’ key.

Parameters:

input_data (str | dict)

Return type:

Any

haive.agents.reasoning_and_critique.reflexion.agent.create_reflexion_agent(tools=None, model='gpt-4o-mini', **kwargs)¶

Factory for ReflexionAgent.