pub struct ProtocolServer { /* private fields */ }Expand description
Bridge protocol server — wraps an AgentRuntime and exposes it over
the NDJSON bridge protocol for external SDK consumption.
Manages sessions, tool registration via proxy tools, and event forwarding. Tool calls use a single-slot pattern: the serve loop pushes a receiver before each tool call, and ProxyTool pops it.
Implementations§
Source§impl ProtocolServer
impl ProtocolServer
Sourcepub fn new(runtime: AgentRuntime) -> Self
pub fn new(runtime: AgentRuntime) -> Self
Wrap an existing AgentRuntime in a protocol server.
Sourcepub fn from_builder(builder: AgentBuilder) -> Result<Self, AgentError>
pub fn from_builder(builder: AgentBuilder) -> Result<Self, AgentError>
Build a protocol server from an AgentBuilder.
Sourcepub async fn register_tool(
&self,
name: String,
description: String,
parameters: Value,
)
pub async fn register_tool( &self, name: String, description: String, parameters: Value, )
Register a tool implemented on the SDK side.
The tool’s call will block until the SDK sends a tool_result
message through the bridge.
Sourcepub async fn prepare_tool_call(
&self,
) -> UnboundedSender<AgentResult<Vec<Content>>>
pub async fn prepare_tool_call( &self, ) -> UnboundedSender<AgentResult<Vec<Content>>>
Set up the response channel for the NEXT tool call. Returns the sender — keep it; send the result when the SDK replies.
Sourcepub async fn create_session(
&self,
external_id: Option<String>,
) -> (SessionId, Option<String>)
pub async fn create_session( &self, external_id: Option<String>, ) -> (SessionId, Option<String>)
Create a new session, optionally with an external ID for reuse.
Sourcepub async fn get_or_create_session(
&self,
external_id: Option<String>,
) -> SessionId
pub async fn get_or_create_session( &self, external_id: Option<String>, ) -> SessionId
Get or create a session by external_id.
If external_id is Some and a session with that id already
exists, it is reused (preserving conversation history). Otherwise
a new session is created and registered.
Sourcepub fn subscribe_events(&self) -> Receiver<RuntimeEvent>
pub fn subscribe_events(&self) -> Receiver<RuntimeEvent>
Subscribe to runtime events broadcast by the agent.
Sourcepub async fn run_turn<F>(
&self,
sid: &SessionId,
input: &str,
f: F,
) -> AgentResult<RunOutcome>
pub async fn run_turn<F>( &self, sid: &SessionId, input: &str, f: F, ) -> AgentResult<RunOutcome>
Run a turn on the given session, forwarding events to the callback.
Sourcepub async fn list_tools(&self) -> Vec<ToolMetadata>
pub async fn list_tools(&self) -> Vec<ToolMetadata>
List all registered tools with their metadata, sorted by name.