Skip to main content

agentd/runtime/
events.rs

1// SPDX-License-Identifier: Apache-2.0
2//! The runtime's **event vocabulary** (RFC 0026 §3): everything the loop reacts
3//! to arrives here — child frames, reaped children, executor results, timers,
4//! signals, and the durable inbox events (A2A messages, start-node firings,
5//! signals) that are written ahead before being acted on.
6
7use crate::state::InboxEvent;
8use crate::subagent::protocol::AgentMsg;
9use crate::supervisor::reap::Reaped;
10use crate::supervisor::tree::NodeId;
11use serde_json::Value;
12
13/// One loop event.
14#[derive(Debug)]
15pub enum Event {
16    /// A frame from a child (turn worker / subagent).
17    Child(NodeId, AgentMsg),
18    /// A child exited (from the reaper).
19    Reaped(Reaped),
20    /// An executor thread finished a workflow step (`mcp.tool`, mapped tools…).
21    StepDone {
22        run: String,
23        step: String,
24        output: Value,
25        is_error: bool,
26        error: Option<String>,
27        tokens: u64,
28    },
29    /// An executor thread finished a mapped/MCP call made on behalf of a child's
30    /// tool request.
31    ToolDone {
32        node: NodeId,
33        req: u64,
34        result: Value,
35        is_error: bool,
36    },
37    /// Knowledge auto-context retrieval finished for a staged turn.
38    KnowledgeDone { job: u64, block: Option<String> },
39    /// A background think/summarize finished (unused in P3; reserved).
40    #[allow(dead_code)]
41    Background { id: String, result: Value },
42    /// A durable timer fired.
43    TimerFired {
44        id: String,
45        owner: Value,
46        payload: Value,
47    },
48    /// A durable event was accepted (already in the inbox).
49    Inbox(InboxEvent),
50    /// An A2A transport request awaiting a loop-computed reply (RFC 0029).
51    #[cfg(feature = "a2a")]
52    A2a(Box<super::a2a_server::A2aRequest>),
53    /// An inbound webhook awaiting a loop-computed reply (RFC 0027).
54    #[cfg(feature = "a2a")]
55    Webhook(Box<super::webhooks::WebhookRequest>),
56    /// The 200 ms tick.
57    Tick,
58}
59
60/// The inbox event kinds the runtime understands.
61pub mod kinds {
62    /// A start node fired: `{workflow, node, payload, inputs}`.
63    pub const START_FIRED: &str = "start_fired";
64    /// An A2A message: `{context_id, task_id?, principal, role, parts, message_id}`.
65    pub const A2A_MESSAGE: &str = "a2a_message";
66    /// A named signal: `{name, payload, from}`.
67    pub const SIGNAL: &str = "signal";
68    /// A2A control: `{op, args}`.
69    pub const A2A_CONTROL: &str = "a2a_control";
70    /// A tool-driven request to run a workflow (`workflow.run`): `{workflow, inputs, start, requested_by}`.
71    pub const WORKFLOW_RUN: &str = "workflow_run";
72}