pub struct AgentRuntime { /* private fields */ }Implementations§
Source§impl AgentRuntime
impl AgentRuntime
pub async fn create_session(&self) -> SessionId
pub async fn restore_session( &self, session_id: &SessionId, ) -> Option<AgentSession>
pub async fn session(&self, session_id: &SessionId) -> Option<AgentSession>
pub async fn session_or_err( &self, session_id: &SessionId, ) -> AgentResult<AgentSession>
pub async fn with_session_mut<F, R>(
&self,
session_id: &SessionId,
f: F,
) -> AgentResult<R>where
F: FnOnce(&mut AgentSession) -> R,
pub fn emit_event(&self, event: RuntimeEvent)
Sourcepub fn subscribe_runtime_events(&self) -> Receiver<RuntimeEvent>
pub fn subscribe_runtime_events(&self) -> Receiver<RuntimeEvent>
Subscribe to runtime events from the internal broadcast channel.
Events are delivered directly from the runtime’s event bus (capacity 2048).
Slow consumers may receive Lagged(n) errors if they cannot keep up —
ensure the receiver loop processes events promptly or use a buffering
layer in the consumer if backpressure is a concern.
pub fn session_manager(&self) -> &SessionManager
pub fn llm_engine(&self) -> &LlmEngine
pub fn provider(&self) -> Arc<dyn LlmProvider> ⓘ
Sourcepub fn set_client(&mut self, provider: Arc<dyn LlmProvider>)
pub fn set_client(&mut self, provider: Arc<dyn LlmProvider>)
Replace the LLM provider at runtime (e.g., model switch).
Requires &mut self — obtain via runtime.lock().await.
pub fn tools_mut(&self) -> Arc<RwLock<ToolRegistry>> ⓘ
pub fn config(&self) -> RwLockReadGuard<'_, AgentConfig>
Sourcepub async fn set_reasoning_effort(&self, effort: ReasoningEffort)
pub async fn set_reasoning_effort(&self, effort: ReasoningEffort)
设置 reasoning effort(异步版本)
Sourcepub fn set_reasoning_effort_sync(&self, effort: ReasoningEffort)
pub fn set_reasoning_effort_sync(&self, effort: ReasoningEffort)
设置 reasoning effort(同步版本,只在同步上下文中使用)
pub fn approval_handler(&self) -> Option<&Arc<dyn ApprovalHandler>>
pub fn tool_policy(&self) -> Option<&Arc<dyn ToolPolicy>>
pub async fn cached_approval( &self, session_id: &SessionId, action_key: &str, ) -> bool
pub async fn cache_approval(&self, session_id: &SessionId, action_key: String)
pub async fn save_checkpoint( &self, session_id: &SessionId, checkpoint: CheckpointData, ) -> AgentResult<()>
pub async fn load_checkpoint( &self, _session_id: &SessionId, _checkpoint: &CheckpointData, ) -> AgentResult<Option<CheckpointData>>
pub async fn run<F>( &self, session_id: SessionId, on_event: F, ) -> AgentResult<RunOutcome>
pub async fn run_turn<F>( &self, session_id: SessionId, user_input: &str, on_event: F, ) -> AgentResult<RunOutcome>
pub async fn run_turn_collect( &self, session_id: SessionId, user_input: &str, ) -> AgentResult<(Vec<RuntimeEvent>, RunOutcome)>
pub async fn add_user_message( &self, session_id: &SessionId, text: impl Into<String>, ) -> AgentResult<()>
pub async fn add_system_message( &self, session_id: &SessionId, text: impl Into<String>, ) -> AgentResult<()>
pub async fn add_tool_result( &self, session_id: &SessionId, tool_call_id: &str, summary: impl Into<String>, ) -> AgentResult<()>
pub async fn get_messages( &self, session_id: &SessionId, ) -> AgentResult<Vec<ChatMessage>>
Sourcepub async fn set_messages(
&self,
session_id: &SessionId,
messages: Vec<ChatMessage>,
) -> AgentResult<()>
pub async fn set_messages( &self, session_id: &SessionId, messages: Vec<ChatMessage>, ) -> AgentResult<()>
Replace the chat messages for a session — only for persistence restore. Validates message sequence before applying.
仅供持久化恢复使用。
pub async fn validate_session(&self, session_id: &SessionId) -> AgentResult<()>
pub fn session_store(&self) -> Arc<dyn SessionStore> ⓘ
Sourcepub fn on_turn_end<F>(&self, f: F)
pub fn on_turn_end<F>(&self, f: F)
Register a turn-end callback. The callback receives a TurnContext
with raw data about the completed turn iteration. Consumers (e.g.
phi-telemetry) use this to build their own metrics without agent-base
knowing anything about metrics.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel the currently executing run_turn / run. No-op if there is no current execution.
Sourcepub fn reset_cancel(&self)
pub fn reset_cancel(&self)
Reset the cancel token (called automatically before each run_turn)
Sourcepub fn cancel_token(&self) -> CancellationToken
pub fn cancel_token(&self) -> CancellationToken
Get a clone of the cancel token
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if cancellation has been requested
Sourcepub fn steer(&self, message: String)
pub fn steer(&self, message: String)
Push a steering message — will be processed at the start of the next turn
in the current run_managed() loop.
Sourcepub fn follow_up(&self, message: String)
pub fn follow_up(&self, message: String)
Push a follow-up message — will be processed after the inner turn loop stops naturally (no tool calls or max turns).
Sourcepub async fn run_managed<F>(
&self,
session_id: SessionId,
user_input: &str,
on_event: F,
) -> AgentResult<RunOutcome>
pub async fn run_managed<F>( &self, session_id: SessionId, user_input: &str, on_event: F, ) -> AgentResult<RunOutcome>
Run the agent in managed mode with message queue support.
This wraps run_turn() (or run()) in an outer loop: after the inner
turn loop completes, any follow-up messages are drained and a new inner
loop is started. Steering messages are drained automatically at each
iteration of the inner turn loop.
The on_event callback receives all events from every inner run.
Sourcepub fn set_queue_mode(&self, mode: QueueMode)
pub fn set_queue_mode(&self, mode: QueueMode)
Set the drain mode for the message queues.
Trait Implementations§
Source§impl Clone for AgentRuntime
impl Clone for AgentRuntime
Source§fn clone(&self) -> AgentRuntime
fn clone(&self) -> AgentRuntime
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more