pub struct AgentRuntime<P: LlmProvider> { /* private fields */ }Expand description
The main agent runtime.
Implementations§
Source§impl<P: LlmProvider + 'static> AgentRuntime<P>
impl<P: LlmProvider + 'static> AgentRuntime<P>
Sourcepub async fn run_turn_streaming<F: Frontend + 'static>(
&self,
session: &mut AgentSession,
input: &str,
frontend: Arc<F>,
) -> RuntimeResult<()>
pub async fn run_turn_streaming<F: Frontend + 'static>( &self, session: &mut AgentSession, input: &str, frontend: Arc<F>, ) -> RuntimeResult<()>
Run a single turn with streaming output.
The frontend parameter is wrapped in Arc so it can be registered as an
approval handler for the duration of the turn.
§Errors
Returns an error if:
- The LLM provider fails to generate a response
- An MCP tool call fails
- An approval request fails
- Session persistence fails
Sourcepub async fn run_subagent_turn<F: Frontend + 'static>(
&self,
session: &mut AgentSession,
prompt: &str,
frontend: Arc<F>,
parent_subagent_id: Option<SubAgentId>,
) -> RuntimeResult<()>
pub async fn run_subagent_turn<F: Frontend + 'static>( &self, session: &mut AgentSession, prompt: &str, frontend: Arc<F>, parent_subagent_id: Option<SubAgentId>, ) -> RuntimeResult<()>
Run a single turn for a sub-agent session.
Like run_turn_streaming but without hooks, summarization, or session persistence.
The session is ephemeral and owned by the caller (SubAgentExecutor).
parent_subagent_id is the pool handle ID of this sub-agent, passed so that
nested sub-agents (if the sub-agent calls task tool) can declare their parent.
§Errors
Returns an error if the LLM or tool execution fails.
Source§impl<P: LlmProvider + 'static> AgentRuntime<P>
impl<P: LlmProvider + 'static> AgentRuntime<P>
Sourcepub fn new(
llm: P,
mcp: McpClient,
audit: AuditLog,
sessions: SessionStore,
crypto: KeyPair,
config: RuntimeConfig,
) -> Self
pub fn new( llm: P, mcp: McpClient, audit: AuditLog, sessions: SessionStore, crypto: KeyPair, config: RuntimeConfig, ) -> Self
Create a new runtime.
Sourcepub fn with_capsule_registry(
self,
registry: Arc<RwLock<CapsuleRegistry>>,
) -> Self
pub fn with_capsule_registry( self, registry: Arc<RwLock<CapsuleRegistry>>, ) -> Self
Set the capsule registry for capsule tool integration.
Sourcepub fn new_arc(
llm: P,
mcp: McpClient,
audit: AuditLog,
sessions: SessionStore,
crypto: KeyPair,
config: RuntimeConfig,
hooks: Option<HookManager>,
capsule_registry: Option<Arc<RwLock<CapsuleRegistry>>>,
) -> Arc<Self>
pub fn new_arc( llm: P, mcp: McpClient, audit: AuditLog, sessions: SessionStore, crypto: KeyPair, config: RuntimeConfig, hooks: Option<HookManager>, capsule_registry: Option<Arc<RwLock<CapsuleRegistry>>>, ) -> Arc<Self>
Create a new runtime wrapped in Arc with the self-reference pre-set.
Uses Arc::new_cyclic to avoid the two-step new() + set_self_arc() pattern.
Accepts an optional HookManager since with_hooks() can’t be chained after
Arc wrapping. Accepts an optional PluginRegistry for capsule tool integration.
Sourcepub fn create_session(&self, workspace_override: Option<&Path>) -> AgentSession
pub fn create_session(&self, workspace_override: Option<&Path>) -> AgentSession
Create a new session.
Uses build_system_prompt() to dynamically assemble a workspace-aware
prompt with tool guidelines and project instructions. If the user has
explicitly set a custom system_prompt in config, that takes priority.
An optional workspace_override can be supplied to use a different
workspace root than the one in the runtime config (e.g. the CLI
client’s actual working directory).
Sourcepub fn save_session(&self, session: &AgentSession) -> RuntimeResult<()>
pub fn save_session(&self, session: &AgentSession) -> RuntimeResult<()>
Sourcepub fn load_session(
&self,
id: &SessionId,
) -> RuntimeResult<Option<AgentSession>>
pub fn load_session( &self, id: &SessionId, ) -> RuntimeResult<Option<AgentSession>>
Sourcepub fn list_sessions(&self) -> RuntimeResult<Vec<SessionSummary>>
pub fn list_sessions(&self) -> RuntimeResult<Vec<SessionSummary>>
List sessions.
§Errors
Returns an error if the session directory cannot be read or session files cannot be parsed.
Sourcepub fn config(&self) -> &RuntimeConfig
pub fn config(&self) -> &RuntimeConfig
Get runtime configuration.
Sourcepub fn boundary(&self) -> &WorkspaceBoundary
pub fn boundary(&self) -> &WorkspaceBoundary
Get the workspace boundary.
Sourcepub fn cleanup_capsule_kv_stores(&self, session_id: &SessionId)
pub fn cleanup_capsule_kv_stores(&self, session_id: &SessionId)
Remove plugin KV stores for a session that has ended.
Should be called when a session is finished to prevent unbounded growth
of the capsule_kv_stores map in long-running processes.
Sourcepub fn with_security_policy(self, policy: SecurityPolicy) -> Self
pub fn with_security_policy(self, policy: SecurityPolicy) -> Self
Set a custom security policy.
Sourcepub fn with_hooks(self, hooks: HookManager) -> Self
pub fn with_hooks(self, hooks: HookManager) -> Self
Set a pre-configured hook manager.
Sourcepub fn hooks(&self) -> &Arc<HookManager>
pub fn hooks(&self) -> &Arc<HookManager>
Get the hook manager.
Sourcepub fn subagent_pool(&self) -> &Arc<SubAgentPool>
pub fn subagent_pool(&self) -> &Arc<SubAgentPool>
Get the sub-agent pool.
Sourcepub async fn set_self_arc(self: &Arc<Self>)
pub async fn set_self_arc(self: &Arc<Self>)
Store a weak self-reference for sub-agent spawner injection.
Important: Callers must wrap the runtime in Arc and call this method
for sub-agent support to work. Without it, the task tool will return
“not available in this context”.
let runtime = Arc::new(AgentRuntime::new(/* ... */));
runtime.set_self_arc(&runtime).await;Auto Trait Implementations§
impl<P> !Freeze for AgentRuntime<P>
impl<P> !RefUnwindSafe for AgentRuntime<P>
impl<P> Send for AgentRuntime<P>
impl<P> Sync for AgentRuntime<P>
impl<P> Unpin for AgentRuntime<P>
impl<P> UnsafeUnpin for AgentRuntime<P>
impl<P> !UnwindSafe for AgentRuntime<P>
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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more