pub struct AgentId { /* private fields */ }Expand description
A validated agent identifier in TypeID format.
The agent ID uniquely identifies an agent and encodes:
- Semantic classification (the prefix)
- Unique identity (the
UUIDv7suffix) - Creation timestamp (encoded in
UUIDv7)
§Format
<prefix>_<suffix> where:
- prefix: 1-63 lowercase letters and underscores
- suffix: 26 character base32-encoded
UUIDv7
§Examples
use agent_uri::AgentId;
let id = AgentId::parse("llm_01h455vb4pex5vsknk084sn02q").unwrap();
assert_eq!(id.prefix().as_str(), "llm");
assert_eq!(id.suffix(), "01h455vb4pex5vsknk084sn02q");
// Create a new agent ID
let id = AgentId::new("llm_chat");
assert_eq!(id.suffix().len(), 26);Implementations§
Source§impl AgentId
impl AgentId
Sourcepub fn new(prefix: &str) -> Self
pub fn new(prefix: &str) -> Self
Creates a new agent ID with the given prefix and a fresh UUIDv7.
§Panics
Panics if the prefix is invalid. Use AgentId::try_new for fallible creation.
Sourcepub fn try_new(prefix: &str) -> Result<Self, AgentIdError>
pub fn try_new(prefix: &str) -> Result<Self, AgentIdError>
Creates a new agent ID with the given prefix and a fresh UUIDv7.
§Errors
Returns AgentIdError if the prefix is invalid.
Sourcepub fn parse(input: &str) -> Result<Self, AgentIdError>
pub fn parse(input: &str) -> Result<Self, AgentIdError>
Parses an agent ID from a string.
§Errors
Returns AgentIdError if:
- The input is empty
- The input exceeds 90 characters
- The prefix is invalid
- The suffix is invalid (not valid base32 or wrong length)
- The separator is missing
Sourcepub const fn prefix(&self) -> &AgentPrefix
pub const fn prefix(&self) -> &AgentPrefix
Returns the prefix (semantic classification).
Sourcepub const fn inner(&self) -> &MagicTypeId
pub const fn inner(&self) -> &MagicTypeId
Returns the underlying MagicTypeId.
Trait Implementations§
Source§impl AsRef<MagicTypeId> for AgentId
impl AsRef<MagicTypeId> for AgentId
Source§fn as_ref(&self) -> &MagicTypeId
fn as_ref(&self) -> &MagicTypeId
Converts this type into a shared reference of the (usually inferred) input type.
impl Eq for AgentId
Source§impl Ord for AgentId
impl Ord for AgentId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for AgentId
impl PartialOrd for AgentId
impl StructuralPartialEq for AgentId
Auto Trait Implementations§
impl Freeze for AgentId
impl RefUnwindSafe for AgentId
impl Send for AgentId
impl Sync for AgentId
impl Unpin for AgentId
impl UnsafeUnpin for AgentId
impl UnwindSafe for AgentId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more