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, ) -> Result<AgentSession, AgentError>
pub async fn with_session_mut<F, R>(
&self,
session_id: &SessionId,
f: F,
) -> Result<R, AgentError>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 client(&self) -> Arc<dyn LlmClient>
Sourcepub fn set_client(&mut self, client: Arc<dyn LlmClient>)
pub fn set_client(&mut self, client: Arc<dyn LlmClient>)
Replace the LLM client at runtime (e.g., model switch).
Requires &mut self — obtain via runtime.lock().await.
pub fn tools_mut(&self) -> Arc<RwLock<ToolRegistry>>
Sourcepub fn inject_framework_deps(&self, tools: &ToolRegistry)
pub fn inject_framework_deps(&self, tools: &ToolRegistry)
Inject the internal EventBus into framework tools in the given registry.
Call this after replacing tools in the registry (e.g., in build_tools).
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 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, ) -> Result<(), AgentError>
pub async fn load_checkpoint( &self, _session_id: &SessionId, _checkpoint: &CheckpointData, ) -> Result<Option<CheckpointData>, AgentError>
pub async fn run<F>( &self, session_id: SessionId, on_event: F, ) -> Result<RunOutcome, AgentError>
pub async fn run_turn<F>( &self, session_id: SessionId, user_input: &str, on_event: F, ) -> Result<RunOutcome, AgentError>
pub async fn run_turn_collect( &self, session_id: SessionId, user_input: &str, ) -> Result<(Vec<RuntimeEvent>, RunOutcome), AgentError>
pub async fn add_user_message( &self, session_id: &SessionId, text: impl Into<String>, ) -> Result<(), AgentError>
pub async fn add_system_message( &self, session_id: &SessionId, text: impl Into<String>, ) -> Result<(), AgentError>
pub async fn add_tool_result( &self, session_id: &SessionId, tool_call_id: &str, summary: impl Into<String>, ) -> Result<(), AgentError>
pub async fn get_messages( &self, session_id: &SessionId, ) -> Result<Vec<ChatMessage>, AgentError>
Sourcepub async fn set_messages(
&self,
session_id: &SessionId,
messages: Vec<ChatMessage>,
) -> Result<(), AgentError>
pub async fn set_messages( &self, session_id: &SessionId, messages: Vec<ChatMessage>, ) -> Result<(), AgentError>
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, ) -> Result<(), AgentError>
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
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