Skip to main content

jamjet_agents/
registry.rs

1use crate::card::AgentCard;
2use crate::lifecycle::AgentStatus;
3use async_trait::async_trait;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8pub type AgentId = Uuid;
9
10/// A registered agent with its card, status, and metadata.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Agent {
13    pub id: AgentId,
14    pub card: AgentCard,
15    pub status: AgentStatus,
16    pub registered_at: DateTime<Utc>,
17    pub updated_at: DateTime<Utc>,
18    pub last_heartbeat: Option<DateTime<Utc>>,
19}
20
21/// Filter for agent discovery queries.
22#[derive(Debug, Default)]
23pub struct AgentFilter {
24    pub skill: Option<String>,
25    pub protocol: Option<String>,
26    pub status: Option<AgentStatus>,
27}
28
29#[async_trait]
30pub trait AgentRegistry: Send + Sync {
31    /// Register a new agent with the given Agent Card.
32    async fn register(&self, card: AgentCard) -> Result<AgentId, String>;
33
34    /// Get an agent by its internal id.
35    async fn get(&self, id: AgentId) -> Result<Option<Agent>, String>;
36
37    /// Get an agent by its URI (e.g. "jamjet://myorg/research-analyst").
38    async fn get_by_uri(&self, uri: &str) -> Result<Option<Agent>, String>;
39
40    /// Find agents matching a filter (by skill, protocol, status).
41    async fn find(&self, filter: AgentFilter) -> Result<Vec<Agent>, String>;
42
43    /// Update an agent's status.
44    async fn update_status(&self, id: AgentId, status: AgentStatus) -> Result<(), String>;
45
46    /// Record a heartbeat for an active agent.
47    async fn heartbeat(&self, id: AgentId) -> Result<(), String>;
48
49    /// Discover a remote A2A agent by fetching its Agent Card from a URL.
50    /// Stores the agent in the registry as an external agent.
51    async fn discover_remote(&self, url: &str) -> Result<Agent, String>;
52}