pub struct PythonRuntime { /* private fields */ }Expand description
Manages a dedicated Python thread with an asyncio event loop.
All Python/SDK interactions go through the command channel. This isolates GIL acquisition to the Python thread and keeps the tokio runtime responsive.
Implementations§
Source§impl PythonRuntime
impl PythonRuntime
Sourcepub fn new(config: RuntimeConfig) -> Result<Self, Error>
pub fn new(config: RuntimeConfig) -> Result<Self, Error>
Spawn a new Python runtime on a dedicated thread.
Creates an asyncio event loop in the thread and starts the command dispatch loop.
§Errors
Returns Error::BackendError if the thread fails to spawn or
Python initialization fails.
Sourcepub async fn shutdown(self) -> Result<(), Error>
pub async fn shutdown(self) -> Result<(), Error>
Graceful shutdown: send Shutdown command, then join the thread.
§Errors
Returns Error::Timeout if the thread doesn’t join within the
configured shutdown timeout, or Error::BackendError if the
thread panicked.
Sourcepub const fn quota_state(&self) -> &Arc<QuotaState> ⓘ
pub const fn quota_state(&self) -> &Arc<QuotaState> ⓘ
Access the shared quota state.
Trait Implementations§
Source§impl Debug for PythonRuntime
impl Debug for PythonRuntime
Source§impl Drop for PythonRuntime
impl Drop for PythonRuntime
Source§impl Runtime for PythonRuntime
impl Runtime for PythonRuntime
Source§async 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.
Source§async 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. Read more
Source§async fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>
async fn shutdown_agent(&self, agent_id: AgentId) -> Result<(), Error>
Gracefully shut down the agent.
Source§fn try_shutdown_agent(&self, agent_id: AgentId)
fn try_shutdown_agent(&self, agent_id: AgentId)
Source§async fn cancel(&self, agent_id: AgentId) -> Result<(), Error>
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>
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>
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>
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>
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)
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)
async fn record_quota_hit(&self, retry_after: Duration)
Record a quota hit with the suggested retry duration.
Source§fn quota_registry(&self) -> &QuotaRegistry
fn quota_registry(&self) -> &QuotaRegistry
Access this runtime’s per-key quota registry. Read more
Source§async 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.
Source§async 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.
Source§async 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.
Source§async 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.
Source§async fn clear_history(&self, agent_id: AgentId) -> Result<(), Error>
async fn clear_history(&self, agent_id: AgentId) -> Result<(), Error>
Clear the conversation history and reset state.
Source§async 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. Read more
Source§async 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. Read more
Source§async fn delete(&self, agent_id: AgentId) -> Result<(), Error>
async fn delete(&self, agent_id: AgentId) -> Result<(), Error>
Delete the conversation and all associated state. Read more
Auto Trait Implementations§
impl !Freeze for PythonRuntime
impl !RefUnwindSafe for PythonRuntime
impl !UnwindSafe for PythonRuntime
impl Send for PythonRuntime
impl Sync for PythonRuntime
impl Unpin for PythonRuntime
impl UnsafeUnpin for PythonRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more