Skip to main content

ag_session/
agent_definition.rs

1//! Built-in task roles, independent of provider selection and personalities.
2
3use crate::PermissionMode;
4
5/// Built-in role contracts for a planner-to-implementer workflow.
6///
7/// These definitions do not dispatch work, select a model, or change ordinary
8/// session turns. A workflow may use the same session Smart
9/// [`crate::AgentSelection`] for both roles. Assignments, isolated
10/// conversations, and result handoff must be supplied by the workflow before
11/// these contracts can govern execution.
12#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
13pub enum BuiltinAgentDefinition {
14    /// Inspects the workspace and proposes a plan without making changes.
15    Planner,
16    /// Implements an explicitly accepted plan within session permissions.
17    Implementer,
18}
19
20impl BuiltinAgentDefinition {
21    /// Stable role identity, separate from provider kind or personality ID.
22    pub fn id(self) -> &'static str {
23        match self {
24            Self::Planner => "planner",
25            Self::Implementer => "implementer",
26        }
27    }
28
29    /// Resolves a stable role identity produced by [`Self::id`].
30    pub fn from_id(id: &str) -> Option<Self> {
31        match id {
32            "planner" => Some(Self::Planner),
33            "implementer" => Some(Self::Implementer),
34            _ => None,
35        }
36    }
37
38    /// Human-readable role name for transcripts and status displays.
39    pub fn display_name(self) -> &'static str {
40        match self {
41            Self::Planner => "Planner",
42            Self::Implementer => "Implementer",
43        }
44    }
45
46    /// Static application instructions, without interpolated user or model
47    /// data.
48    ///
49    /// A caller must preserve the protocol's policy and response schema when
50    /// delivering these instructions. Prompt text does not enforce permissions.
51    pub fn instructions(self) -> &'static str {
52        match self {
53            Self::Planner => include_str!("template/planner_instructions.md"),
54            Self::Implementer => include_str!("template/implementer_instructions.md"),
55        }
56    }
57
58    /// Explicit inputs required in the role's own conversation context.
59    pub fn context_requirement(self) -> AgentContextRequirement {
60        match self {
61            Self::Planner => AgentContextRequirement::UserRequest,
62            Self::Implementer => AgentContextRequirement::UserRequestAndAcceptedPlan,
63        }
64    }
65
66    /// Expected answer content, using the existing response protocol.
67    pub fn output_kind(self) -> AgentOutputKind {
68        match self {
69            Self::Planner => AgentOutputKind::Plan,
70            Self::Implementer => AgentOutputKind::ImplementationReport,
71        }
72    }
73
74    /// Restricts session permissions for this role without granting new access.
75    ///
76    /// Callers must pass this mode through worker/runtime permission
77    /// enforcement; resolving a value alone does not sandbox a run. Worker
78    /// execution policy remains an independent restriction. Implementers
79    /// retain read-only sessions and the session's existing
80    /// auto-address-comments behavior unchanged.
81    pub fn permission_mode(self, session_permission_mode: PermissionMode) -> PermissionMode {
82        match self {
83            Self::Planner => PermissionMode::ReadOnly,
84            Self::Implementer => session_permission_mode,
85        }
86    }
87}
88
89/// Inputs a workflow must explicitly supply, in addition to workspace access.
90///
91/// Each role requires its own conversation; another role's provider
92/// conversation must not be implicitly reused. These requirements describe the
93/// contract, not a context builder. They neither copy the session transcript
94/// nor grant access.
95#[derive(Clone, Copy, Debug, Eq, PartialEq)]
96pub enum AgentContextRequirement {
97    /// The original user request and any clarification addressed to this role.
98    UserRequest,
99    /// The original request, explicitly accepted plan, and relevant
100    /// clarification. A workflow must retain which planner attempt produced
101    /// the accepted plan; a successful attempt by itself does not establish
102    /// acceptance.
103    UserRequestAndAcceptedPlan,
104}
105
106/// Semantic answer content; does not replace the protocol's response schema.
107///
108/// Clarification uses the existing questions field and leaves the task open.
109/// Producing either output does not automatically accept or complete a task.
110#[derive(Clone, Copy, Debug, Eq, PartialEq)]
111pub enum AgentOutputKind {
112    /// Proposed steps, scope, assumptions, and validation for user input.
113    Plan,
114    /// Observed changes, verification results, and remaining work or blockers.
115    ImplementationReport,
116}
117
118#[cfg(test)]
119#[path = "agent_definition_test.rs"]
120mod tests;