Skip to content

API Reference parrot.integrations.matrix.crew.delegation

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

parrot.integrations.matrix.crew.delegation

View source

Hybrid tool delegation for Matrix collaborative crew sessions.

HybridDelegator bridges the collaborative session layer with the Matrix custom event layer (m.parrot.task / m.parrot.result), enabling an agent to request tool execution from a peer agent that has privileged access.

Flow:

  1. Post a visible "Asking @peer to: ..." message in the room.
  2. Send a m.parrot.task custom event via the AppService.
  3. Wait for the matching m.parrot.result custom event (with timeout).
  4. Post the result as a visible reply-to the original request message.

Class DelegationRequest

Represents a request to delegate a task to another agent.

Fields:

Field Type Default Description
requester_name str Agent name of the delegating agent
target_agent str Agent name of the peer agent
task_description str Description of the delegated task
room_id str Matrix room ID for the delegation
context Optional[str] None Optional shared context

Class HybridDelegator

Orchestrates hybrid tool delegation in a Matrix room.

Combines visible Matrix messages (for human readability) with custom m.parrot.task / m.parrot.result events (for agent-to-agent communication).

Parameter Type Default Description
appservice 'MatrixAppService' The shared MatrixAppService instance.
registry 'MatrixCrewRegistry' MatrixCrewRegistry for resolving agent cards.

Method HybridDelegator.delegate

Execute a hybrid delegation request.

Steps:

  1. Resolve the target agent's card from the registry.
  2. Post a visible "Asking @target to: ..." message as the requester.
  3. Send a m.parrot.task custom event with the task description.
  4. Wait for the matching m.parrot.result event (with timeout).
  5. Post the result text as a reply-to the visible request message.

delegate(request: DelegationRequest, timeout: float = 60.0) -> Optional[str]

Parameter Type Default Description
request DelegationRequest Delegation request details.
timeout float 60.0 Maximum seconds to wait for the result.

Returns: Optional[str] — Result text string if received, None on timeout.

Method HybridDelegator.on_custom_event

Handle an incoming custom event from the AppService.

Should be connected to MatrixAppService via set_custom_event_callback(). Resolves pending futures when a m.parrot.result event matching a known task_id is received.

on_custom_event(event_type: str, content: dict) -> None

Parameter Type Default Description
event_type str The raw event type string.
content dict The event content dict.

Alias MatrixAppService

Re-exported from parrot.integrations.matrix.appservice.MatrixAppService.

Alias MatrixCrewRegistry

Re-exported from parrot.integrations.matrix.crew.registry.MatrixCrewRegistry.

Alias ParrotEventType

Re-exported from parrot.integrations.matrix.events.ParrotEventType.

Alias ResultEventContent

Re-exported from parrot.integrations.matrix.events.ResultEventContent.

Alias TaskEventContent

Re-exported from parrot.integrations.matrix.events.TaskEventContent.

Alias build_pill

Re-exported from parrot.integrations.matrix.crew.mention.build_pill.

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