pub struct RpcEngine { /* private fields */ }Expand description
The out-of-process RPC driver: wraps one already-constructed
crate::Agent with the submit/interrupt/status/shutdown
method set (§ module doc). Shared by both transports (run_stdio,
run_http) so the method semantics — including the fail-closed
permission behavior — can never drift between them.
Implementations§
Source§impl RpcEngine
impl RpcEngine
Sourcepub fn new(
agent: impl Into<SdkAgent>,
on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>,
) -> Arc<RpcEngine> ⓘ
pub fn new( agent: impl Into<SdkAgent>, on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>, ) -> Arc<RpcEngine> ⓘ
Wrap agent (already fully built by the caller — same Config,
same permission/sandbox posture as a local session) for out-of-
process driving. Installs its OWN event sink via
Agent::set_event_sink, overwriting whatever sink agent may
already have had wired (callers of this module drive an agent
exclusively through the RPC surface, so there is never a second,
competing consumer of its events).
Sourcepub fn new_named(
agent: impl Into<SdkAgent>,
session_id: impl Into<String>,
on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>,
) -> Arc<RpcEngine> ⓘ
pub fn new_named( agent: impl Into<SdkAgent>, session_id: impl Into<String>, on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>, ) -> Arc<RpcEngine> ⓘ
Construct the canonical SDK runtime with an explicit durable session identity. Every frontend must use this identity when referring to the same live agent; transport-local connection ids are not session ids.
Sourcepub fn new_named_with_frontend_metadata(
agent: impl Into<SdkAgent>,
session_id: impl Into<String>,
frontend_metadata: FrontendRuntimeMetadata,
on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>,
) -> Arc<RpcEngine> ⓘ
pub fn new_named_with_frontend_metadata( agent: impl Into<SdkAgent>, session_id: impl Into<String>, frontend_metadata: FrontendRuntimeMetadata, on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>, ) -> Arc<RpcEngine> ⓘ
Construct the canonical runtime with explicit source-harness and emulation-profile identity for every attached frontend.
Sourcepub fn new_named_with_frontend_requests(
agent: impl Into<SdkAgent>,
session_id: impl Into<String>,
frontend_metadata: FrontendRuntimeMetadata,
on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>,
) -> Arc<RpcEngine> ⓘ
pub fn new_named_with_frontend_requests( agent: impl Into<SdkAgent>, session_id: impl Into<String>, frontend_metadata: FrontendRuntimeMetadata, on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>, ) -> Arc<RpcEngine> ⓘ
Construct a canonical runtime whose attached frontends may answer
policy-authorized approval requests. Existing constructors retain the
historical fail-closed headless behavior and report respond=false.
Sourcepub fn new_named_with_frontend_bridge(
agent: impl Into<SdkAgent>,
session_id: impl Into<String>,
frontend_metadata: FrontendRuntimeMetadata,
bridge: FrontendRequestBridge,
on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>,
) -> Arc<RpcEngine> ⓘ
pub fn new_named_with_frontend_bridge( agent: impl Into<SdkAgent>, session_id: impl Into<String>, frontend_metadata: FrontendRuntimeMetadata, bridge: FrontendRequestBridge, on_turn_complete: Option<Box<dyn Fn(&SdkAgent) + Sync + Send>>, ) -> Arc<RpcEngine> ⓘ
Bind a pre-created request bridge after its elicitation handler has been installed on MCP clients.
Sourcepub fn subscribe(&self) -> Receiver<Value>
pub fn subscribe(&self) -> Receiver<Value>
Subscribe to this engine’s event-notification stream (already
AgentEvent::to_json-projected) — each subscriber gets every event
emitted from this point on, independent of any other subscriber.
Sourcepub fn frontend_descriptor(&self) -> FrontendRuntimeDescriptor
pub fn frontend_descriptor(&self) -> FrontendRuntimeDescriptor
Describe the SDK-owned runtime without locking the active agent turn.
Sourcepub fn frontend_attach(
&self,
history_limit: usize,
) -> Result<FrontendAttachment, SdkError>
pub fn frontend_attach( &self, history_limit: usize, ) -> Result<FrontendAttachment, SdkError>
Attach to one atomic history/replay/live boundary. The live receiver
is created before the projection snapshot is locked; events racing the
snapshot therefore appear either in replay or in the receiver, and
FrontendAttachment::next_event removes any overlap by sequence.
Sourcepub fn frontend_subscribe(&self) -> Receiver<SdkEvent>
pub fn frontend_subscribe(&self) -> Receiver<SdkEvent>
Subscribe to sequenced frontend events. Transport adapters subscribe
before taking Self::frontend_snapshot so boundary events cannot be
missed.
Sourcepub fn frontend_snapshot(
&self,
history_limit: usize,
) -> Result<FrontendAttachSnapshot, SdkError>
pub fn frontend_snapshot( &self, history_limit: usize, ) -> Result<FrontendAttachSnapshot, SdkError>
Capture the serializable history/replay half of a frontend attachment.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Stable SDK session identity shared by every frontend.
Sourcepub async fn submit(
&self,
prompt: impl Into<String>,
) -> Result<String, RuntimeSubmitError>
pub async fn submit( &self, prompt: impl Into<String>, ) -> Result<String, RuntimeSubmitError>
Submit one prompt through the canonical runtime and wait for its reply.
Sourcepub async fn submit_with_images(
&self,
prompt: impl Into<String>,
image_urls: Vec<String>,
) -> Result<String, RuntimeSubmitError>
pub async fn submit_with_images( &self, prompt: impl Into<String>, image_urls: Vec<String>, ) -> Result<String, RuntimeSubmitError>
Submit one prompt with runtime-owned multimodal image inputs.
Sourcepub fn send_input(
self: &Arc<RpcEngine>,
prompt: String,
) -> Result<(), RuntimeSubmitError>
pub fn send_input( self: &Arc<RpcEngine>, prompt: String, ) -> Result<(), RuntimeSubmitError>
Atomically claim one prompt, then run it on the SDK owner while the caller consumes the canonical event stream.
Sourcepub fn send_input_with_images(
self: &Arc<RpcEngine>,
prompt: String,
image_urls: Vec<String>,
) -> Result<(), RuntimeSubmitError>
pub fn send_input_with_images( self: &Arc<RpcEngine>, prompt: String, image_urls: Vec<String>, ) -> Result<(), RuntimeSubmitError>
Atomically claim one multimodal prompt, then run it while callers consume the canonical event stream.
Sourcepub fn steer(&self, prompt: impl Into<String>) -> Result<(), SdkError>
pub fn steer(&self, prompt: impl Into<String>) -> Result<(), SdkError>
Queue steering for the active agent loop without waiting for its long-held async lock. The agent consumes it at the next model-loop boundary according to the configured steering mode.
Sourcepub fn respond(&self, response: FrontendResponse) -> Result<(), SdkError>
pub fn respond(&self, response: FrontendResponse) -> Result<(), SdkError>
Resolve one pending interactive request exactly once.
Sourcepub async fn invoke(
&self,
operation: FrontendOperationInvocation,
) -> Result<FrontendOperationResult, SdkError>
pub async fn invoke( &self, operation: FrontendOperationInvocation, ) -> Result<FrontendOperationResult, SdkError>
Invoke one operation after resolving its opaque identifier solely against the trusted catalog captured at runtime construction.
Sourcepub async fn interrupt(&self) -> bool
pub async fn interrupt(&self) -> bool
Cancel the current turn through the shared runtime handle.
Sourcepub fn status(&self) -> RuntimeStatus
pub fn status(&self) -> RuntimeStatus
Return a lock-free runtime snapshot, including while a turn is active.
Sourcepub async fn history(&self, limit: usize) -> Vec<ChatMessage>
pub async fn history(&self, limit: usize) -> Vec<ChatMessage>
Return the tail of the canonical conversation for newly attached frontends. This is SDK state, not a transport-local replay buffer, and remains answerable while a turn owns the agent lock.
Sourcepub async fn finalize_with<R>(&self, finalize: impl FnOnce(&SdkAgent) -> R) -> R
pub async fn finalize_with<R>(&self, finalize: impl FnOnce(&SdkAgent) -> R) -> R
Run one caller-owned finalization projection while holding the agent
at a quiescent boundary. This is the persistence/inspection seam for
local frontends that transfer Agent ownership into the SDK runtime;
it does not expose a second way to drive the model loop.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Request graceful runtime shutdown. All connected frontends observe the same transition and any in-flight turn is interrupted.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Whether shutdown has been requested — callers use this to stop
accepting new work/connections.
Sourcepub async fn wait_for_shutdown(&self)
pub async fn wait_for_shutdown(&self)
Resolves once shutdown has been requested. Cheap to call
repeatedly/concurrently — every waiter is woken.
Sourcepub async fn handle_request(self: &Arc<RpcEngine>, req: RpcRequest) -> Value
pub async fn handle_request(self: &Arc<RpcEngine>, req: RpcRequest) -> Value
Dispatch one already-parsed RpcRequest to the right method
handler. Every recognized method is fully wired to real Agent
behavior — there is no method that parses but no-ops.