pub struct ProgressiveTransformer { /* private fields */ }Expand description
A two-phase output transformer that returns an LLM-generated summary first,
with the full output cached and available on demand via the
__get_full_output virtual tool.
§Workflow
- Output arrives from a tool call.
- If
output.len() <= max_summary_length→ returned unchanged (no LLM call). - If larger → LLM is called to summarize → summary returned + note appended.
- Full output cached internally keyed by
tool_name. - Agent can call
__get_full_output→FullOutputRetrieverserves it.
§Example
use traitclaw_core::transformers::ProgressiveTransformer;
use std::sync::Arc;
// let transformer = ProgressiveTransformer::new(provider.clone(), 500)
// .with_summary_prompt("Give a one-sentence summary: {output}");Implementations§
Source§impl ProgressiveTransformer
impl ProgressiveTransformer
Sourcepub fn new(provider: Arc<dyn Provider>, max_summary_length: usize) -> Self
pub fn new(provider: Arc<dyn Provider>, max_summary_length: usize) -> Self
Create a new progressive transformer.
provider: LLM used to generate summaries.max_summary_length: Outputs shorter than this are passed through unchanged.
Sourcepub fn with_summary_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_summary_prompt(self, prompt: impl Into<String>) -> Self
Override the summarization prompt template.
Use {output} as the placeholder for the tool output.
Sourcepub fn retriever_tool(&self) -> FullOutputRetriever
pub fn retriever_tool(&self) -> FullOutputRetriever
Build a FullOutputRetriever that reads from this transformer’s cache.
Register this tool with the agent so the LLM can call __get_full_output.
Trait Implementations§
Source§impl OutputTransformer for ProgressiveTransformer
impl OutputTransformer for ProgressiveTransformer
Source§fn transform<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
output: String,
tool_name: &'life1 str,
_state: &'life2 AgentState,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn transform<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
output: String,
tool_name: &'life1 str,
_state: &'life2 AgentState,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Transform tool output, optionally using context about which tool
produced it and the current agent state. Read more
Auto Trait Implementations§
impl Freeze for ProgressiveTransformer
impl !RefUnwindSafe for ProgressiveTransformer
impl Send for ProgressiveTransformer
impl Sync for ProgressiveTransformer
impl Unpin for ProgressiveTransformer
impl UnsafeUnpin for ProgressiveTransformer
impl !UnwindSafe for ProgressiveTransformer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more