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§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Returns a human-readable description of what this extension does.
Provided Methods§
Sourcefn manifest(&self) -> ExtensionManifest
fn manifest(&self) -> ExtensionManifest
Returns the extension manifest containing metadata and permissions.
Default implementation constructs a minimal manifest from name() and
description().
Sourcefn register_tools(&self) -> Vec<Arc<dyn AgentTool>>
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).
Sourcefn register_commands(&self) -> Vec<Command>
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).
Sourcefn on_load(&self, _ctx: &ExtensionContext)
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.
Sourcefn on_unload(&self)
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().
Sourcefn on_message_sent(&self, _msg: &str)
fn on_message_sent(&self, _msg: &str)
Called after the agent sends a message to the LLM.
_msg is the raw message content string.
Sourcefn on_message_received(&self, _msg: &str)
fn on_message_received(&self, _msg: &str)
Called after receiving a response from the LLM.
_msg is the raw response content string.
Sourcefn on_tool_call(&self, _tool: &str, _params: &Value)
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.
Sourcefn on_tool_result(&self, _tool: &str, _result: &AgentToolResult)
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.
Sourcefn on_session_start(&self, _session_id: &str)
fn on_session_start(&self, _session_id: &str)
Called when a new session starts.
_session_id uniquely identifies the session.
Sourcefn on_session_end(&self, _session_id: &str)
fn on_session_end(&self, _session_id: &str)
Called when a session ends.
_session_id uniquely identifies the session that ended.
Sourcefn on_settings_changed(&self, _settings: &Settings)
fn on_settings_changed(&self, _settings: &Settings)
Called whenever the user saves or updates settings.
Sourcefn on_event(&self, _event: &AgentEvent)
fn on_event(&self, _event: &AgentEvent)
Catch-all hook for any agent event not covered by a specific method.
Sourcefn on_before_tool_call(&self, _tool: &str, _args: &Value) -> Result<(), Error>
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.
Sourcefn on_after_tool_call(
&self,
_tool: &str,
_result: &AgentToolResult,
) -> Result<(), Error>
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.
Sourcefn on_before_compaction(&self, _ctx: &CompactionContext) -> Result<(), Error>
fn on_before_compaction(&self, _ctx: &CompactionContext) -> Result<(), Error>
Called before the context window is compacted. Return Err to abort compaction.
Sourcefn on_after_compaction(&self, _summary: &str) -> Result<(), Error>
fn on_after_compaction(&self, _summary: &str) -> Result<(), Error>
Called after the context window is compacted with the generated summary.
Sourcefn on_error(&self, _error: &Error) -> Result<(), Error>
fn on_error(&self, _error: &Error) -> Result<(), Error>
Called when any error occurs in the agent loop.
Sourcefn session_before_switch(
&self,
_event: &SessionBeforeSwitchEvent,
) -> Result<(), Error>
fn session_before_switch( &self, _event: &SessionBeforeSwitchEvent, ) -> Result<(), Error>
Called before the active session switches to a different branch or parent.
Sourcefn session_before_fork(
&self,
_event: &SessionBeforeForkEvent,
) -> Result<(), Error>
fn session_before_fork( &self, _event: &SessionBeforeForkEvent, ) -> Result<(), Error>
Called before a session is forked (branched) into a new subtree.
Sourcefn session_before_compact(
&self,
_event: &SessionBeforeCompactEvent,
) -> Result<(), Error>
fn session_before_compact( &self, _event: &SessionBeforeCompactEvent, ) -> Result<(), Error>
Called before the context window is compacted.
Sourcefn session_compact(&self, _event: &SessionCompactEvent) -> Result<(), Error>
fn session_compact(&self, _event: &SessionCompactEvent) -> Result<(), Error>
Called when the context window is being compacted.
Sourcefn session_shutdown(&self, _event: &SessionShutdownEvent)
fn session_shutdown(&self, _event: &SessionShutdownEvent)
Called when a session is shutting down.
Sourcefn session_before_tree(
&self,
_event: &SessionBeforeTreeEvent,
) -> Result<(), Error>
fn session_before_tree( &self, _event: &SessionBeforeTreeEvent, ) -> Result<(), Error>
Called before a tree navigation action (branch listing, traversal, etc.).
Sourcefn session_tree(&self, _event: &SessionTreeEvent)
fn session_tree(&self, _event: &SessionTreeEvent)
Called during a tree navigation action.
Sourcefn context(&self, _event: &mut ContextEvent) -> Result<(), Error>
fn context(&self, _event: &mut ContextEvent) -> Result<(), Error>
Emits into the agent context. Return Err to signal that the event was handled.
Sourcefn before_provider_request(
&self,
_event: &mut BeforeProviderRequestEvent,
) -> Result<(), Error>
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.).
Sourcefn after_provider_response(
&self,
_event: &AfterProviderResponseEvent,
) -> Result<(), Error>
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.
Sourcefn model_select(&self, _event: &ModelSelectEvent)
fn model_select(&self, _event: &ModelSelectEvent)
Called when the user or agent selects a model (via /model or auto-routing).
Sourcefn thinking_level_select(&self, _event: &ThinkingLevelSelectEvent)
fn thinking_level_select(&self, _event: &ThinkingLevelSelectEvent)
Called when the thinking level is changed.
Sourcefn input(&self, _event: &InputEvent) -> InputEventResult
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.
Sourcefn register_shortcuts(&self) -> Vec<ExtensionShortcut>
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".