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