Skip to main content

treeship_core/
agent.rs

1//! Agent Identity Certificate schema.
2//!
3//! An Agent Identity Certificate is a signed credential that proves who an
4//! agent is and what it is authorized to do. Produced once when an agent
5//! registers, lives permanently with the agent. The TLS certificate
6//! equivalent for AI agents.
7
8use serde::{Deserialize, Serialize};
9
10/// Agent identity: who the agent is.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct AgentIdentity {
13    pub agent_name: String,
14    pub ship_id: String,
15    pub public_key: String,
16    pub issuer: String,
17    pub issued_at: String,
18    pub valid_until: String,
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub model: Option<String>,
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub description: Option<String>,
23}
24
25/// Agent capabilities: what tools and services the agent is authorized to use.
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct AgentCapabilities {
28    /// Authorized MCP tool names.
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub tools: Vec<ToolCapability>,
31    /// Authorized API endpoints.
32    #[serde(default, skip_serializing_if = "Vec::is_empty")]
33    pub api_endpoints: Vec<String>,
34    /// Authorized MCP server names.
35    #[serde(default, skip_serializing_if = "Vec::is_empty")]
36    pub mcp_servers: Vec<String>,
37}
38
39/// A single authorized tool with optional description.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ToolCapability {
42    pub name: String,
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub description: Option<String>,
45}
46
47/// Agent declaration: scope constraints.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct AgentDeclaration {
50    #[serde(default, skip_serializing_if = "Vec::is_empty")]
51    pub bounded_actions: Vec<String>,
52    #[serde(default, skip_serializing_if = "Vec::is_empty")]
53    pub forbidden: Vec<String>,
54    #[serde(default, skip_serializing_if = "Vec::is_empty")]
55    pub escalation_required: Vec<String>,
56}
57
58/// The complete Agent Certificate -- identity + capabilities + declaration
59/// with a signature over the canonical JSON of all three.
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct AgentCertificate {
62    pub r#type: String, // "treeship/agent-certificate/v1"
63    pub identity: AgentIdentity,
64    pub capabilities: AgentCapabilities,
65    pub declaration: AgentDeclaration,
66    pub signature: CertificateSignature,
67}
68
69/// Signature over the certificate content.
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct CertificateSignature {
72    pub algorithm: String,     // "ed25519"
73    pub key_id: String,
74    pub public_key: String,    // base64url-encoded Ed25519 public key
75    pub signature: String,     // base64url-encoded Ed25519 signature
76    pub signed_fields: String, // "identity+capabilities+declaration"
77}
78
79pub const CERTIFICATE_TYPE: &str = "treeship/agent-certificate/v1";