use async_trait::async_trait;
use klieo_core::{Agent, AgentContext, ToolDef};
use std::sync::Arc;
use crate::tenant::{scope_tenant, TenantResolver};
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
}
}