agents.patterns.react_structured_agent_variants

React Structured Agent Variants - Building on base Agent patterns.

This module creates various ReactAgent → SimpleAgent patterns using the base agent.py architecture, as requested. Shows different ways to combine agents for structured workflows with reasoning and output formatting.

Variants include: 1. Basic React → Simple structured flow 2. Multi-stage reasoning with structured outputs 3. Tool-enhanced React → Simple patterns 4. Reflection-enabled variants

Classes

AnalysisResult

Structured analysis from reasoning.

MultiStageReasoningAgent

Multi-stage reasoning with structured outputs at each stage.

ReactToStructuredAgent

React → Structured output agent pattern.

ReflectiveStructuredAgent

React → Structured → Reflection pattern.

StructuredSolution

Structured solution output.

ToolEnhancedStructuredAgent

Enhanced React → Structured agent with specialized tools.

Functions

create_multi_stage_reasoning_agent([name, stages, debug])

Create a multi-stage reasoning agent.

create_react_structured_agent([name, tools, ...])

Create a React → Structured agent.

create_reflective_structured_agent([name, ...])

Create a reflective structured agent.

create_tool_enhanced_agent([name, output_model, debug])

Create a tool-enhanced structured agent.

example_basic_react_structured()

Example of basic React → Structured flow.

example_multi_stage()

Example of multi-stage reasoning.

example_reflective()

Example of reflective structured output.

Module Contents

class agents.patterns.react_structured_agent_variants.AnalysisResult(/, **data)

Bases: pydantic.BaseModel

Structured analysis from reasoning.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class agents.patterns.react_structured_agent_variants.MultiStageReasoningAgent

Bases: haive.agents.base.agent.Agent

Multi-stage reasoning with structured outputs at each stage.

This pattern chains multiple reasoning stages, each producing structured outputs that feed into the next stage.

build_graph()

Build multi-stage graph.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

setup_agent()

Setup multi-stage reasoning pipeline.

Return type:

None

class agents.patterns.react_structured_agent_variants.ReactToStructuredAgent

Bases: haive.agents.base.agent.Agent

React → Structured output agent pattern.

This agent combines ReactAgent for reasoning with SimpleAgentV3 for structured output generation, following the base Agent pattern.

Examples

>>> agent = ReactToStructuredAgent(
...     name="analyzer",
...     tools=[calculator, search_tool],
...     output_model=AnalysisResult,
...     debug=True
... )
>>> result = await agent.arun("Analyze market trends")
build_graph()

Build React → Structured graph.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

setup_agent()

Setup React and Simple agents.

Return type:

None

class agents.patterns.react_structured_agent_variants.ReflectiveStructuredAgent

Bases: haive.agents.base.agent.Agent

React → Structured → Reflection pattern.

This adds a reflection stage that reviews and improves the structured output before final delivery.

build_graph()

Build graph with optional reflection.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

setup_agent()

Setup reasoning, structuring, and reflection agents.

Return type:

None

class agents.patterns.react_structured_agent_variants.StructuredSolution(/, **data)

Bases: pydantic.BaseModel

Structured solution output.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class agents.patterns.react_structured_agent_variants.ToolEnhancedStructuredAgent

Bases: ReactToStructuredAgent

Enhanced React → Structured agent with specialized tools.

This variant adds domain-specific tools for enhanced reasoning.

setup_agent()

Setup with enhanced tools.

Return type:

None

agents.patterns.react_structured_agent_variants.create_multi_stage_reasoning_agent(name='multi_stage', stages=None, debug=True)

Create a multi-stage reasoning agent.

Parameters:
Return type:

MultiStageReasoningAgent

agents.patterns.react_structured_agent_variants.create_react_structured_agent(name='react_structured', tools=None, output_model=StructuredSolution, debug=True)

Create a React → Structured agent.

Parameters:
  • name (str)

  • tools (list[Any] | None)

  • output_model (type[pydantic.BaseModel])

  • debug (bool)

Return type:

ReactToStructuredAgent

agents.patterns.react_structured_agent_variants.create_reflective_structured_agent(name='reflective', include_reflection=True, output_model=StructuredSolution, debug=True)

Create a reflective structured agent.

Parameters:
  • name (str)

  • include_reflection (bool)

  • output_model (type[pydantic.BaseModel])

  • debug (bool)

Return type:

ReflectiveStructuredAgent

agents.patterns.react_structured_agent_variants.create_tool_enhanced_agent(name='tool_enhanced', output_model=AnalysisResult, debug=True)

Create a tool-enhanced structured agent.

Parameters:
  • name (str)

  • output_model (type[pydantic.BaseModel])

  • debug (bool)

Return type:

ToolEnhancedStructuredAgent

async agents.patterns.react_structured_agent_variants.example_basic_react_structured()

Example of basic React → Structured flow.

async agents.patterns.react_structured_agent_variants.example_multi_stage()

Example of multi-stage reasoning.

async agents.patterns.react_structured_agent_variants.example_reflective()

Example of reflective structured output.