Expand description
Parser and validator for the agent:// URI scheme.
This crate implements parsing, validation, and serialization of agent URIs as defined in the Agent Identity URI Scheme specification.
§Overview
Agent URIs provide topology-independent identity for agents with capability-based discovery. They have the structure:
agent://<trust-root>/<capability-path>/<agent-id>[?query][#fragment]§Quick Start
use agent_uri::AgentUri;
// Parse an agent URI
let uri = AgentUri::parse(
"agent://anthropic.com/assistant/chat/llm_chat_01h455vb4pex5vsknk084sn02q"
).unwrap();
// Access components
assert_eq!(uri.trust_root().host_str(), "anthropic.com");
assert_eq!(uri.capability_path().as_str(), "assistant/chat");
assert_eq!(uri.agent_id().prefix().as_str(), "llm_chat");
// Create new agent IDs
use agent_uri::AgentId;
let id = AgentId::new("llm_chat");
println!("New agent: {}", id);§Builder Pattern
Use the typestate builder for compile-time enforced construction:
use agent_uri::{AgentUriBuilder, TrustRoot, CapabilityPath, AgentId};
let uri = AgentUriBuilder::new()
.trust_root(TrustRoot::parse("anthropic.com").unwrap())
.capability_path(CapabilityPath::parse("assistant/chat").unwrap())
.agent_id(AgentId::new("llm_chat"))
.build()
.unwrap();
assert_eq!(uri.trust_root().host_str(), "anthropic.com");§Length Constraints
| Component | Max Length |
|---|---|
| Total URI | 512 chars |
| Trust root | 128 chars |
| Capability path | 256 chars |
| Path segments | 32 max count |
| Each segment | 64 chars |
| Agent ID prefix | 63 chars |
| Agent ID suffix | 26 chars (fixed) |
§Grammar Specification
This crate implements the ABNF grammar defined in grammar.abnf at the crate root.
The grammar follows RFC 5234 (ABNF) and specifies:
- URI structure:
agent://<trust-root>/<capability-path>/<agent-id>[?query][#fragment] - Trust root: Domain names, IPv4, and IPv6 addresses with optional ports
- Capability path: Hierarchical path with 1-32 segments
- Agent ID:
TypeIDformat with semantic prefix andUUIDv7suffix
See grammar.abnf for the complete formal specification.
Modules§
- prelude
- Convenient re-exports for glob imports.
Structs§
- AgentId
- A validated agent identifier in
TypeIDformat. - Agent
Prefix - A validated agent prefix (semantic type classification).
- Agent
Uri - A parsed and validated agent URI.
- Agent
UriBuilder - A typestate builder for constructing
AgentUriinstances. - Capability
Path - A validated capability path from an agent URI.
- Empty
- Marker: No components set yet.
- Extension
Class - An extension class name (custom type classes).
- Fragment
- A validated fragment from an agent URI.
- HasCapability
Path - Marker: Trust root and capability path have been set.
- HasTrust
Root - Marker: Trust root has been set.
- Parse
Error - Errors that can occur when parsing an agent URI.
- Path
Segment - A validated path segment in a capability path.
- Query
Params - Query parameters from an agent URI.
- Ready
- Marker: All required components are set, ready to build.
- Trust
Root - A validated trust root (authority) from an agent URI.
Enums§
- Agent
IdError - Errors for agent ID parsing.
- Agent
Prefix Error - Errors for agent prefix parsing.
- Builder
Error - Errors that can occur when building an agent URI.
- Capability
Path Error - Errors for capability path parsing.
- Fragment
Error - Errors for fragment parsing.
- Host
- The host portion of a trust root.
- Parse
Error Kind - Specific parsing error types.
- Path
Segment Error - Errors for path segment parsing.
- Query
Error - Errors for query string parsing.
- Trust
Root Error - Errors for trust root parsing.
- Type
Class - Primary type classification for agents.
Constants§
- AGENT_
SUFFIX_ LENGTH - Fixed agent-id suffix length (
UUIDv7in base32). - MAX_
AGENT_ ID_ LENGTH - Maximum total agent-id length (prefix + underscore + suffix).
- MAX_
AGENT_ PREFIX_ LENGTH - Maximum agent-id prefix length per
TypeIDspec. - MAX_
CAPABILITY_ PATH_ LENGTH - Maximum capability path length (all segments combined with slashes).
- MAX_
DNS_ DOMAIN_ LENGTH - DNS domain maximum length.
- MAX_
DNS_ LABEL_ LENGTH - DNS label maximum length.
- MAX_
PATH_ SEGMENTS - Maximum number of path segments.
- MAX_
PATH_ SEGMENT_ LENGTH - Maximum length of a single path segment.
- MAX_
TRUST_ ROOT_ LENGTH - Maximum trust root length including port.
- MAX_
URI_ LENGTH - Maximum total URI length in characters.
- SCHEME
- The URI scheme.