pub struct AgentUri { /* private fields */ }Expand description
A parsed and validated agent URI.
Agent URIs provide topology-independent identity for agents with capability-based discovery.
§Structure
agent://<trust-root>/<capability-path>/<agent-id>[?query][#fragment]§Examples
use agent_uri::AgentUri;
let uri = AgentUri::parse("agent://anthropic.com/assistant/chat/llm_chat_01h455vb4pex5vsknk084sn02q").unwrap();
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");
// With query and fragment
let uri = AgentUri::parse("agent://openai.com/tool/code/llm_01h455vb4pex5vsknk084sn02q?version=2.0#summarization").unwrap();
assert_eq!(uri.query().version(), Some("2.0"));
assert_eq!(uri.fragment().map(|f| f.as_str()), Some("summarization"));Implementations§
Source§impl AgentUri
impl AgentUri
Sourcepub fn parse(input: &str) -> Result<Self, ParseError>
pub fn parse(input: &str) -> Result<Self, ParseError>
Parses an agent URI from a string.
§Errors
Returns ParseError if:
- The URI is empty
- The URI exceeds 512 characters
- The scheme is not “agent://”
- Any component (trust root, path, agent ID, query, fragment) is invalid
Sourcepub fn new(
trust_root: TrustRoot,
capability_path: CapabilityPath,
agent_id: AgentId,
query: QueryParams,
fragment: Option<Fragment>,
) -> Result<Self, ParseError>
pub fn new( trust_root: TrustRoot, capability_path: CapabilityPath, agent_id: AgentId, query: QueryParams, fragment: Option<Fragment>, ) -> Result<Self, ParseError>
Creates a new agent URI from its components.
§Errors
Returns ParseError if the resulting URI would exceed the maximum length.
Sourcepub const fn trust_root(&self) -> &TrustRoot
pub const fn trust_root(&self) -> &TrustRoot
Returns the trust root.
Sourcepub const fn capability_path(&self) -> &CapabilityPath
pub const fn capability_path(&self) -> &CapabilityPath
Returns the capability path.
Sourcepub const fn query(&self) -> &QueryParams
pub const fn query(&self) -> &QueryParams
Returns the query parameters.
Sourcepub fn is_localhost(&self) -> bool
pub fn is_localhost(&self) -> bool
Returns true if this URI references a localhost agent.
Sourcepub fn with_query(&self, query: QueryParams) -> Result<Self, ParseError>
pub fn with_query(&self, query: QueryParams) -> Result<Self, ParseError>
Returns a new URI with the given query parameters.
§Errors
Returns ParseError if the resulting URI would exceed the maximum length.
§Examples
use agent_uri::{AgentUri, QueryParams};
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q").unwrap();
let query = QueryParams::parse("version=2.0").unwrap();
let updated = uri.with_query(query).unwrap();
assert_eq!(updated.query().version(), Some("2.0"));Sourcepub fn with_query_str(&self, s: &str) -> Result<Self, ParseError>
pub fn with_query_str(&self, s: &str) -> Result<Self, ParseError>
Returns a new URI with query parameters parsed from a string.
§Errors
Returns ParseError if the query string is invalid or the resulting URI
would exceed the maximum length.
§Examples
use agent_uri::AgentUri;
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q").unwrap();
let updated = uri.with_query_str("version=2.0&ttl=300").unwrap();
assert_eq!(updated.query().version(), Some("2.0"));
assert_eq!(updated.query().ttl(), Some(300));Sourcepub fn without_query(&self) -> Result<Self, ParseError>
pub fn without_query(&self) -> Result<Self, ParseError>
Returns a new URI without query parameters.
§Errors
Returns ParseError if the resulting URI would exceed the maximum length.
(This is unlikely but possible in edge cases.)
§Examples
use agent_uri::AgentUri;
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q?version=2.0").unwrap();
let updated = uri.without_query().unwrap();
assert!(updated.query().is_empty());Sourcepub fn with_fragment(&self, fragment: Fragment) -> Result<Self, ParseError>
pub fn with_fragment(&self, fragment: Fragment) -> Result<Self, ParseError>
Returns a new URI with the given fragment.
§Errors
Returns ParseError if the resulting URI would exceed the maximum length.
§Examples
use agent_uri::{AgentUri, Fragment};
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q").unwrap();
let fragment = Fragment::parse("summarization").unwrap();
let updated = uri.with_fragment(fragment).unwrap();
assert_eq!(updated.fragment().map(|f| f.as_str()), Some("summarization"));Sourcepub fn with_fragment_str(&self, s: &str) -> Result<Self, ParseError>
pub fn with_fragment_str(&self, s: &str) -> Result<Self, ParseError>
Returns a new URI with a fragment parsed from a string.
§Errors
Returns ParseError if the fragment is invalid or the resulting URI
would exceed the maximum length.
§Examples
use agent_uri::AgentUri;
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q").unwrap();
let updated = uri.with_fragment_str("summarization").unwrap();
assert_eq!(updated.fragment().map(|f| f.as_str()), Some("summarization"));Sourcepub fn without_fragment(&self) -> Result<Self, ParseError>
pub fn without_fragment(&self) -> Result<Self, ParseError>
Returns a new URI without a fragment.
§Errors
Returns ParseError if the resulting URI would exceed the maximum length.
(This is unlikely but possible in edge cases.)
§Examples
use agent_uri::AgentUri;
let uri = AgentUri::parse("agent://anthropic.com/chat/llm_01h455vb4pex5vsknk084sn02q#test").unwrap();
let updated = uri.without_fragment().unwrap();
assert!(updated.fragment().is_none());Trait Implementations§
impl Eq for AgentUri
Source§impl Ord for AgentUri
impl Ord for AgentUri
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for AgentUri
impl PartialOrd for AgentUri
impl StructuralPartialEq for AgentUri
Auto Trait Implementations§
impl Freeze for AgentUri
impl RefUnwindSafe for AgentUri
impl Send for AgentUri
impl Sync for AgentUri
impl Unpin for AgentUri
impl UnsafeUnpin for AgentUri
impl UnwindSafe for AgentUri
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> PrefixFactory for T
impl<T> PrefixFactory for T
Source§fn create_prefix_sanitized(&self) -> TypeIdPrefix
fn create_prefix_sanitized(&self) -> TypeIdPrefix
TypeIdPrefix. Read moreSource§fn try_create_prefix(&self) -> Result<TypeIdPrefix, ValidationError>
fn try_create_prefix(&self) -> Result<TypeIdPrefix, ValidationError>
TypeIdPrefix from the input without modifying it. Read more