ag_contracts/output.rs
1//! Streamed model output of one in-process agent turn.
2
3/// One change to the model output an agent streams while its turn runs.
4///
5/// Items are numbered in the order they start. Hosts render them transiently
6/// and replace them with the persisted turn result when the turn ends; the
7/// output is session content, never telemetry, and is never replayed to a
8/// provider.
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub enum OutputEvent {
11 /// Item `id` started; its fragments and completion follow.
12 Started {
13 /// Identifier of the item within its turn.
14 id: u64,
15 /// What the item holds.
16 kind: OutputKind,
17 },
18 /// A fragment of display text appended to message or reasoning item
19 /// `id`; tool calls stream no fragments.
20 Delta {
21 /// Identifier of the item, as [`Self::Started`] reported it.
22 id: u64,
23 /// The fragment.
24 text: String,
25 },
26 /// Item `id` finished, and `text` replaces its fragments. A tool call
27 /// finishes once its arguments are complete and carries no text.
28 Completed {
29 /// Identifier of the item, as [`Self::Started`] reported it.
30 id: u64,
31 /// The authoritative item text.
32 text: String,
33 },
34 /// The turn's validated final answer.
35 Answer {
36 /// Message item that held the answer as it streamed, which the answer
37 /// supersedes, or `None` when the answer did not stream.
38 replaces: Option<u64>,
39 /// The answer text.
40 text: String,
41 },
42 /// Items that belong to a discarded response, or that the turn left
43 /// unfinished, are void.
44 Discard {
45 /// Identifiers of the void items.
46 ids: Vec<u64>,
47 },
48}
49
50/// What one streamed output item holds.
51#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
52pub enum OutputKind {
53 /// Assistant text.
54 Message,
55 /// Provider reasoning, such as a reasoning summary.
56 Reasoning,
57 /// A tool call whose arguments the model is still writing.
58 ToolCall,
59}