Skip to main content

Runtime

Trait Runtime 

Source
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§

Source

async fn create_agent(&self, config: AgentConfig) -> Result<AgentId, Error>

Create an agent from the given config, returning its ID.

Source

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.

Source

async fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>

Gracefully shut down the agent.

Source

async fn cancel(&self, agent_id: AgentId) -> Result<(), Error>

Interrupt any active prompt/chat run.

Source

async fn wait_for_idle(&self, agent_id: AgentId) -> Result<(), Error>

Wait for the active run or conversational loop to stabilize.

Source

async fn send(&self, agent_id: AgentId, content: &Content) -> Result<(), Error>

Send a message without waiting for completion.

Source

async fn signal_idle(&self, agent_id: AgentId) -> Result<(), Error>

Signal that the agent is idle.

Source

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.

Source

async fn wait_for_quota(&self)

Wait if we’re in a quota backoff period.

Source

async fn record_quota_hit(&self, retry_after: Duration)

Record a quota hit with the suggested retry duration.

Source

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.

Source

async fn history( &self, agent_id: AgentId, ) -> Result<Vec<ConversationMessage>, Error>

Retrieve the conversation’s message history.

Source

async fn turn_count(&self, agent_id: AgentId) -> Result<u32, Error>

Return the number of completed turns in the conversation.

Source

async fn total_usage(&self, agent_id: AgentId) -> Result<UsageMetadata, Error>

Return cumulative token usage across all turns.

Source

async fn last_turn_usage( &self, agent_id: AgentId, ) -> Result<UsageMetadata, Error>

Return token usage from the most recent turn only.

Source

async fn clear_history(&self, agent_id: AgentId) -> Result<(), Error>

Clear the conversation history and reset state.

Provided Methods§

Source

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).

Source

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.

Source

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(()).

Source

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(()).

Source

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).

Source

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".

Implementors§