forked from agentclientprotocol/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_agent.rs
More file actions
32 lines (31 loc) · 1.32 KB
/
simple_agent.rs
File metadata and controls
32 lines (31 loc) · 1.32 KB
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
use agent_client_protocol::schema::{AgentCapabilities, InitializeRequest, InitializeResponse};
use agent_client_protocol::{Agent, Client, ConnectionTo, Dispatch, Result};
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
#[tokio::main]
async fn main() -> Result<()> {
Agent
.builder()
.name("my-agent") // for debugging
.on_receive_request(
async move |initialize: InitializeRequest, responder, _connection| {
// Respond to initialize successfully
responder.respond(
InitializeResponse::new(initialize.protocol_version)
.agent_capabilities(AgentCapabilities::new()),
)
},
agent_client_protocol::on_receive_request!(),
)
.on_receive_dispatch(
async move |message: Dispatch, cx: ConnectionTo<Client>| {
// Respond to any other message with an error
message.respond_with_error(agent_client_protocol::util::internal_error("unhandled message"), cx)
},
agent_client_protocol::on_receive_dispatch!(),
)
.connect_to(agent_client_protocol::ByteStreams::new(
tokio::io::stdout().compat_write(),
tokio::io::stdin().compat(),
))
.await
}