Skip to main content

PythonRuntime

Struct PythonRuntime 

Source
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

Source

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.

Source

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.

Source

pub const fn quota_state(&self) -> &Arc<QuotaState>

Access the shared quota state.

Trait Implementations§

Source§

impl Debug for PythonRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PythonRuntime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Runtime for PythonRuntime

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. Read more
Source§

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

Gracefully shut down the agent.
Source§

fn try_shutdown_agent(&self, agent_id: AgentId)

Best-effort synchronous shutdown signal, called from Drop. Read more
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. Read more
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.
Source§

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>

Return the text of the last model response, if any. Read more
Source§

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

Delete the conversation and all associated state. Read more
Source§

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

Disconnect from the agent without deleting state. Read more
Source§

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

Check whether the agent is currently idle (not running a turn). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more