agents.patterns.sequential_with_structured_outputΒΆ

Generic Sequential Agent Pattern with Structured Output Hooks.

This module provides a flexible pattern for creating sequential agent flows where the first agent performs some task and the second agent structures the output into a specific format.

Examples

Common sequential patterns:

ReactAgent β†’ StructuredOutputAgent
ResearchAgent β†’ SummaryAgent
AnalysisAgent β†’ ReportAgent

ClassesΒΆ

SequentialAgentWithStructuredOutput

Generic sequential agent pattern with structured output.

SequentialHooks

Hooks for customizing sequential agent behavior.

FunctionsΒΆ

create_analysis_to_report(analysis_prompt, report_model)

Create an Analysis β†’ Report pipeline.

create_react_to_structured(tools, structured_output_model)

Create a ReactAgent β†’ StructuredOutput pipeline.

Module ContentsΒΆ

class agents.patterns.sequential_with_structured_output.SequentialAgentWithStructuredOutput(first_agent, structured_output_model, structured_output_prompt=None, second_agent=None, hooks=None, name='sequential_structured', debug=False)ΒΆ

Bases: Generic[OutputT]

Generic sequential agent pattern with structured output.

This class orchestrates two agents in sequence: 1. First agent performs the main task (e.g., reasoning, research) 2. Second agent structures the output into a specific format

The pattern is flexible and works with any agent types.

Initialize sequential agent with structured output.

Parameters:
  • first_agent (haive.agents.base.agent.Agent) – The agent that performs the main task

  • structured_output_model (type[OutputT]) – Pydantic model for structured output

  • structured_output_prompt (langchain_core.prompts.ChatPromptTemplate | None) – Optional custom prompt for structuring

  • second_agent (haive.agents.base.agent.Agent | None) – Optional custom second agent (otherwise creates SimpleAgent)

  • hooks (SequentialHooks | None) – Optional hooks for customizing behavior

  • name (str) – Name for this sequential pattern

  • debug (bool) – Enable debug mode

async arun(input_data, context=None, **kwargs)ΒΆ

Run the sequential agent pipeline asynchronously.

Parameters:
  • input_data (Any) – Input for the first agent

  • context (dict[str, Any] | None) – Optional context to pass through pipeline

  • **kwargs – Additional arguments for agents

Returns:

Structured output according to the model

Return type:

OutputT

class agents.patterns.sequential_with_structured_output.SequentialHooks(/, **data)ΒΆ

Bases: pydantic.BaseModel

Hooks for customizing sequential agent behavior.

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)

agents.patterns.sequential_with_structured_output.create_analysis_to_report(analysis_prompt, report_model, name='analysis_report', analysis_config=None, report_prompt=None, hooks=None, debug=False)ΒΆ

Create an Analysis β†’ Report pipeline.

Parameters:
  • analysis_prompt (langchain_core.prompts.ChatPromptTemplate) – Prompt for analysis agent

  • report_model (type[OutputT]) – Model for structured report

  • name (str) – Name for the pipeline

  • analysis_config (dict[str, Any] | None) – Optional config for analysis agent

  • report_prompt (langchain_core.prompts.ChatPromptTemplate | None) – Optional custom report prompt

  • hooks (SequentialHooks | None) – Optional behavior hooks

  • debug (bool) – Enable debug mode

Returns:

Configured sequential agent pipeline

Return type:

SequentialAgentWithStructuredOutput[OutputT]

agents.patterns.sequential_with_structured_output.create_react_to_structured(tools, structured_output_model, name='react_structured', react_config=None, structured_prompt=None, hooks=None, debug=False)ΒΆ

Create a ReactAgent β†’ StructuredOutput pipeline.

Parameters:
  • tools (list[Any]) – Tools for the ReactAgent

  • structured_output_model (type[OutputT]) – Output model for structuring

  • name (str) – Name for the pipeline

  • react_config (dict[str, Any] | None) – Optional config for ReactAgent

  • structured_prompt (langchain_core.prompts.ChatPromptTemplate | None) – Optional custom structuring prompt

  • hooks (SequentialHooks | None) – Optional behavior hooks

  • debug (bool) – Enable debug mode

Returns:

Configured sequential agent pipeline

Return type:

SequentialAgentWithStructuredOutput[OutputT]