Skip to main content

ag_ui/
input.rs

1//! The request body an agent receives to start or resume a run.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::context::Context;
7use crate::ids::{RunId, ThreadId};
8use crate::message::Message;
9use crate::outcome::ResumeEntry;
10use crate::tool::Tool;
11
12/// Everything an agent needs for one run.
13///
14/// This is the body of the AG-UI run request, and it is also embedded verbatim
15/// in [`RunStartedEvent::input`](crate::event::RunStartedEvent::input) so a
16/// recorded stream can be replayed without the original request.
17#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
20#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
21pub struct RunAgentInput {
22    /// The conversation this run belongs to.
23    pub thread_id: ThreadId,
24    /// This run's id, echoed on every lifecycle event.
25    pub run_id: RunId,
26    /// The run that spawned this one, for nested / delegated agents.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub parent_run_id: Option<RunId>,
29    /// Shared state, mutated by the agent through `STATE_SNAPSHOT` and
30    /// `STATE_DELTA`. Free-form JSON, opaque to the protocol.
31    /// Null and absent state serialize as omitted, matching upstream normalization.
32    #[serde(default, skip_serializing_if = "Value::is_null")]
33    pub state: Value,
34    /// Conversation history, oldest first.
35    pub messages: Vec<Message>,
36    /// Tools the client is offering for this run.
37    pub tools: Vec<Tool>,
38    /// Ambient context entries.
39    pub context: Vec<Context>,
40    /// Arbitrary passthrough properties, opaque to the protocol.
41    #[serde(default)]
42    pub forwarded_props: Value,
43    /// Answers to the interrupts a previous run paused on. Present only when
44    /// resuming — see [`crate::outcome`].
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub resume: Option<Vec<ResumeEntry>>,
47}
48
49impl RunAgentInput {
50    /// Builds an input with only the two required identifiers set.
51    pub fn new(thread_id: impl Into<ThreadId>, run_id: impl Into<RunId>) -> Self {
52        Self {
53            thread_id: thread_id.into(),
54            run_id: run_id.into(),
55            ..Default::default()
56        }
57    }
58
59    /// Whether this request resumes a paused run.
60    pub fn is_resume(&self) -> bool {
61        self.resume.as_ref().is_some_and(|r| !r.is_empty())
62    }
63}