Skip to main content

made_core/ports/
agent_factory.rs

1//! [`AgentFactoryPort`] — materialize an [`AgentPort`] from a typed descriptor.
2//!
3//! Callers (the composition root and the `RegisterAgent` RPC) do not
4//! construct agent implementations directly; they hand a descriptor to
5//! this factory and receive a live handle back. That keeps the set of
6//! wired providers (vLLM, Anthropic, OpenAI, rule-based, human-in-the-
7//! loop, …) behind Cargo features at the adapter layer, exactly like
8//! every other provider-specific concern in this crate.
9//!
10//! The `kind` field in [`AgentDescriptor`] names the provider the
11//! factory should dispatch to. Adapters return
12//! [`DomainError::InvariantViolated`] when asked for a kind they do
13//! not support; the composition root is responsible for wiring a
14//! factory that recognises every kind the deployment intends to accept.
15
16use std::sync::Arc;
17
18use crate::error::DomainError;
19use crate::ports::agent::AgentPort;
20use crate::ports::AgentDescriptor;
21use async_trait::async_trait;
22
23#[async_trait]
24pub trait AgentFactoryPort: Send + Sync {
25    /// Produce a live agent matching `descriptor`.
26    ///
27    /// Adapters that do not recognise `descriptor.kind` must return
28    /// [`DomainError::InvariantViolated`] with a reason naming the
29    /// unsupported kind, so operators see the mismatch loudly.
30    async fn create(&self, descriptor: AgentDescriptor) -> Result<Arc<dyn AgentPort>, DomainError>;
31}