Skip to main content

RuntimeAgent

Struct RuntimeAgent 

Source
pub struct RuntimeAgent { /* private fields */ }

Implementations§

Source§

impl RuntimeAgent

Source

pub fn new( info: AgentInfo, llm_registry: Arc<LLMRegistry>, memory: Arc<dyn Memory>, tools: Arc<ToolRegistry>, skills: Vec<SkillDefinition>, system_prompt: String, max_iterations: u32, ) -> Self

Constructs a runtime with one gate shared by every external root-turn entry point.

Source

pub fn with_declared_tool_ids(self, ids: Option<Vec<String>>) -> Self

Source

pub fn with_storage_config(self, config: StorageConfig) -> Self

Source

pub fn with_storage(self, storage: Arc<dyn AgentStorage>) -> Self

Source

pub fn with_reasoning(self, config: ReasoningConfig) -> Self

Source

pub fn with_reflection(self, config: ReflectionConfig) -> Self

Source

pub fn with_relationships(self, manager: Arc<RelationshipManager>) -> Self

Attach a relationship manager configured by the builder or host application.

Source

pub fn with_observability(self, manager: Arc<ObservabilityManager>) -> Self

Attach a shared observability manager for traces, metrics, reports, and exports.

Source

pub fn with_runtime_config(self, config: RuntimeConfig) -> Self

Attach runtime optimization policy and resize the background queue.

Source

pub fn runtime_config(&self) -> &RuntimeConfig

Returns the runtime optimization policy.

Source

pub async fn flush_background_tasks(&self) -> Result<()>

Wait for all background maintenance tasks to finish.

Source

pub async fn flush_background_tasks_for_actor( &self, actor_id: &str, ) -> Result<()>

Wait for background maintenance associated with one actor to finish.

Source

pub async fn flush_background_tasks_for_purpose( &self, purpose: RuntimeTaskPurpose, ) -> Result<()>

Wait for background maintenance associated with one task kind to finish.

Source

pub async fn flush_background_tasks_for_actor_purpose( &self, actor_id: &str, purpose: RuntimeTaskPurpose, ) -> Result<()>

Wait for background maintenance associated with one actor and task kind to finish.

Source

pub async fn shutdown_background_tasks(&self) -> Result<()>

Flush background maintenance before a host shuts down the runtime.

Source

pub fn observability(&self) -> Option<Arc<ObservabilityManager>>

Returns the configured observability manager for report and export access.

Source

pub fn relationship_manager(&self) -> Option<Arc<RelationshipManager>>

Returns the configured relationship manager, if relationship memory is enabled.

Source

pub async fn chat_with_actor_context( &self, input: &str, actor_context: TurnActorContext, ) -> Result<AgentResponse>

Run one serialized turn with turn-scoped actor context without mutating the runtime’s global actor ID.

The supplied context is available to actor-scoped facts, relationship memory, orchestration, and prompt templates only for the lifetime of this call.

Source

pub async fn chat_as_actor( &self, actor_id: &str, input: &str, ) -> Result<AgentResponse>

Convenience wrapper around Self::chat_with_actor_context for a turn whose original actor is known up front.

Source

pub async fn load_actor_relationship(&self) -> Result<()>

Ensure the effective actor’s relationship is loaded from storage into the relationship manager.

Source

pub async fn update_relationship_dimension( &self, dimension: &str, delta: f64, reason: Option<&str>, ) -> Result<DimensionChange>

Manually apply a delta to the effective actor’s agent_to_actor relationship perspective and persist the updated relationship when storage is configured.

Source

pub async fn update_relationship_dimension_for_perspective( &self, perspective: RelationshipPerspective, dimension: &str, delta: f64, reason: Option<&str>, ) -> Result<DimensionChange>

Manually apply a delta to a specific relationship perspective for the effective actor.

Use this for two-sided configurations when you need to update agent_to_actor, perceived_actor_to_agent, or mutual explicitly from application logic.

Source

pub fn reasoning_config(&self) -> &ReasoningConfig

Source

pub fn reflection_config(&self) -> &ReflectionConfig

Source

pub fn with_facts_config( self, actor_memory_config: Option<ActorMemoryConfig>, facts_config: Option<FactsConfig>, ) -> Self

Set only the actor memory and facts configs without creating the store. The store and extractor are created lazily in init_storage().

Source

pub fn with_facts( self, store: Arc<FactStore>, extractor: Option<Arc<dyn FactExtractor>>, actor_memory_config: Option<ActorMemoryConfig>, facts_config: Option<FactsConfig>, ) -> Self

Configure fact store and optional extractor for actor memory. Pass None for extractor to load existing facts without running extraction.

Source

pub fn fact_store(&self) -> Option<Arc<FactStore>>

Get the fact store for direct fact manipulation.

Source

pub fn actor_id(&self) -> Option<String>

Get the current actor ID.

Source

pub fn set_actor_id(&self, actor_id: &str) -> Result<()>

Set the current actor ID (player, user, another agent, etc.).

Source

pub fn clear_actor_id(&self)

Clear the current actor binding while retaining the session actor roster.

Source

pub fn set_user_id(&self, user_id: &str) -> Result<()>

Set the current actor ID. Convenience wrapper around set_actor_id.

Source

pub async fn load_actor_memory(&self) -> Result<()>

Load facts for the current actor from storage and cache them for prompt injection.

Source

pub fn actor_facts(&self) -> Vec<KeyFact>

Get cached actor facts for the effective actor.

Source

pub fn relationship_memory_text(&self) -> Option<String>

Returns the formatted relationship prompt text for the effective actor, if relationship injection produced any text for this turn.

Source

pub async fn extract_facts(&self, last_n: usize) -> Result<Vec<KeyFact>>

Manually extract facts from the last N messages.

Source

pub fn with_persona(self, manager: Arc<PersonaManager>) -> Self

Source

pub fn persona_manager(&self) -> Option<&Arc<PersonaManager>>

Source

pub fn with_disambiguation(self, config: DisambiguationConfig) -> Self

Source

pub fn disambiguation_manager(&self) -> Option<&DisambiguationManager>

Source

pub fn has_disambiguation(&self) -> bool

Source

pub async fn init_storage(&self) -> Result<()>

Source

pub fn storage(&self) -> Option<Arc<dyn AgentStorage>>

Source

pub fn storage_config(&self) -> &StorageConfig

Source

pub fn spawner(&self) -> Option<&Arc<AgentSpawner>>

Returns the spawner if configured via a spawner: YAML section.

Source

pub fn spawner_registry(&self) -> Option<&Arc<AgentRegistry>>

Returns the agent registry if configured via a spawner: YAML section.

Source

pub fn has_spawner(&self) -> bool

Source

pub fn with_spawner_handles( self, spawner: Arc<AgentSpawner>, registry: Arc<AgentRegistry>, ) -> Self

Source

pub fn with_hooks(self, hooks: Arc<dyn AgentHooks>) -> Self

Source

pub fn with_parallel_tools(self, config: ParallelToolsConfig) -> Self

Source

pub fn with_streaming(self, config: StreamingConfig) -> Self

Source

pub fn with_hitl( self, engine: HITLEngine, handler: Arc<dyn ApprovalHandler>, ) -> Self

Source

pub fn with_max_context_tokens(self, tokens: u32) -> Self

Source

pub fn with_memory_token_budget(self, budget: MemoryTokenBudget) -> Self

Source

pub fn with_recovery_manager(self, manager: RecoveryManager) -> Self

Source

pub fn with_tool_security(self, engine: ToolSecurityEngine) -> Self

Source

pub fn runtime_control(&self) -> RuntimeControlHandle

Returns the host-only runtime control handle.

Source

pub fn set_question_handler(&self, handler: Option<Arc<dyn QuestionHandler>>)

Installs or clears the host question handler used by ask_user.

Source

pub fn set_diagnostics_provider(&self, provider: Arc<dyn DiagnosticsProvider>)

Installs the host diagnostics provider used by diagnostics.

Source

pub fn set_command_runner(&self, runner: Arc<dyn CommandRunner>)

Installs the host command runner used by command.

Source

pub fn set_web_search_provider(&self, provider: Arc<dyn WebSearchProvider>)

Installs the host web-search provider used by web_search.

Source

pub fn todos(&self) -> Vec<TodoItem>

Returns the current session-local todo list.

Source

pub fn with_process_processor(self, processor: ProcessProcessor) -> Self

Source

pub fn with_state_machine( self, state_machine: Arc<StateMachine>, evaluator: Arc<dyn TransitionEvaluator>, ) -> Self

Source

pub fn with_context_manager(self, manager: Arc<ContextManager>) -> Self

Source

pub fn register_message_filter( &self, name: impl Into<String>, filter: Arc<dyn MessageFilter>, )

Source

pub fn set_context(&self, key: &str, value: Value) -> Result<()>

Source

pub fn update_context(&self, path: &str, value: Value) -> Result<()>

Source

pub fn get_context(&self) -> HashMap<String, Value>

Source

pub fn remove_context(&self, key: &str) -> Option<Value>

Source

pub async fn refresh_context(&self, key: &str) -> Result<()>

Source

pub fn register_context_provider( &self, name: &str, provider: Arc<dyn ContextProvider>, )

Source

pub fn current_state(&self) -> Option<String>

Source

pub async fn transition_to(&self, state: &str) -> Result<()>

Applies a manual transition after reserving its exit actions and keeping async lifecycle work outside the commit lock.

Source

pub fn state_history(&self) -> Vec<StateTransitionEvent>

Source

pub fn session_metadata(&self) -> SessionMetadata

Get a copy of current session metadata.

Source

pub async fn delete_actor_data(&self, actor_id: &str) -> Result<()>

Delete all facts and sessions for an actor, gated by privacy.allow_deletion. Returns Err when actor_memory.privacy.allow_deletion is false.

Source

pub fn set_session_metadata(&self, meta: SessionMetadata)

Overwrite session metadata (tags, ttl, custom fields).

Source

pub async fn cleanup_expired_sessions(&self) -> Result<usize>

Delete sessions whose TTL has expired. Returns number of sessions removed.

Source

pub async fn list_sessions_filtered( &self, filter: &SessionFilter, ) -> Result<Vec<SessionSummary>>

List sessions matching a filter. Supports actor, tag, and date filters.

Source

pub async fn save_state(&self) -> Result<AgentSnapshot>

Source

pub async fn save_state_full(&self) -> Result<AgentSnapshot>

Save state including spawned agents manifest for session persistence.

Source

pub async fn restore_state(&self, snapshot: AgentSnapshot) -> Result<()>

Restores persisted state after invalidating any pending confirmation ownership.

Source

pub async fn save_to( &self, storage: &dyn AgentStorage, session_id: &str, ) -> Result<()>

Source

pub async fn load_from( &self, storage: &dyn AgentStorage, session_id: &str, ) -> Result<bool>

Source

pub async fn save_session(&self, session_id: &str) -> Result<()>

Source

pub async fn load_session(&self, session_id: &str) -> Result<bool>

Source

pub async fn restore_session_full(&self, session_id: &str) -> Result<usize>

Restore this runtime and its complete saved child topology from one named session.

Source

pub async fn delete_session(&self, session_id: &str) -> Result<()>

Source

pub async fn list_sessions(&self) -> Result<Vec<String>>

Source

pub fn info(&self) -> AgentInfo

Source

pub fn skills(&self) -> &[SkillDefinition]

Source

pub async fn reset(&self) -> Result<()>

Resets the runtime using the same cleanup path as the Agent trait.

Source

pub fn max_context_tokens(&self) -> u32

Source

pub fn llm_registry(&self) -> &Arc<LLMRegistry>

Source

pub fn state_machine(&self) -> Option<&Arc<StateMachine>>

Source

pub fn context_manager(&self) -> &Arc<ContextManager>

Source

pub fn tool_call_history(&self) -> Vec<ToolCallRecord>

Source

pub fn memory_token_budget(&self) -> Option<&MemoryTokenBudget>

Source

pub fn parallel_tools_config(&self) -> &ParallelToolsConfig

Source

pub fn streaming_config(&self) -> &StreamingConfig

Source

pub fn hooks(&self) -> &Arc<dyn AgentHooks>

Source

pub fn hitl_engine(&self) -> Option<&HITLEngine>

Source

pub fn approval_handler(&self) -> &Arc<dyn ApprovalHandler>

Source

pub async fn check_state_hitl( &self, from: Option<&str>, to: &str, ) -> Result<bool>

Source

pub async fn chat_stream<'a>( &'a self, input: &'a str, ) -> Result<Pin<Box<dyn Stream<Item = StreamChunk> + Send + 'a>>>

Streams one serialized root turn and releases its owned gate guard at Done or when the stream is dropped.

The captured immutable identity stack is restored for every inner poll and export with an Arc clone, so nested hooks and orchestration calls detect same-runtime reentry without rebuilding ancestry. The inner stream is drained after Done before ownership is released.

Source

pub async fn chat_stream_events<'a>( &'a self, input: &'a str, ) -> Result<Pin<Box<dyn Stream<Item = AgentStreamEvent> + Send + 'a>>>

Streams one serialized root turn and releases its owned gate guard at the authoritative terminal event or on drop.

The captured immutable identity stack is restored for every inner poll and export with an Arc clone. The event API shares and drains the legacy execution stream so cleanup, nested-call detection, cancellation, and side effects cannot diverge before the gate is released.

Trait Implementations§

Source§

impl Agent for RuntimeAgent

Source§

fn chat<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<AgentResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs one blocking external root turn with task-local ownership visible through finalization, hooks, orchestration, and export.

Source§

fn reset<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Resets the runtime without leaving clarification or skill ownership behind.

Source§

fn info(&self) -> AgentInfo

Source§

impl Debug for RuntimeAgent

Source§

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

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

impl ToolInvoker for RuntimeAgent

Source§

fn invoke_tool<'life0, 'async_trait>( &'life0 self, request: ToolExecutionRequest, ) -> Pin<Box<dyn Future<Output = Result<ToolExecutionRecord>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Invokes a tool request and returns a structured execution record.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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