ag_protocol/graph_proposal.rs
1//! Model-authored graph proposals, before host resolution and approval.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::{ProtocolRequestProfile, QuestionItem};
7
8/// Direct structured response to an initial graph-generation request.
9///
10/// The object wrapper keeps the transport schema rooted at an object. A
11/// proposal describes requirements only: it grants no execution authority.
12#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
13#[serde(deny_unknown_fields)]
14pub struct GraphProposalResponse {
15 /// Either missing information or one complete proposal, never both.
16 pub outcome: GraphProposalOutcome,
17}
18
19/// Mutually exclusive outcomes of proposal generation.
20#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
21#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
22pub enum GraphProposalOutcome {
23 /// Ask only for information required to propose a complete graph.
24 Clarification {
25 /// Nonempty ordered questions; no partial graph accompanies them.
26 #[schemars(length(min = 1, max = crate::model::MAX_QUESTIONS))]
27 questions: Vec<QuestionItem>,
28 },
29 /// Supply the complete graph for host validation and inspection.
30 Proposal {
31 /// Declarative graph; resolution and approval remain host-owned.
32 proposal: GraphProposal,
33 },
34}
35
36/// Complete logical graph, without runtime identities or acceptance evidence.
37#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
38#[serde(deny_unknown_fields)]
39pub struct GraphProposal {
40 /// Nonempty nodes whose references are local to this proposal.
41 #[schemars(length(min = 1))]
42 pub nodes: Vec<GraphProposalNode>,
43}
44
45/// One proposed invocation of an available agent definition.
46#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
47#[serde(deny_unknown_fields)]
48pub struct GraphProposalNode {
49 /// Exact identifier from the host-supplied available agent catalog.
50 pub agent_id: String,
51 /// All prerequisites required before this node may run.
52 pub dependencies: Vec<GraphProposalDependency>,
53 /// Declarative requirements, subject to host support and permissions.
54 pub execution: GraphProposalExecution,
55 /// Logical identifier unique within this proposal, not a runtime ID.
56 pub id: String,
57 /// Named handoffs from declared outputs on prerequisite nodes.
58 pub inputs: Vec<GraphProposalInput>,
59 /// Desired outcome, separate from the referenced agent's instructions.
60 pub objective: String,
61 /// Named outputs containing the complete response under its schema.
62 pub outputs: Vec<GraphProposalOutput>,
63}
64
65/// Execution requirements that contain no model, Env, task, or budget IDs.
66#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
67#[serde(deny_unknown_fields)]
68pub struct GraphProposalExecution {
69 /// Fresh utility or isolated task conversation; the host allocates context.
70 pub context: GraphProposalContext,
71 /// Requested host effects; this does not authorize those effects.
72 pub post_processing: GraphProposalPostProcessing,
73 /// Protocol schema to enforce for this node's response.
74 pub response_profile: ProtocolRequestProfile,
75 /// Requested Env access, intersected with host and agent restrictions.
76 pub workspace_access: GraphProposalWorkspaceAccess,
77}
78
79/// Context lifetime requested without a host-owned task identity.
80#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
81#[serde(rename_all = "snake_case")]
82pub enum GraphProposalContext {
83 /// Isolated utility with a fresh context for each execution.
84 Fresh,
85 /// Isolated, resumable task context allocated by the host.
86 TaskConversation,
87}
88
89/// Requested host post-processing, independent of model tools.
90#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
91#[serde(rename_all = "snake_case")]
92pub enum GraphProposalPostProcessing {
93 /// No mutating host effects.
94 None,
95 /// Ordered session effects, if authorized by the host.
96 SessionWorkflow,
97}
98
99/// Resource requirements within the session Env, never a permission grant.
100#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
101#[serde(rename_all = "snake_case")]
102pub enum GraphProposalWorkspaceAccess {
103 /// Share read-only access with other graph readers.
104 SharedRead,
105 /// Fresh read-only utility that tolerates concurrent ordinary host work.
106 BackgroundRead,
107 /// Serialize against all other Env work; writes still require permission.
108 ExclusiveWrite,
109}
110
111/// Logical prerequisite; evidence satisfying it must come from the host.
112#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
113#[serde(deny_unknown_fields)]
114pub struct GraphProposalDependency {
115 /// Required condition, distinct from approval of the graph itself.
116 pub gate: GraphProposalGate,
117 /// Producing node's logical identifier in this proposal.
118 pub node_id: String,
119}
120
121/// Host-established condition needed before a dependent node runs.
122#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
123#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
124pub enum GraphProposalGate {
125 /// Successful execution including ordered host effects and no questions.
126 ExecutionSucceeded {},
127 /// Successful, question-free execution with a validated named output.
128 ResultValidated {
129 /// Declared output on the prerequisite node.
130 output_name: String,
131 },
132 /// Explicit host-recorded acceptance of an exact validated output version.
133 ResultAccepted {
134 /// Declared output on the prerequisite node.
135 output_name: String,
136 },
137}
138
139/// Named input referencing a producer's output, without an execution identity.
140#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
141#[serde(deny_unknown_fields)]
142pub struct GraphProposalInput {
143 /// Slot name unique on the consumer.
144 pub name: String,
145 /// Declared output name on the producer.
146 pub output_name: String,
147 /// Logical producer node, protected by a matching result dependency gate.
148 pub producer_node_id: String,
149}
150
151/// Named complete response; it does not assert validation or acceptance.
152#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
153#[serde(deny_unknown_fields)]
154pub struct GraphProposalOutput {
155 /// Output name unique on the producer.
156 pub name: String,
157 /// Must match the producing node's response profile.
158 pub schema: ProtocolRequestProfile,
159}