Skip to main content

gemini_adk_fluent_rs/
tasks.rs

1//! Skill authoring and the shared task runtime.
2
3pub use crate::spec::{
4    SkillSpec, SkillToolSpec, TaskExpectation, TaskObservationKind, TaskScenario, TaskStep,
5    TaskTraceSnapshot,
6};
7pub use gemini_adk_rs::tasks::*;
8
9/// Small fluent authoring surface over the serializable skill definition.
10#[derive(Debug, Clone)]
11pub struct Skill {
12    spec: SkillSpec,
13}
14
15impl Skill {
16    /// Start a versioned local capability.
17    pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
18        Self {
19            spec: SkillSpec {
20                name: name.into(),
21                version: version.into(),
22                ..Default::default()
23            },
24        }
25    }
26    /// Set the short catalog description.
27    pub fn description(mut self, text: impl Into<String>) -> Self {
28        self.spec.description = text.into();
29        self
30    }
31    /// Set instructions loaded when this capability is foreground.
32    pub fn instruction(mut self, text: impl Into<String>) -> Self {
33        self.spec.instruction = text.into();
34        self
35    }
36    /// Declare a typed input field.
37    pub fn input(mut self, name: impl Into<String>, field: crate::spec::StateFieldSpec) -> Self {
38        self.spec.inputs.insert(name.into(), field);
39        self
40    }
41    /// Declare a state field exported on completion.
42    pub fn output(mut self, name: impl Into<String>, field: crate::spec::StateFieldSpec) -> Self {
43        self.spec.outputs.insert(name.into(), field);
44        self
45    }
46    /// Add a declared operation with an explicit external-effect policy.
47    pub fn tool(mut self, tool: crate::spec::ToolSpec, effect: TaskToolEffect) -> Self {
48        self.spec.tools.push(SkillToolSpec { tool, effect });
49        self
50    }
51    /// Attach optional user-facing stages and digressions.
52    pub fn conversation(mut self, conversation: crate::conversation::ConversationSpec) -> Self {
53        self.spec.conversation = Some(conversation);
54        self
55    }
56    /// Declare task-private state and its optional default.
57    pub fn state(mut self, name: impl Into<String>, field: crate::spec::StateFieldSpec) -> Self {
58        self.spec.state.insert(name.into(), field);
59        self
60    }
61    /// Extract structured fields from this activation's owned transcript.
62    pub fn extract(mut self, extractor: crate::spec::ExtractSpec) -> Self {
63        self.spec.extract.push(extractor);
64        self
65    }
66    /// Add a dependency-ordered derived state value.
67    pub fn computed(mut self, computed: crate::spec::ComputedSpec) -> Self {
68        self.spec.computed.push(computed);
69        self
70    }
71    /// React to an accepted task-local state change.
72    pub fn watch(mut self, watch: crate::spec::WatchSpec) -> Self {
73        self.spec.watch.push(watch);
74        self
75    }
76    /// Detect a condition over task-local turns or active time.
77    pub fn pattern(mut self, pattern: crate::spec::PatternSpec) -> Self {
78        self.spec.patterns.push(pattern);
79        self
80    }
81    /// Project declared memory slots through the existing memory binding.
82    pub fn memory(mut self, memory: crate::spec::MemorySpec) -> Self {
83        self.spec.memory = Some(memory);
84        self
85    }
86    /// Compile tools to be rebound against each private invocation snapshot.
87    pub fn compile(self, resources: &crate::spec::SpecResources) -> Result<CompiledSkill, String> {
88        self.spec.compile(resources)
89    }
90    /// Return the data document for editors or publication through existing bundles.
91    pub fn into_spec(self) -> SkillSpec {
92        self.spec
93    }
94}