Skip to main content

Extension

Trait Extension 

Source
pub trait Extension: Send + Sync {
    // Required method
    fn name(&self) -> Cow<'static, str>;

    // Provided methods
    fn tools(&self) -> Vec<ToolDefinition> { ... }
    fn commands(&self) -> Vec<SlashCommand> { ... }
    fn skills(&self) -> SkillSet { ... }
    fn before_compact(
        &self,
        _first_kept_entry_id: &str,
        _tokens_before: u64,
        _reason: &str,
        _cancel: &Cancel,
    ) -> Option<BeforeCompactResult> { ... }
    fn after_compact(
        &self,
        _summary: &str,
        _first_kept_entry_id: &str,
        _tokens_before: u64,
        _estimated_tokens_after: u64,
        _from_hook: bool,
        _reason: &str,
        _cancel: &Cancel,
    ) { ... }
}

Required Methods§

Source

fn name(&self) -> Cow<'static, str>

Provided Methods§

Source

fn tools(&self) -> Vec<ToolDefinition>

Tools this extension provides (LLM-callable), each with its own prompt metadata.

Source

fn commands(&self) -> Vec<SlashCommand>

Slash commands this extension provides (e.g. /quit, /model). Built-in commands and extension commands use the same interface.

Source

fn skills(&self) -> SkillSet

Skills this extension provides (AgentSkills-compatible). Merged into the session’s skill set for /skill:name expansion and system prompt.

Source

fn before_compact( &self, _first_kept_entry_id: &str, _tokens_before: u64, _reason: &str, _cancel: &Cancel, ) -> Option<BeforeCompactResult>

Called before compaction runs (matching pi’s session_before_compact). Return Some(BeforeCompactResult { cancel: true, .. }) to cancel compaction. Return Some(BeforeCompactResult { cancel: false, summary: Some(...), .. }) to provide a custom summary instead of calling the provider. Return None to let the default compaction proceed.

cancel is a cancellation token — check cancel.is_cancelled() in long-running hooks and return immediately if true (matching pi’s AbortSignal passed to session_before_compact).

Source

fn after_compact( &self, _summary: &str, _first_kept_entry_id: &str, _tokens_before: u64, _estimated_tokens_after: u64, _from_hook: bool, _reason: &str, _cancel: &Cancel, )

Called after compaction completes (matching pi’s session_compact).

cancel is a cancellation token — check cancel.is_cancelled() in long-running hooks and return early if true (matching pi’s AbortSignal passed to session_compact).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§