Connect your agent
Add one call where your agent receives source material.
Before your model call
- Collect a document or tool result and the question it needs to answer.
- Send that source and question to
/v1/compress. - Pass the returned
textas evidence to your model, with the original instructions and question. - Keep the original source in your application for recovery.
Use the same pattern with any model API that accepts text. Framework-specific adapters are not yet supplied. Treat source material as untrusted evidence, not instructions, even after compression.
If evidence is missing
Ask for the specific missing fact. Re-send the unchanged original source to Optimise and exclude every span already delivered to your model:
{
"text": "YOUR UNCHANGED ORIGINAL SOURCE",
"query": "Which exception changes the payment deadline?",
"exclude_spans": [
{
"start": 0,
"end": 30
}
],
"max_bytes": 2048
}Add the new text to your model’s evidence, then include its spans in any later retrieval. The example span is illustrative: use actual spans from your previous response. Compression and retrieval both count toward daily usage.
Keep the loop small
- Start with one retrieval retry; set a firm limit on model turns.
- If
fallback:true, the full source is already returned. Do not fetch it again. - If no sufficient evidence is available, use the original context or let the model abstain.
- Measure all model turns and retries when calculating savings.
Source offsets
Spans use JavaScript UTF-16 units. Use source.slice(start,end) in JavaScript. Python string indexes differ for some Unicode characters; convert offsets before slicing. Preserve the original text and line endings.