1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Shared Agent contract and input types.
//!
//! Runtime-owned execution graphs and node state live under `runtime::agent`.
use futures_core::Stream;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use crate::Cancellation;
use crate::components::event::Event;
pub type Error = crate::Error;
/// Public business input shared by ChatAgent and ReActAgent.
///
/// Runtime metadata is kept separate from the user payload. Execution source
/// identities stay in Input/Runtime, not internal Message metadata. Other
/// input metadata is retained while payload becomes ordered model content.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, JsonSchema)]
pub struct Input {
#[serde(default)]
pub metadata: Map<String, Value>,
#[serde(default)]
pub payload: Vec<Payload>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)]
pub struct Payload {
#[serde(rename = "type")]
pub r#type: String,
pub data: Value,
pub mime_type: Option<String>,
}
pub trait Agent: Send + Sync {
type Stream: Stream<Item = Result<Event, Error>> + 'static;
/// Fix outward delivery for this invocation: true delivers Delta and
/// Complete, false delivers Complete only. Errors and per-call Complete
/// results are retained in both modes; the stream type never changes.
///
/// `cancellation` is this invocation's cancellation scope. Create a fresh
/// value for each independent run; clones are for work belonging to this
/// run and share its cancellation state.
fn run(
&self,
input: Input,
stream: bool,
cancellation: Cancellation,
) -> impl Future<Output = Result<Self::Stream, Error>>;
/// Submit feedback to a live question. Business events stay on run's stream.
/// The cancellation value scopes this reply submission, not other runs.
fn reply(
&self,
input: Input,
cancellation: Cancellation,
) -> impl Future<Output = Result<(), Error>>;
}