klieo-ops 0.2.0

Operational layer above klieo-core: supervisor, governor, gates, escalation, worklog, handoff.
Documentation
//! Generic Agent wrapper. Pass-through in Phase A skeleton; subsequent
//! tasks graft supervisor / governor / gates hooks into the `run` body.

use async_trait::async_trait;
use klieo_core::{Agent, AgentContext, ToolDef};
use std::sync::Arc;

use crate::tenant::{scope_tenant, TenantResolver};

/// Wrapper around `A: Agent` that threads tenant resolution and (in
/// subsequent tasks) supervisor / governor / gate hooks.
pub struct SupervisedAgent<A: Agent> {
    pub(crate) inner: A,
    pub(crate) tenant_resolver: Arc<dyn TenantResolver>,
}

#[async_trait]
impl<A> Agent for SupervisedAgent<A>
where
    A: Agent + 'static,
    A::Input: Send + 'static,
    A::Output: Send + 'static,
    A::Error: Send + Sync + 'static,
{
    type Input = A::Input;
    type Output = A::Output;
    type Error = A::Error;

    fn name(&self) -> &str {
        self.inner.name()
    }
    fn system_prompt(&self) -> &str {
        self.inner.system_prompt()
    }
    fn tools(&self) -> &[ToolDef] {
        self.inner.tools()
    }

    async fn run(
        &self,
        ctx: AgentContext,
        input: Self::Input,
    ) -> Result<Self::Output, Self::Error> {
        let tenant = self.tenant_resolver.resolve().await;
        scope_tenant(tenant, async move { self.inner.run(ctx, input).await }).await
    }
}