Skip to main content

systemprompt_identifiers/
agent.rs

1//! Agent identity newtypes: opaque [`AgentId`] (UUID-backed), checked
2//! [`AgentName`] (non-empty, rejects the `"unknown"`/`"unset"` sentinels), and
3//! [`ExternalAgentId`] for off-platform "super-agents" (Claude Desktop,
4//! Codex CLI, Claude Code) that connect via the bridge binary.
5//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9crate::define_id!(AgentId, generate, schema);
10crate::define_id!(ExternalAgentId, non_empty);
11
12use crate::error::IdValidationError;
13
14crate::define_id!(AgentName, checked, validate_agent_name);
15
16fn validate_agent_name(name: &str) -> Result<(), IdValidationError> {
17    if name.trim().is_empty() {
18        return Err(IdValidationError::empty("AgentName"));
19    }
20    if name.eq_ignore_ascii_case("unknown") || name.eq_ignore_ascii_case("unset") {
21        return Err(IdValidationError::invalid(
22            "AgentName",
23            format!("'{name}' is a reserved sentinel, not an agent name"),
24        ));
25    }
26    Ok(())
27}
28
29impl AgentName {
30    pub fn system() -> Self {
31        Self("system".to_owned())
32    }
33
34    pub fn bridge() -> Self {
35        Self("bridge".to_owned())
36    }
37}