1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Capability-based DHT discovery for the agent:// URI scheme.
//!
//! This crate provides DHT (Distributed Hash Table) infrastructure for
//! discovering agents by their capabilities. It includes:
//!
//! - **Key derivation**: [`DhtKey`] for Kademlia-style routing
//! - **Registration records**: [`Registration`] with endpoints and attestations
//! - **Trait interface**: [`Dht`] trait for abstracting DHT implementations
//! - **In-memory simulation**: [`SimulatedDht`] for evaluation and testing
//! - **Prefix matching**: [`PathTrie`] for efficient hierarchical discovery
//!
//! # Overview
//!
//! The core idea is that agents register at DHT keys derived from their
//! trust root and capability path:
//!
//! ```text
//! key = SHA256(trust_root || "/" || capability_path)
//! ```
//!
//! This enables capability-based discovery: "find me an agent at
//! `anthropic.com` that can do `assistant/chat`".
//!
//! # Quick Start
//!
//! ```rust
//! use agent_uri::{AgentUri, CapabilityPath, TrustRoot};
//! use agent_uri_dht::{Dht, Endpoint, Registration, SimulatedDht, SimulationConfig};
//!
//! // Create a simulated DHT
//! let dht = SimulatedDht::new(SimulationConfig::default());
//!
//! // Register an agent
//! let uri = AgentUri::parse(
//! "agent://anthropic.com/assistant/chat/llm_01h455vb4pex5vsknk084sn02q"
//! ).unwrap();
//! let endpoint = Endpoint::https("agent.anthropic.com:443");
//! let registration = Registration::new(uri, vec![endpoint]);
//!
//! dht.register(registration).unwrap();
//!
//! // Discover agents by capability
//! let results = dht.lookup_prefix(
//! &TrustRoot::parse("anthropic.com").unwrap(),
//! &CapabilityPath::parse("assistant").unwrap(),
//! ).unwrap();
//!
//! assert_eq!(results.len(), 1);
//! ```
//!
//! # Key Derivation
//!
//! DHT keys are derived deterministically from trust root and capability path
//! using SHA-256. This enables:
//!
//! - **Exact lookup**: Find agents at a specific capability path
//! - **Prefix lookup**: Find agents at a path and all child paths
//! - **Cross-trust-root lookup**: Find agents with a capability across all authorities
//!
//! ```rust
//! use agent_uri::{TrustRoot, CapabilityPath};
//! use agent_uri_dht::DhtKey;
//!
//! let trust_root = TrustRoot::parse("anthropic.com").unwrap();
//! let path = CapabilityPath::parse("assistant/chat").unwrap();
//!
//! // Derive a key for this capability
//! let key = DhtKey::derive(&trust_root, &path);
//!
//! // Keys are deterministic
//! let key2 = DhtKey::derive(&trust_root, &path);
//! assert_eq!(key, key2);
//!
//! // Partial depth for hierarchical queries
//! let parent_key = DhtKey::derive_at_depth(&trust_root, &path, 1).unwrap();
//! ```
//!
//! # Agent Migration
//!
//! The identity stability of agent:// URIs means agents can migrate
//! between network locations without changing their identity:
//!
//! ```rust
//! use agent_uri::AgentUri;
//! use agent_uri_dht::{Dht, Endpoint, Registration, SimulatedDht, SimulationConfig};
//!
//! let dht = SimulatedDht::with_defaults();
//!
//! let uri = AgentUri::parse(
//! "agent://anthropic.com/assistant/chat/llm_01h455vb4pex5vsknk084sn02q"
//! ).unwrap();
//!
//! // Register at initial location
//! let registration = Registration::new(
//! uri.clone(),
//! vec![Endpoint::https("us-east-1.agent.anthropic.com")]
//! );
//! dht.register(registration).unwrap();
//!
//! // Migrate to new location (same identity)
//! dht.update_endpoint(
//! &uri,
//! vec![Endpoint::https("eu-west-1.agent.anthropic.com")]
//! ).unwrap();
//! ```
pub use SimulationConfig;
pub use Endpoint;
pub use DhtError;
pub use DhtKey;
pub use Registration;
pub use SimulatedDht;
pub use ;
pub use Dht;
pub use PathTrie;