Skip to main content

enact_core/context/
invocation.rs

1//! Invocation Context - Context for agent/tool invocation
2//!
3//! Extends RuntimeContext with invocation-specific fields like input
4//! and available services.
5
6use super::execution_context::RuntimeContext;
7use crate::kernel::{ExecutionId, StepId};
8use serde::{Deserialize, Serialize};
9
10/// Services available during invocation
11#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct InvocationServices {
13    /// Memory service available
14    pub memory: bool,
15    /// Artifact storage available
16    pub artifacts: bool,
17    /// Tool registry available
18    pub tools: bool,
19}
20
21impl InvocationServices {
22    /// Create with all services enabled
23    pub fn all() -> Self {
24        Self {
25            memory: true,
26            artifacts: true,
27            tools: true,
28        }
29    }
30
31    /// Create with no services
32    pub fn none() -> Self {
33        Self::default()
34    }
35}
36
37/// InvocationContext - Context for invoking an agent or tool
38///
39/// Extends RuntimeContext with invocation-specific fields like input
40/// and available services.
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct InvocationContext {
43    /// Runtime context
44    pub runtime: RuntimeContext,
45
46    /// Invocation input
47    pub input: serde_json::Value,
48
49    /// Services available to the invocation
50    pub services: InvocationServices,
51}
52
53impl InvocationContext {
54    /// Create a new InvocationContext
55    pub fn new(runtime: RuntimeContext, input: serde_json::Value) -> Self {
56        Self {
57            runtime,
58            input,
59            services: InvocationServices::default(),
60        }
61    }
62
63    /// Enable all services
64    pub fn with_all_services(mut self) -> Self {
65        self.services = InvocationServices::all();
66        self
67    }
68
69    /// Enable specific services
70    pub fn with_services(mut self, services: InvocationServices) -> Self {
71        self.services = services;
72        self
73    }
74
75    /// Get the execution ID
76    pub fn execution_id(&self) -> &ExecutionId {
77        &self.runtime.execution_id
78    }
79
80    /// Get the step ID
81    pub fn step_id(&self) -> Option<&StepId> {
82        self.runtime.step_id.as_ref()
83    }
84
85    /// Get the runtime context
86    pub fn runtime(&self) -> &RuntimeContext {
87        &self.runtime
88    }
89
90    /// Get the input
91    pub fn input(&self) -> &serde_json::Value {
92        &self.input
93    }
94
95    /// Get input as string (convenience method)
96    pub fn input_str(&self) -> Option<&str> {
97        self.input.as_str()
98    }
99}