Skip to content

Commit 3bf40e5

Browse files
committed
docs(acp-nats-agent): add README
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 8df36ff commit 3bf40e5

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# acp-nats-agent
2+
3+
Server-side framework for building [ACP](https://agentclientprotocol.com/) agents over NATS.
4+
5+
## Architecture
6+
7+
```
8+
IDE <-> Bridge (acp-nats-stdio) <-> NATS <-> Agent (acp-nats-agent)
9+
```
10+
11+
## Usage
12+
13+
```rust
14+
use acp_nats::AcpPrefix;
15+
use acp_nats_agent::AgentSideNatsConnection;
16+
use agent_client_protocol::*;
17+
18+
struct MyAgent;
19+
20+
#[async_trait::async_trait(?Send)]
21+
impl Agent for MyAgent {
22+
async fn initialize(&self, args: InitializeRequest) -> Result<InitializeResponse> {
23+
Ok(InitializeResponse::new(ProtocolVersion::V0))
24+
}
25+
26+
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse> {
27+
Ok(NewSessionResponse::new("session-123"))
28+
}
29+
30+
async fn prompt(&self, args: PromptRequest) -> Result<PromptResponse> {
31+
Ok(PromptResponse::new(StopReason::EndTurn))
32+
}
33+
}
34+
35+
#[tokio::main]
36+
async fn main() {
37+
let nats = async_nats::connect("localhost:4222").await.unwrap();
38+
39+
let (connection, io_task) = AgentSideNatsConnection::new(
40+
MyAgent,
41+
nats,
42+
AcpPrefix::new("acp").unwrap(),
43+
|fut| { tokio::task::spawn_local(fut); },
44+
);
45+
46+
let local = tokio::task::LocalSet::new();
47+
local.run_until(io_task).await.unwrap();
48+
}
49+
```
50+
51+
## Client callbacks
52+
53+
Use `connection.client_for_session(session_id)` to send notifications, request permissions, read files, and run terminal commands back to the IDE.
54+
55+
```rust
56+
let client = connection.client_for_session(session_id);
57+
client.session_notification(notification).await?;
58+
client.request_permission(request).await?;
59+
client.read_text_file(request).await?;
60+
```

0 commit comments

Comments
 (0)