Skip to main content

Extension

Trait Extension 

Source
pub trait Extension: Send + Sync {
Show 35 methods // Required methods fn name(&self) -> &str; fn description(&self) -> &str; // Provided methods fn manifest(&self) -> ExtensionManifest { ... } fn register_tools(&self) -> Vec<Arc<dyn AgentTool>> { ... } fn register_commands(&self) -> Vec<Command> { ... } fn on_load(&self, _ctx: &ExtensionContext) { ... } fn on_unload(&self) { ... } fn on_message_sent(&self, _msg: &str) { ... } fn on_message_received(&self, _msg: &str) { ... } fn on_tool_call(&self, _tool: &str, _params: &Value) { ... } fn on_tool_result(&self, _tool: &str, _result: &AgentToolResult) { ... } fn on_session_start(&self, _session_id: &str) { ... } fn on_session_end(&self, _session_id: &str) { ... } fn on_settings_changed(&self, _settings: &Settings) { ... } fn on_event(&self, _event: &AgentEvent) { ... } fn on_before_tool_call( &self, _tool: &str, _args: &Value, ) -> Result<(), Error> { ... } fn on_after_tool_call( &self, _tool: &str, _result: &AgentToolResult, ) -> Result<(), Error> { ... } fn on_before_compaction( &self, _ctx: &CompactionContext, ) -> Result<(), Error> { ... } fn on_after_compaction(&self, _summary: &str) -> Result<(), Error> { ... } fn on_error(&self, _error: &Error) -> Result<(), Error> { ... } fn session_before_switch( &self, _event: &SessionBeforeSwitchEvent, ) -> Result<(), Error> { ... } fn session_before_fork( &self, _event: &SessionBeforeForkEvent, ) -> Result<(), Error> { ... } fn session_before_compact( &self, _event: &SessionBeforeCompactEvent, ) -> Result<(), Error> { ... } fn session_compact(&self, _event: &SessionCompactEvent) -> Result<(), Error> { ... } fn session_shutdown(&self, _event: &SessionShutdownEvent) { ... } fn session_before_tree( &self, _event: &SessionBeforeTreeEvent, ) -> Result<(), Error> { ... } fn session_tree(&self, _event: &SessionTreeEvent) { ... } fn context(&self, _event: &mut ContextEvent) -> Result<(), Error> { ... } fn before_provider_request( &self, _event: &mut BeforeProviderRequestEvent, ) -> Result<(), Error> { ... } fn after_provider_response( &self, _event: &AfterProviderResponseEvent, ) -> Result<(), Error> { ... } fn model_select(&self, _event: &ModelSelectEvent) { ... } fn thinking_level_select(&self, _event: &ThinkingLevelSelectEvent) { ... } fn bash(&self, _event: &BashEvent) { ... } fn input(&self, _event: &InputEvent) -> InputEventResult { ... } fn register_shortcuts(&self) -> Vec<ExtensionShortcut> { ... }
}
Expand description

Core trait that every oxi extension must implement.

Required Methods§

Source

fn name(&self) -> &str

Returns the extension’s unique identifier.

Source

fn description(&self) -> &str

Returns a human-readable description of what this extension does.

Provided Methods§

Source

fn manifest(&self) -> ExtensionManifest

Returns the extension manifest containing metadata and permissions. Default implementation constructs a minimal manifest from name() and description().

Source

fn register_tools(&self) -> Vec<Arc<dyn AgentTool>>

Registers custom tools exposed by this extension. Each returned tool becomes available to the agent at runtime. Default returns an empty vector (no custom tools).

Source

fn register_commands(&self) -> Vec<Command>

Registers slash commands exposed by this extension. Each returned command becomes available as /<name> in the input field. Default returns an empty vector (no custom commands).

Source

fn on_load(&self, _ctx: &ExtensionContext)

Called once when the extension is first loaded into a session. Use this to initialize resources, read config, or register with external services.

Source

fn on_unload(&self)

Called once when the extension is unloaded or the session ends. Use this to clean up resources allocated in on_load().

Source

fn on_message_sent(&self, _msg: &str)

Called after the agent sends a message to the LLM. _msg is the raw message content string.

Source

fn on_message_received(&self, _msg: &str)

Called after receiving a response from the LLM. _msg is the raw response content string.

Source

fn on_tool_call(&self, _tool: &str, _params: &Value)

Called immediately before a tool is executed. _tool is the tool name and _params are the JSON arguments.

Source

fn on_tool_result(&self, _tool: &str, _result: &AgentToolResult)

Called immediately after a tool execution completes. _tool is the tool name and _result contains the output or error.

Source

fn on_session_start(&self, _session_id: &str)

Called when a new session starts. _session_id uniquely identifies the session.

Source

fn on_session_end(&self, _session_id: &str)

Called when a session ends. _session_id uniquely identifies the session that ended.

Source

fn on_settings_changed(&self, _settings: &Settings)

Called whenever the user saves or updates settings.

Source

fn on_event(&self, _event: &AgentEvent)

Catch-all hook for any agent event not covered by a specific method.

Source

fn on_before_tool_call(&self, _tool: &str, _args: &Value) -> Result<(), Error>

Called before a tool is executed. Return Err to block the tool call.

Source

fn on_after_tool_call( &self, _tool: &str, _result: &AgentToolResult, ) -> Result<(), Error>

Called after a tool completes. Return Err to surface an error to the agent.

Source

fn on_before_compaction(&self, _ctx: &CompactionContext) -> Result<(), Error>

Called before the context window is compacted. Return Err to abort compaction.

Source

fn on_after_compaction(&self, _summary: &str) -> Result<(), Error>

Called after the context window is compacted with the generated summary.

Source

fn on_error(&self, _error: &Error) -> Result<(), Error>

Called when any error occurs in the agent loop.

Source

fn session_before_switch( &self, _event: &SessionBeforeSwitchEvent, ) -> Result<(), Error>

Called before the active session switches to a different branch or parent.

Source

fn session_before_fork( &self, _event: &SessionBeforeForkEvent, ) -> Result<(), Error>

Called before a session is forked (branched) into a new subtree.

Source

fn session_before_compact( &self, _event: &SessionBeforeCompactEvent, ) -> Result<(), Error>

Called before the context window is compacted.

Source

fn session_compact(&self, _event: &SessionCompactEvent) -> Result<(), Error>

Called when the context window is being compacted.

Source

fn session_shutdown(&self, _event: &SessionShutdownEvent)

Called when a session is shutting down.

Source

fn session_before_tree( &self, _event: &SessionBeforeTreeEvent, ) -> Result<(), Error>

Called before a tree navigation action (branch listing, traversal, etc.).

Source

fn session_tree(&self, _event: &SessionTreeEvent)

Called during a tree navigation action.

Source

fn context(&self, _event: &mut ContextEvent) -> Result<(), Error>

Emits into the agent context. Return Err to signal that the event was handled.

Source

fn before_provider_request( &self, _event: &mut BeforeProviderRequestEvent, ) -> Result<(), Error>

Called before every LLM provider request. Allows the extension to mutate the request parameters (model, temperature, tools, etc.).

Source

fn after_provider_response( &self, _event: &AfterProviderResponseEvent, ) -> Result<(), Error>

Called after every LLM provider response. Allows the extension to read or annotate the response before it is processed by the agent loop.

Source

fn model_select(&self, _event: &ModelSelectEvent)

Called when the user or agent selects a model (via /model or auto-routing).

Source

fn thinking_level_select(&self, _event: &ThinkingLevelSelectEvent)

Called when the thinking level is changed.

Source

fn bash(&self, _event: &BashEvent)

Called when a bash command is about to be executed.

Source

fn input(&self, _event: &InputEvent) -> InputEventResult

Called for every user input keystroke. Return InputEventResult::Handled to suppress the default input handling, or InputEventResult::Transform { text } to replace the input text.

Source

fn register_shortcuts(&self) -> Vec<ExtensionShortcut>

Registers keyboard shortcuts exposed by this extension. Default returns an empty vector (no shortcuts).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§