Skip to content

API Reference parrot.a2a.orchestrator

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.a2a.orchestrator

View source

A2A Hybrid Orchestrator - Combines rule-based routing with LLM-driven orchestration.

This module provides an intelligent orchestrator that uses deterministic rules when possible (fast, zero cost) and falls back to LLM-based decision making for complex scenarios requiring reasoning about which agents to use.

Alias A2AClient

Re-exported from parrot.a2a.client.A2AClient.

Alias A2AMeshDiscovery

Re-exported from parrot.a2a.mesh.A2AMeshDiscovery.

Class A2AOrchestrator

Hybrid orchestrator combining rule-based routing with LLM decision-making.

This orchestrator provides intelligent request routing and multi-agent coordination. It uses deterministic rules when patterns are known and falls back to LLM-based reasoning for complex or ambiguous requests.

Parameter Type Default Description
mesh A2AMeshDiscovery A2AMeshDiscovery instance for agent lookup
name str 'A2AOrchestrator' Name for this orchestrator
default_mode OrchestrationMode OrchestrationMode.HYBRID Default orchestration mode
default_timeout float 60.0 Default timeout for agent calls
max_parallel_agents int 10 Maximum agents in parallel execution
max_sequential_agents int 5 Maximum agents in sequential pipeline
aggregate_parallel_responses bool True Whether to combine parallel responses

Attributes:

Attribute Type Description
stats OrchestratorStats Get current statistics.
router A2AProxyRouter Access the internal router for advanced configuration.

Method A2AOrchestrator.route_by_skill

Add skill-based routing rule.

route_by_skill(skill_id: str, target: Union[str, List[str]], **kwargs) -> 'A2AOrchestrator'

Parameter Type Default Description
skill_id str
target Union[str, List[str]]
**kwargs {}

Returns: 'A2AOrchestrator'

Method A2AOrchestrator.route_by_tag

Add tag-based routing rule.

route_by_tag(tag: str, target: Union[str, List[str]], **kwargs) -> 'A2AOrchestrator'

Parameter Type Default Description
tag str
target Union[str, List[str]]
**kwargs {}

Returns: 'A2AOrchestrator'

Method A2AOrchestrator.route_by_regex

Add regex-based routing rule.

route_by_regex(pattern: str, target: Union[str, List[str]], **kwargs) -> 'A2AOrchestrator'

Parameter Type Default Description
pattern str
target Union[str, List[str]]
**kwargs {}

Returns: 'A2AOrchestrator'

Method A2AOrchestrator.set_default

Set default agent for unmatched requests.

set_default(agent_name: str) -> 'A2AOrchestrator'

Parameter Type Default Description
agent_name str

Returns: 'A2AOrchestrator'

Method A2AOrchestrator.set_fallback_llm

Configure LLM for complex orchestration decisions.

The LLM is used when:

  • No routing rule matches (in HYBRID mode)
  • Explicitly requested (LLM_ONLY mode)
  • Task requires multiple agents

set_fallback_llm(llm_client: 'AbstractClient', *, decision_prompt: Optional[str] = None, model: Optional[str] = None) -> 'A2AOrchestrator'

Parameter Type Default Description
llm_client 'AbstractClient' Parrot AbstractClient instance (Claude, GPT, etc.)
decision_prompt Optional[str] None Custom prompt template for decisions
model Optional[str] None Specific model to use for decisions

Returns: 'A2AOrchestrator' — Self for method chaining

Method A2AOrchestrator.clear_llm

Remove LLM fallback configuration.

clear_llm() -> 'A2AOrchestrator'

Returns: 'A2AOrchestrator'

Method A2AOrchestrator.run

Execute orchestration for a message.

This is the main entry point. The orchestrator will:

  1. Try rule-based routing if applicable
  2. Fall back to LLM decision if needed (HYBRID mode)
  3. Execute on selected agent(s)
  4. Aggregate results if multiple agents used

run(message: str, *, mode: Optional[OrchestrationMode] = None, agents: Optional[List[str]] = None, skill_id: Optional[str] = None, tags: Optional[List[str]] = None, context_id: Optional[str] = None, timeout: Optional[float] = None, metadata: Optional[Dict[str, Any]] = None) -> OrchestrationResult

Parameter Type Default Description
message str The message/request to process
mode Optional[OrchestrationMode] None Override default orchestration mode
agents Optional[List[str]] None Explicit list of agents to use (bypasses routing)
skill_id Optional[str] None Optional skill ID hint for routing
tags Optional[List[str]] None Optional tags for routing
context_id Optional[str] None Optional context for multi-turn conversations
timeout Optional[float] None Override default timeout
metadata Optional[Dict[str, Any]] None Additional metadata

Returns: OrchestrationResult — OrchestrationResult with response(s) and execution details

Method A2AOrchestrator.close_clients

Close all cached clients.

close_clients() -> None

Method A2AOrchestrator.ask

Shortcut: get response as string.

ask(message: str, *, agent: Optional[str] = None, mode: Optional[OrchestrationMode] = None, **kwargs) -> str

Parameter Type Default Description
message str Message to send
agent Optional[str] None Optional specific agent
mode Optional[OrchestrationMode] None Optional mode override
**kwargs {} Additional arguments

Returns: str — Response text

Raises:

  • RuntimeError — If orchestration fails

Method A2AOrchestrator.fan_out

Send to multiple agents and collect responses.

fan_out(message: str, agents: List[str], **kwargs) -> Dict[str, Union[str, Exception]]

Parameter Type Default Description
message str Message to send
agents List[str] List of agent names
**kwargs {} Additional arguments

Returns: Dict[str, Union[str, Exception]] — Dict mapping agent name to response or exception

Method A2AOrchestrator.pipeline

Execute sequential pipeline.

pipeline(message: str, agents: List[str], **kwargs) -> str

Parameter Type Default Description
message str Initial message
agents List[str] Ordered list of agents
**kwargs {} Additional arguments

Returns: str — Final output from last agent

Method A2AOrchestrator.get_info

Get orchestrator state information.

get_info() -> Dict[str, Any]

Returns: Dict[str, Any]

Alias A2AProxyRouter

Re-exported from parrot.a2a.router.A2AProxyRouter.

Alias AbstractClient

Re-exported from parrot.clients.base.AbstractClient.

Class AgentExecutionResult

Result from a single agent execution.

Parameter Type Default Description
agent_name str
success bool
response Optional[str] None
task Optional[Task] None
error Optional[str] None
latency_ms float 0.0
metadata Dict[str, Any] dict()

Fields:

Field Type Default Description
agent_name str
success bool
response Optional[str] None
task Optional[Task] None
error Optional[str] None
latency_ms float 0.0
metadata Dict[str, Any] field(default_factory=dict)

Class AgentSelection

Single agent selection from LLM.

Fields:

Field Type Default Description
agent_name str Name of the selected agent
confidence float 1.0 Confidence score 0-1
reasoning str '' Why this agent was selected

Class LLMDecisionStrategy

Strategy for LLM-based agent selection.

Class OrchestrationMode

Mode of orchestration.

Class OrchestrationPlan

Complete orchestration plan from LLM.

Fields:

Field Type Default Description
strategy str Execution strategy: 'single', 'parallel', or 'sequential'
agents List[str] Ordered list of agent names to use
reasoning str '' Explanation of the orchestration decision
transform_between bool False For sequential: whether to transform output between agents

Class OrchestrationResult

Complete result from orchestration.

Parameter Type Default Description
success bool
mode_used OrchestrationMode
agents_used List[str]
responses List[AgentExecutionResult]
final_output Optional[str] None
total_time_ms float 0.0
llm_fallback_used bool False
llm_decision Optional[OrchestrationPlan] None
metadata Dict[str, Any] dict()

Fields:

Field Type Default Description
success bool
mode_used OrchestrationMode
agents_used List[str]
responses List[AgentExecutionResult]
final_output Optional[str] None
total_time_ms float 0.0
llm_fallback_used bool False
llm_decision Optional[OrchestrationPlan] None
metadata Dict[str, Any] field(default_factory=dict)

Attributes:

Attribute Type Description
primary_response Optional[str] Get the primary response (first successful or final output).

Method OrchestrationResult.to_dict

Convert to dictionary.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Class OrchestratorStats

Statistics for the orchestrator.

Parameter Type Default Description
total_requests int 0
successful_requests int 0
failed_requests int 0
rules_used int 0
llm_fallback_used int 0
parallel_executions int 0
sequential_executions int 0
total_latency_ms float 0.0
agents_called Dict[str, int] dict()
mode_usage Dict[str, int] dict()

Fields:

Field Type Default Description
total_requests int 0
successful_requests int 0
failed_requests int 0
rules_used int 0
llm_fallback_used int 0
parallel_executions int 0
sequential_executions int 0
total_latency_ms float 0.0
agents_called Dict[str, int] field(default_factory=dict)
mode_usage Dict[str, int] field(default_factory=dict)

Attributes:

Attribute Type Description
avg_latency_ms float
success_rate float

Method OrchestratorStats.to_dict

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Alias RegisteredAgent

Re-exported from parrot.a2a.mesh.RegisteredAgent.

Alias Task

Re-exported from parrot.a2a.models.Task.

Alias TaskState

Re-exported from parrot.a2a.models.TaskState.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally