agents.patterns.hybrid_multi_agent_patterns

Hybrid Multi-Agent Patterns - Advanced compositions using base patterns.

This module demonstrates advanced multi-agent patterns that combine different agent types and execution modes, using the base agent.py and SimpleAgentV3 patterns as building blocks.

Patterns include: 1. Parallel-then-Sequential workflows 2. Conditional routing with multiple branches 3. Hierarchical agent structures 4. Dynamic agent composition

Classes

AdaptiveMultiAgent

Adaptive multi-agent that changes behavior based on context.

CollaborativeMultiAgent

Collaborative multi-agent where agents work together.

HybridMultiAgent

Hybrid multi-agent with mixed execution patterns.

ParallelResults

Results from parallel agent execution.

TaskClassification

Task classification result.

Functions

create_adaptive_agent([name, debug])

Create an adaptive multi-agent.

create_collaborative_agent([name, collaboration_mode, ...])

Create a collaborative multi-agent.

create_hybrid_agent([name, execution_pattern, debug])

Create a hybrid multi-agent.

example_adaptive_processing()

Example of adaptive processing.

example_collaborative()

Example of collaborative multi-agent.

example_hybrid_classify_process()

Example of classification-based processing.

Module Contents

class agents.patterns.hybrid_multi_agent_patterns.AdaptiveMultiAgent(**kwargs)

Bases: haive.agents.multi.agent.MultiAgent

Adaptive multi-agent that changes behavior based on context.

This agent dynamically adjusts its execution pattern based on input characteristics and intermediate results.

Init .

class agents.patterns.hybrid_multi_agent_patterns.CollaborativeMultiAgent(**kwargs)

Bases: haive.agents.multi.agent.MultiAgent

Collaborative multi-agent where agents work together.

Agents share information and build on each other’s work.

Init .

class agents.patterns.hybrid_multi_agent_patterns.HybridMultiAgent

Bases: haive.agents.base.agent.Agent

Hybrid multi-agent with mixed execution patterns.

This agent can combine parallel and sequential execution, conditional routing, and dynamic agent selection.

Examples

>>> agent = HybridMultiAgent(
...     name="hybrid_processor",
...     initial_agents=[classifier],
...     processing_agents=[simple_proc, complex_proc, research_proc],
...     synthesis_agents=[combiner, formatter],
...     execution_pattern="classify_then_process"
... )
build_graph()

Build hybrid execution graph.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

setup_agent()

Setup hybrid agent structure.

Return type:

None

class agents.patterns.hybrid_multi_agent_patterns.ParallelResults(/, **data)

Bases: pydantic.BaseModel

Results from parallel agent execution.

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.hybrid_multi_agent_patterns.TaskClassification(/, **data)

Bases: pydantic.BaseModel

Task classification result.

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.hybrid_multi_agent_patterns.create_adaptive_agent(name='adaptive', debug=True)

Create an adaptive multi-agent.

Parameters:
Return type:

AdaptiveMultiAgent

agents.patterns.hybrid_multi_agent_patterns.create_collaborative_agent(name='collaborative', collaboration_mode='consensus', debug=True)

Create a collaborative multi-agent.

Parameters:
  • name (str)

  • collaboration_mode (str)

  • debug (bool)

Return type:

CollaborativeMultiAgent

agents.patterns.hybrid_multi_agent_patterns.create_hybrid_agent(name='hybrid', execution_pattern='classify_then_process', debug=True)

Create a hybrid multi-agent.

Parameters:
Return type:

HybridMultiAgent

async agents.patterns.hybrid_multi_agent_patterns.example_adaptive_processing()

Example of adaptive processing.

async agents.patterns.hybrid_multi_agent_patterns.example_collaborative()

Example of collaborative multi-agent.

async agents.patterns.hybrid_multi_agent_patterns.example_hybrid_classify_process()

Example of classification-based processing.