enact-core 0.0.2

Core agent runtime for Enact - Graph-Native AI agents
Documentation
//! Invocation Context - Context for agent/tool invocation
//!
//! Extends RuntimeContext with invocation-specific fields like input
//! and available services.

use super::execution_context::RuntimeContext;
use crate::kernel::{ExecutionId, StepId};
use serde::{Deserialize, Serialize};

/// Services available during invocation
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InvocationServices {
    /// Memory service available
    pub memory: bool,
    /// Artifact storage available
    pub artifacts: bool,
    /// Tool registry available
    pub tools: bool,
}

impl InvocationServices {
    /// Create with all services enabled
    pub fn all() -> Self {
        Self {
            memory: true,
            artifacts: true,
            tools: true,
        }
    }

    /// Create with no services
    pub fn none() -> Self {
        Self::default()
    }
}

/// InvocationContext - Context for invoking an agent or tool
///
/// Extends RuntimeContext with invocation-specific fields like input
/// and available services.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvocationContext {
    /// Runtime context
    pub runtime: RuntimeContext,

    /// Invocation input
    pub input: serde_json::Value,

    /// Services available to the invocation
    pub services: InvocationServices,
}

impl InvocationContext {
    /// Create a new InvocationContext
    pub fn new(runtime: RuntimeContext, input: serde_json::Value) -> Self {
        Self {
            runtime,
            input,
            services: InvocationServices::default(),
        }
    }

    /// Enable all services
    pub fn with_all_services(mut self) -> Self {
        self.services = InvocationServices::all();
        self
    }

    /// Enable specific services
    pub fn with_services(mut self, services: InvocationServices) -> Self {
        self.services = services;
        self
    }

    /// Get the execution ID
    pub fn execution_id(&self) -> &ExecutionId {
        &self.runtime.execution_id
    }

    /// Get the step ID
    pub fn step_id(&self) -> Option<&StepId> {
        self.runtime.step_id.as_ref()
    }

    /// Get the runtime context
    pub fn runtime(&self) -> &RuntimeContext {
        &self.runtime
    }

    /// Get the input
    pub fn input(&self) -> &serde_json::Value {
        &self.input
    }

    /// Get input as string (convenience method)
    pub fn input_str(&self) -> Option<&str> {
        self.input.as_str()
    }
}