use crate::blueprint::compiler::RustFnInProcessSpawnerFactory;
use crate::worker::adapter::WorkerResult;
use serde_json::json;
pub const AG_IDENTITY: &str = "identity";
pub fn extend_with_baseline(base: RustFnInProcessSpawnerFactory) -> RustFnInProcessSpawnerFactory {
base.register_fn(AG_IDENTITY, |inv| async move {
Ok(WorkerResult {
value: json!({
"by": "baseline-identity",
"agent": inv.agent,
"echoed": inv.prompt,
}),
ok: true,
})
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::blueprint::compiler::{SpawnerFactory, SpawnerFactoryKind};
use crate::blueprint::{AgentDef, AgentKind};
use serde_json::json;
#[test]
fn ag_identity_is_stable_literal() {
assert_eq!(AG_IDENTITY, "identity");
}
#[test]
fn extend_with_baseline_builds_identity_adapter() {
let factory = extend_with_baseline(RustFnInProcessSpawnerFactory::new());
assert_eq!(
<RustFnInProcessSpawnerFactory as SpawnerFactoryKind>::KIND,
AgentKind::RustFn
);
let agent_def = AgentDef {
name: "id".into(),
kind: AgentKind::RustFn,
spec: json!({ "fn_id": AG_IDENTITY }),
profile: None,
meta: None,
};
factory
.build(&agent_def, None)
.expect("AG_IDENTITY fn must be registered for AgentDef build");
}
}