pub trait Runtime: Send + Sync {
Show 22 methods
// Required methods
async fn create_agent(&self, config: AgentConfig) -> Result<AgentId, Error>;
async fn chat(
&self,
agent_id: AgentId,
content: &Content,
) -> Result<ChatResponseHandle, Error>;
async fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>;
async fn cancel(&self, agent_id: AgentId) -> Result<(), Error>;
async fn wait_for_idle(&self, agent_id: AgentId) -> Result<(), Error>;
async fn send(
&self,
agent_id: AgentId,
content: &Content,
) -> Result<(), Error>;
async fn signal_idle(&self, agent_id: AgentId) -> Result<(), Error>;
async fn wait_for_wakeup(
&self,
agent_id: AgentId,
timeout: Duration,
) -> Result<bool, Error>;
async fn wait_for_quota(&self);
async fn record_quota_hit(&self, retry_after: Duration);
fn quota_registry(&self) -> &QuotaRegistry;
async fn history(
&self,
agent_id: AgentId,
) -> Result<Vec<ConversationMessage>, Error>;
async fn turn_count(&self, agent_id: AgentId) -> Result<u32, Error>;
async fn total_usage(
&self,
agent_id: AgentId,
) -> Result<UsageMetadata, Error>;
async fn last_turn_usage(
&self,
agent_id: AgentId,
) -> Result<UsageMetadata, Error>;
async fn clear_history(&self, agent_id: AgentId) -> Result<(), Error>;
// Provided methods
async fn last_response(
&self,
_agent_id: AgentId,
) -> Result<Option<String>, Error> { ... }
async fn compaction_indices(
&self,
_agent_id: AgentId,
) -> Result<Vec<u32>, Error> { ... }
async fn delete(&self, _agent_id: AgentId) -> Result<(), Error> { ... }
async fn disconnect(&self, _agent_id: AgentId) -> Result<(), Error> { ... }
async fn is_idle(&self, _agent_id: AgentId) -> Result<bool, Error> { ... }
fn try_shutdown_agent(&self, _agent_id: AgentId) { ... }
}Expand description
Trait abstracting the Python runtime interface.
This allows unit tests to inject a mock runtime without requiring a live
Python interpreter. The real implementation will call through to PyO3.
Required Methods§
Sourceasync fn create_agent(&self, config: AgentConfig) -> Result<AgentId, Error>
async fn create_agent(&self, config: AgentConfig) -> Result<AgentId, Error>
Create an agent from the given config, returning its ID.
Sourceasync fn chat(
&self,
agent_id: AgentId,
content: &Content,
) -> Result<ChatResponseHandle, Error>
async fn chat( &self, agent_id: AgentId, content: &Content, ) -> Result<ChatResponseHandle, Error>
Send a chat message to the agent, returning a streaming response handle.
The content parameter accepts any Content variant: plain text,
images, documents, audio, video, or a multi-part list.
Sourceasync fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>
async fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>
Gracefully shut down the agent.
Sourceasync fn cancel(&self, agent_id: AgentId) -> Result<(), Error>
async fn cancel(&self, agent_id: AgentId) -> Result<(), Error>
Interrupt any active prompt/chat run.
Sourceasync fn wait_for_idle(&self, agent_id: AgentId) -> Result<(), Error>
async fn wait_for_idle(&self, agent_id: AgentId) -> Result<(), Error>
Wait for the active run or conversational loop to stabilize.
Sourceasync fn send(&self, agent_id: AgentId, content: &Content) -> Result<(), Error>
async fn send(&self, agent_id: AgentId, content: &Content) -> Result<(), Error>
Send a message without waiting for completion.
Sourceasync fn signal_idle(&self, agent_id: AgentId) -> Result<(), Error>
async fn signal_idle(&self, agent_id: AgentId) -> Result<(), Error>
Signal that the agent is idle.
Sourceasync fn wait_for_wakeup(
&self,
agent_id: AgentId,
timeout: Duration,
) -> Result<bool, Error>
async fn wait_for_wakeup( &self, agent_id: AgentId, timeout: Duration, ) -> Result<bool, Error>
Wait for the agent to wake up. Returns true if woken, false if timed out.
Sourceasync fn wait_for_quota(&self)
async fn wait_for_quota(&self)
Wait if we’re in a quota backoff period.
Sourceasync fn record_quota_hit(&self, retry_after: Duration)
async fn record_quota_hit(&self, retry_after: Duration)
Record a quota hit with the suggested retry duration.
Sourcefn quota_registry(&self) -> &QuotaRegistry
fn quota_registry(&self) -> &QuotaRegistry
Access this runtime’s per-key quota registry.
Each runtime owns its own QuotaRegistry,
so different runtimes have fully independent quota tracking.
Sourceasync fn history(
&self,
agent_id: AgentId,
) -> Result<Vec<ConversationMessage>, Error>
async fn history( &self, agent_id: AgentId, ) -> Result<Vec<ConversationMessage>, Error>
Retrieve the conversation’s message history.
Sourceasync fn turn_count(&self, agent_id: AgentId) -> Result<u32, Error>
async fn turn_count(&self, agent_id: AgentId) -> Result<u32, Error>
Return the number of completed turns in the conversation.
Sourceasync fn total_usage(&self, agent_id: AgentId) -> Result<UsageMetadata, Error>
async fn total_usage(&self, agent_id: AgentId) -> Result<UsageMetadata, Error>
Return cumulative token usage across all turns.
Sourceasync fn last_turn_usage(
&self,
agent_id: AgentId,
) -> Result<UsageMetadata, Error>
async fn last_turn_usage( &self, agent_id: AgentId, ) -> Result<UsageMetadata, Error>
Return token usage from the most recent turn only.
Provided Methods§
Sourceasync fn last_response(
&self,
_agent_id: AgentId,
) -> Result<Option<String>, Error>
async fn last_response( &self, _agent_id: AgentId, ) -> Result<Option<String>, Error>
Return the text of the last model response, if any.
Default implementation returns Ok(None).
Sourceasync fn compaction_indices(
&self,
_agent_id: AgentId,
) -> Result<Vec<u32>, Error>
async fn compaction_indices( &self, _agent_id: AgentId, ) -> Result<Vec<u32>, Error>
Return the step indices at which compaction occurred.
Default implementation returns an empty list.
Sourceasync fn delete(&self, _agent_id: AgentId) -> Result<(), Error>
async fn delete(&self, _agent_id: AgentId) -> Result<(), Error>
Delete the conversation and all associated state.
Default implementation is a no-op that returns Ok(()).
Sourceasync fn disconnect(&self, _agent_id: AgentId) -> Result<(), Error>
async fn disconnect(&self, _agent_id: AgentId) -> Result<(), Error>
Disconnect from the agent without deleting state.
Default implementation is a no-op that returns Ok(()).
Sourceasync fn is_idle(&self, _agent_id: AgentId) -> Result<bool, Error>
async fn is_idle(&self, _agent_id: AgentId) -> Result<bool, Error>
Check whether the agent is currently idle (not running a turn).
Default implementation returns Ok(true).
Sourcefn try_shutdown_agent(&self, _agent_id: AgentId)
fn try_shutdown_agent(&self, _agent_id: AgentId)
Best-effort synchronous shutdown signal, called from Drop.
Unlike shutdown_agent, this is sync and
fire-and-forget — it cannot return errors. The default is a no-op;
implementations backed by a command channel should try_send a
shutdown command here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".