Skip to main content

conversation_api/execution/
agent.rs

1//! Commands accepted by the transport-independent Runtime.
2
3use serde::{Deserialize, Serialize};
4
5use crate::execution::{InvocationContext, Message, MessageId, RunId, UseCase};
6
7/// Mutation policy for tools that can change application state.
8#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum AccessMode {
11    /// Operations requiring approval are denied without creating an interaction.
12    /// Operations requiring no approval remain available.
13    NoAccess,
14    /// Mutating tools pause after prepare and require a user decision.
15    #[default]
16    Interactive,
17    /// Mutating tools may be committed without a user interaction.
18    FullAccess,
19}
20
21/// Per-run policy supplied by a deployment rather than selected through conditional compilation.
22#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
23#[serde(deny_unknown_fields)]
24pub struct RunOptions {
25    /// Logical LLM route selected by the deployment.
26    pub use_case: UseCase,
27
28    /// Tool mutation policy.
29    pub access_mode: AccessMode,
30    /// Whether this run may expose any tools to the model.
31    pub allow_tools: bool,
32    /// Maximum LLM/tool loop steps requested by the caller.
33    pub max_steps: u32,
34    /// Optional maximum normalized credits the run may consume.
35    pub credit_budget: Option<u64>,
36    /// Requests additional sanitized diagnostic observations when enabled.
37    pub debug: bool,
38}
39
40/// User decisions submitted to a waiting run.
41#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
42#[serde(deny_unknown_fields)]
43pub struct Interaction {
44    /// Batch identifier emitted by `InteractionRequired`.
45    pub batch_id: MessageId,
46    /// One response for every waiting item in the batch.
47    pub responses: Vec<crate::InteractionResponse>,
48}
49
50/// Durable request waiting to enter the Runtime execution loop.
51#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
52pub struct QueuedRun {
53    /// Invocation identity frozen when the request is accepted.
54    pub context: InvocationContext,
55    /// User-supplied multimodal message.
56    pub message: Message,
57    /// Runtime policy frozen when the request is accepted.
58    pub options: RunOptions,
59}
60
61impl QueuedRun {
62    /// Returns the stable run identifier used for queue idempotency.
63    #[must_use]
64    pub fn run_id(&self) -> &RunId {
65        &self.context.run_id
66    }
67}
68
69/// Semantic commands understood by the Runtime.
70#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
71#[serde(tag = "type", rename_all = "snake_case")]
72#[serde(deny_unknown_fields)]
73pub enum AgentCommand {
74    /// Enqueues a new user message.
75    Enqueue {
76        /// Invocation identity and ownership.
77        context: InvocationContext,
78        /// User-supplied multimodal message.
79        message: Message,
80        /// Runtime policy for this run.
81        options: RunOptions,
82    },
83    /// Supplies a response to a pending interaction.
84    SubmitInteraction {
85        /// Invocation identity and ownership.
86        context: InvocationContext,
87        /// Submitted interaction.
88        interaction: Interaction,
89    },
90    /// Requests cancellation of the current run.
91    Cancel {
92        /// Invocation identity and ownership.
93        context: InvocationContext,
94    },
95}