Skip to main content

SystemMessageTransform

Trait SystemMessageTransform 

Source
pub trait SystemMessageTransform:
    Send
    + Sync
    + 'static {
    // Required methods
    fn section_ids(&self) -> Vec<String>;
    fn transform_section<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        section_id: &'life1 str,
        content: &'life2 str,
        ctx: TransformContext,
    ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Handles systemMessage.transform RPC requests from the CLI.

The CLI sends these during session creation/resumption when the session’s SystemMessageConfig contains sections with action: "transform". For each such section, the CLI provides the current content and expects the SDK to return the (possibly modified) content.

Implement this trait and pass it to Client::create_session / Client::resume_session to participate in system message customization.

§Example

struct MyTransform;

#[async_trait::async_trait]
impl SystemMessageTransform for MyTransform {
    fn section_ids(&self) -> Vec<String> {
        vec!["instructions".to_string()]
    }

    async fn transform_section(
        &self,
        _section_id: &str,
        content: &str,
        _ctx: TransformContext,
    ) -> Option<String> {
        Some(format!("{content}\n\nAlways be concise."))
    }
}

Required Methods§

Source

fn section_ids(&self) -> Vec<String>

Section IDs this transform handles.

The SDK injects action: "transform" entries into the SystemMessageConfig wire format for each returned ID.

Source

fn transform_section<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, section_id: &'life1 str, content: &'life2 str, ctx: TransformContext, ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Transform a section’s content. Return Some(new_content) to modify the section, or None to pass through unchanged.

Implementors§