Skip to main content

Agent

Struct Agent 

Source
pub struct Agent<C: Channel> { /* private fields */ }

Implementations§

Source§

impl<C: Channel> Agent<C>

Source

pub fn with_autosave_config( self, autosave_assistant: bool, min_length: usize, ) -> Self

Source

pub fn with_tool_call_cutoff(self, cutoff: usize) -> Self

Source

pub fn with_response_cache(self, cache: Arc<ResponseCache>) -> Self

Source

pub fn with_parent_tool_use_id(self, id: impl Into<String>) -> Self

Set the parent tool call ID for subagent sessions.

When set, every LoopbackEvent::ToolStart and LoopbackEvent::ToolOutput emitted by this agent will carry the parent_tool_use_id so the IDE can build a subagent hierarchy tree.

Source

pub fn with_stt(self, stt: Box<dyn SpeechToText>) -> Self

Source

pub fn with_debug_dumper(self, dumper: DebugDumper) -> Self

Enable debug dump mode, writing LLM requests/responses and raw tool output to dumper.

Source

pub fn with_update_notifications(self, rx: Receiver<String>) -> Self

Source

pub fn with_custom_task_rx(self, rx: Receiver<String>) -> Self

Source

pub fn add_tool_executor(self, extra: impl ToolExecutor + 'static) -> Self

Wrap the current tool executor with an additional executor via CompositeExecutor.

Source

pub fn with_max_tool_iterations(self, max: usize) -> Self

Source

pub fn with_max_tool_retries(self, max: usize) -> Self

Set the maximum number of retry attempts for transient tool errors (0 = disabled, max 5).

Source

pub fn with_tool_repeat_threshold(self, threshold: usize) -> Self

Set the repeat-detection threshold (0 = disabled). Window size is 2 * threshold.

Source

pub fn with_memory( self, memory: Arc<SemanticMemory>, conversation_id: ConversationId, history_limit: u32, recall_limit: usize, summarization_threshold: usize, ) -> Self

Source

pub fn with_embedding_model(self, model: String) -> Self

Source

pub fn with_disambiguation_threshold(self, threshold: f32) -> Self

Source

pub fn with_skill_prompt_mode(self, mode: SkillPromptMode) -> Self

Source

pub fn with_document_config(self, config: DocumentConfig) -> Self

Source

pub fn with_graph_config(self, config: GraphConfig) -> Self

Source

pub fn with_anomaly_detector(self, detector: AnomalyDetector) -> Self

Source

pub fn with_instruction_blocks(self, blocks: Vec<InstructionBlock>) -> Self

Source

pub fn with_instruction_reload( self, rx: Receiver<InstructionEvent>, state: InstructionReloadState, ) -> Self

Source

pub fn with_shutdown(self, rx: Receiver<bool>) -> Self

Source

pub fn with_skill_reload( self, paths: Vec<PathBuf>, rx: Receiver<SkillEvent>, ) -> Self

Source

pub fn with_managed_skills_dir(self, dir: PathBuf) -> Self

Source

pub fn with_trust_config(self, config: TrustConfig) -> Self

Source

pub fn with_config_reload( self, path: PathBuf, rx: Receiver<ConfigEvent>, ) -> Self

Source

pub fn with_logging_config(self, logging: LoggingConfig) -> Self

Source

pub fn with_available_secrets( self, secrets: impl IntoIterator<Item = (String, Secret)>, ) -> Self

§Panics

Panics if the registry RwLock is poisoned.

Source

pub fn with_learning(self, config: LearningConfig) -> Self

Source

pub fn with_judge_provider(self, provider: AnyProvider) -> Self

Source

pub fn with_mcp( self, tools: Vec<McpTool>, registry: Option<McpToolRegistry>, manager: Option<Arc<McpManager>>, mcp_config: &McpConfig, ) -> Self

Source

pub fn with_mcp_shared_tools(self, shared: Arc<RwLock<Vec<McpTool>>>) -> Self

Source

pub fn with_security( self, security: SecurityConfig, timeouts: TimeoutConfig, ) -> Self

Source

pub fn with_redact_credentials(self, enabled: bool) -> Self

Source

pub fn with_tool_summarization(self, enabled: bool) -> Self

Source

pub fn with_overflow_config(self, config: OverflowConfig) -> Self

Source

pub fn with_summary_provider(self, provider: AnyProvider) -> Self

Source

pub fn with_quarantine_summarizer(self, qs: QuarantinedSummarizer) -> Self

Source

pub fn with_permission_policy(self, policy: PermissionPolicy) -> Self

Source

pub fn with_context_budget( self, budget_tokens: usize, reserve_ratio: f32, compaction_threshold: f32, compaction_preserve_tail: usize, prune_protect_tokens: usize, ) -> Self

Source

pub fn with_deferred_apply_threshold(self, threshold: f32) -> Self

Source

pub fn with_compression(self, compression: CompressionConfig) -> Self

Source

pub fn with_routing(self, routing: RoutingConfig) -> Self

Source

pub fn with_model_name(self, name: impl Into<String>) -> Self

Source

pub fn with_warmup_ready(self, rx: Receiver<bool>) -> Self

Source

pub fn with_cost_tracker(self, tracker: CostTracker) -> Self

Source

pub fn with_metrics(self, tx: Sender<MetricsSnapshot>) -> Self

§Panics

Panics if the registry RwLock is poisoned.

Source

pub fn cancel_signal(&self) -> Arc<Notify>

Returns a handle that can cancel the current in-flight operation. The returned Notify is stable across messages — callers invoke notify_waiters() to cancel whatever operation is running.

Source

pub fn with_cancel_signal(self, signal: Arc<Notify>) -> Self

Inject a shared cancel signal so an external caller (e.g. ACP session) can interrupt the agent loop by calling notify_one().

Source

pub fn with_subagent_manager(self, manager: SubAgentManager) -> Self

Source

pub fn with_subagent_config(self, config: SubAgentConfig) -> Self

Source

pub fn with_orchestration_config(self, config: OrchestrationConfig) -> Self

Source

pub fn with_provider_override( self, slot: Arc<RwLock<Option<AnyProvider>>>, ) -> Self

Inject a shared provider override slot for runtime model switching (e.g. via ACP set_session_config_option). The agent checks and swaps the provider before each turn.

Source§

impl<C: Channel> Agent<C>

Source

pub async fn handle_graph_command( &mut self, input: &str, ) -> Result<(), AgentError>

Dispatch /graph [subcommand] slash command.

§Errors

Returns an error if the channel send fails or graph store query fails.

Source§

impl<C: Channel> Agent<C>

Source

pub async fn handle_log_command(&mut self) -> Result<(), AgentError>

Handle the /log slash command: show current log file path and recent entries.

§Errors

Returns an error if the channel send fails.

Source§

impl<C: Channel> Agent<C>

Source

pub async fn load_history(&mut self) -> Result<(), AgentError>

Load conversation history from memory and inject into messages.

§Errors

Returns an error if loading history from SQLite fails.

Source§

impl<C: Channel> Agent<C>

Source

pub fn sync_community_detection_failures(&self)

Read the community-detection failure counter from SemanticMemory and update metrics.

Source

pub fn sync_graph_extraction_metrics(&self)

Sync all graph counters (extraction count/failures) from SemanticMemory to metrics.

Source

pub async fn sync_graph_counts(&self)

Fetch entity/edge/community counts from the graph store and write to metrics.

Source

pub async fn check_vector_store_health(&self, backend_name: &str)

Perform a real health check on the vector store and update metrics.

Source

pub fn inject_code_context(&mut self, text: &str)

Inject pre-formatted code context into the message list. The caller is responsible for retrieving and formatting the text.

Source

pub fn context_messages(&self) -> &[Message]

Source§

impl<C: Channel> Agent<C>

Source

pub fn new( provider: AnyProvider, channel: C, registry: SkillRegistry, matcher: Option<SkillMatcherBackend>, max_active_skills: usize, tool_executor: impl ToolExecutor + 'static, ) -> Self

Source

pub fn new_with_registry_arc( provider: AnyProvider, channel: C, registry: Arc<RwLock<SkillRegistry>>, matcher: Option<SkillMatcherBackend>, max_active_skills: usize, tool_executor: impl ToolExecutor + 'static, ) -> Self

Create an agent from a pre-wrapped registry Arc, allowing the caller to share the same Arc with other components (e.g. crate::SkillLoaderExecutor).

§Panics

Panics if the registry RwLock is poisoned.

Source

pub async fn poll_subagents(&mut self) -> Vec<(String, String)>

Poll all active sub-agents for completed/failed/canceled results.

Non-blocking: returns immediately with a list of (task_id, result) pairs for agents that have finished. Each completed agent is removed from the manager.

Source

pub async fn shutdown(&mut self)

Source

pub async fn run(&mut self) -> Result<()>

Run the chat loop, receiving messages via the channel until EOF or shutdown.

§Errors

Returns an error if channel I/O or LLM communication fails.

Source

pub fn set_model(&mut self, model_id: &str) -> Result<(), String>

Switch the active provider to one serving model_id.

Looks up the model in the provider’s remote model list (or cache).

§Errors

Returns Err if the model is not found.

Auto Trait Implementations§

§

impl<C> !Freeze for Agent<C>

§

impl<C> !RefUnwindSafe for Agent<C>

§

impl<C> Send for Agent<C>

§

impl<C> Sync for Agent<C>
where C: Sync,

§

impl<C> Unpin for Agent<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Agent<C>
where C: UnsafeUnpin,

§

impl<C> !UnwindSafe for Agent<C>

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

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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