Implementation:1ay1 Agentty AgentServer
| Knowledge Sources | |
|---|---|
| Domains | Protocols, IDE_Integration |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Concrete ACP agent server over stdio JSON-RPC that exposes agentty's agent capabilities to an editor (like Zed) with session lifecycle, live configuration, streaming turn notifications, and session resume.
Description
The AgentServer class (in `acp/server.hpp`) implements the server side of the Agent Client Protocol (ACP). It reads JSON-RPC from stdin, dispatches method calls to handlers, and writes notifications + replies to stdout.
The server manages multiple sessions, each with its own workspace, model, profile, and turn queue. Turns are serialized per session: a prompt is registered, `acquire_turn` blocks until it's first in line, and `release_turn` hands the session to the next prompt.
Key handlers:
- on_initialize — protocol version negotiation (min of ours + theirs), capability flags.
- on_new_session — create a session with workspace, emit config options (slash menu, model picker).
- on_prompt — run a turn: stream `session/update` notifications (messages, tools, thoughts), deferred reply when the turn settles.
- on_set_config_option — validate + apply a config change (model, effort, mode), echo state.
- on_resume_session / on_load_session — rehydrate a session from ThreadLog, replay history.
- send_update — emit session/update notifications, gated on client capability flags.
Usage
- Editor integration: construct an AgentServer with a stdio channel, provider stream function, auth, model, and profile; call `serve(cap)` to start the JSON-RPC loop.
- Live config: the editor sends `session/set_config_option`; the server validates, applies, and echoes the new state.
- Session resume: the editor sends `session/resume_session`; the server rehydrates from ThreadLog and replays history.
Code Reference
Source Location
- Repository: agentty
- File: include/agentty/acp/server.hpp
- External Dependency: acp-cpp submodule (protocol types, JSON-RPC framing)
Signature
namespace agentty::acp {
class AgentServer {
public:
struct Extras {
StreamToFn stream_to; // cross-provider routing
std::function<auth::AuthHeader()> reauth; // re-read after login
};
AgentServer(rpc::Channel channel, // stdio JSON-RPC transport
StreamFn stream, // provider entrypoint
auth::AuthHeader auth, // resolved credential
std::string model_id, // default model
Profile profile = Profile::Ask,
Extras extras = {});
~AgentServer();
// Start reading; block until client disconnects (EOF on stdin).
// Returns process exit code. Waits for reader: unlocked.
int serve(const maya::unlocked& cap);
private:
// Method handlers (run on rpc reader thread):
::acp::InitializeResult on_initialize(const Cap&, const ::acp::InitializeParams&);
::acp::NewSessionResult on_new_session(const Cap&, const ::acp::NewSessionParams&);
::acp::LoadSessionResult on_load_session(const Cap&, const ::acp::LoadSessionParams&);
::acp::ResumeSessionResult on_resume_session(const Cap&, const ::acp::ResumeSessionParams&);
::acp::SetConfigOptionResult on_set_config_option(const Cap&, const ::acp::SetConfigOptionParams&);
void on_prompt(const Cap&, const ::acp::PromptParams&, Responder);
// Headless turn loop:
void run_turn(Io, const Cap&, std::string session_id, std::string req_id,
Responder, Message user_msg, std::string typed);
// Stream session/update notifications to the editor client.
void send_update(const maya::below<maya::leaf>& cap,
const std::string& session_id,
::acp::SessionUpdate update);
// Emit config options (slash menu, model picker).
void emit_session_config(const Cap&, const std::string& session_id,
const std::string& model_id);
void emit_config_state(const Cap&, const std::string& session_id,
const std::string& fallback_model);
};
} // namespace agentty::acp
Import
#include "agentty/acp/server.hpp"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| channel | rpc::Channel | Yes | stdio JSON-RPC transport |
| stream | StreamFn | Yes | Provider entrypoint (dispatch_stream) |
| auth | auth::AuthHeader | Yes | Resolved credential |
| model_id | std::string | Yes | Default model id |
| profile | Profile | No | Default permission tier (default Ask) |
Outputs
| Name | Type | Description |
|---|---|---|
| return (serve) | int | Process exit code |
| session/update | notification | Messages, tool calls, thoughts, checkpoints |
| session/prompt reply | deferred | Sent when the turn settles |
Usage Examples
Starting the Server
#include "agentty/acp/server.hpp"
using namespace agentty::acp;
// Construct the server
auto server = maya::co_owned<AgentServer>::make(
/*channel=*/rpc::Channel::stdio(),
/*stream=*/dispatch_stream,
/*auth=*/credentials::resolve(provider),
/*model_id=*/default_model,
/*profile=*/Profile::Ask,
/*extras=*/{});
// Start the JSON-RPC loop (blocks until client disconnects)
int exit_code = server->serve(cap);
Protocol Flow
Editor (client) AgentServer
-------------- ------------
-> initialize(params) <- on_initialize -> result (protocol version)
-> session/new(cwd, roots) <- on_new_session -> result
<- session/update (config: slash menu, model picker)
-> session/prompt(text) <- (deferred reply)
<- session/update (InProgress, messages)
<- session/update (ToolCallUpdate)
<- session/update (Completed)
<- session/prompt result (settled)
-> session/set_config_option <- on_set_config_option -> result
<- session/update (config echo)
-> session/resume_session(id) <- on_resume_session -> result
<- session/update (replay history)