agent_client_protocol_schema/acp.rs
1//! [](https://agentclientprotocol.com/)
2//!
3//! # Agent Client Protocol (ACP)
4//!
5//! The Agent Client Protocol standardizes communication between code editors
6//! (IDEs, text-editors, etc.) and coding agents (programs that use generative AI
7//! to autonomously modify code).
8//!
9//! ## Protocol & Transport
10//!
11//! ACP is a JSON-RPC based protocol. While clients typically start agents as
12//! subprocesses and communicate over stdio (stdin/stdout), this crate is
13//! transport-agnostic.
14//!
15//! You can use any bidirectional stream that implements `AsyncRead` and `AsyncWrite`.
16//!
17//! ## Core Components
18//!
19//! - **Agent**: Programs that use generative AI to autonomously modify code
20//! - See: [Agent](https://agentclientprotocol.com/protocol/overview#agent)
21//! - **Client**: Code editors that provide the interface between users and agents
22//! - See: [Client](https://agentclientprotocol.com/protocol/overview#client)
23//!
24//! ## Getting Started
25//!
26//! To understand the protocol, start by exploring the [`Agent`] and [`Client`] traits,
27//! which define the core methods and capabilities of each side of the connection.
28//!
29//! To see working examples of these traits in action, check out the
30//! [agent](https://github.com/agentclientprotocol/rust-sdk/blob/main/examples/agent.rs)
31//! and
32//! [client](https://github.com/agentclientprotocol/rust-sdk/blob/main/examples/client.rs)
33//! example binaries included with this crate.
34//!
35//! ### Implementation Pattern
36//!
37//! ACP uses a symmetric design where each participant implements one trait and
38//! creates a connection that provides the complementary trait:
39//!
40//! - **Agent builders** implement the [`Agent`] trait to handle client requests
41//! (like initialization, authentication, and prompts). They pass this implementation
42//! to [`AgentSideConnection::new`], which returns a connection providing [`Client`]
43//! methods for requesting permissions and accessing the file system.
44//!
45//! - **Client builders** implement the [`Client`] trait to handle agent requests
46//! (like file system operations and permission checks). They pass this implementation
47//! to [`ClientSideConnection::new`], which returns a connection providing [`Agent`]
48//! methods for managing sessions and sending prompts.
49//!
50//! For the complete protocol specification and documentation, visit:
51//! [https://agentclientprotocol.com](https://agentclientprotocol.com)
52
53mod agent;
54mod client;
55mod content;
56mod error;
57mod ext;
58mod plan;
59mod tool_call;
60mod version;
61
62pub use agent::*;
63pub use client::*;
64pub use content::*;
65use derive_more::{Display, From};
66pub use error::*;
67pub use ext::*;
68pub use plan::*;
69pub use serde_json::value::RawValue;
70pub use tool_call::*;
71pub use version::*;
72
73use schemars::JsonSchema;
74use serde::{Deserialize, Serialize};
75use std::sync::Arc;
76
77/// A unique identifier for a conversation session between a client and agent.
78///
79/// Sessions maintain their own context, conversation history, and state,
80/// allowing multiple independent interactions with the same agent.
81///
82/// # Example
83///
84/// ```
85/// use agent_client_protocol::SessionId;
86/// use std::sync::Arc;
87///
88/// let session_id = SessionId(Arc::from("sess_abc123def456"));
89/// ```
90///
91/// See protocol docs: [Session ID](https://agentclientprotocol.com/protocol/session-setup#session-id)
92#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Hash, Display, From)]
93#[serde(transparent)]
94#[from(Arc<str>, String, &'static str)]
95pub struct SessionId(pub Arc<str>);