Skip to content
Get started

Compact an objective

objectives.compact(objective_id, **kwargs) -> ObjectiveCompactResponse { context_window }
POST/v1/workspaces/{workspaceId}/objectives/{objectiveId}/compact

Triggers compaction on a running objective. Optionally override the variation’s compaction config.

ParametersExpand Collapse
workspace_id: String
objective_id: String
compaction_config: AgentVariationSpecCompactionConfig { summarization, tool_result_clearing, trigger_threshold }

CompactionConfig defines how context window compaction behaves for objectives using this variation.

summarization: CompactionConfigSummarizationStrategy { instructions }

SummarizationStrategy configures LLM-powered summarization of older conversation turns.

instructions: String

Custom instructions that guide what the summarizer preserves. Replaces the default summarization prompt entirely. Example: “Preserve all code snippets, variable names, and technical decisions.”

tool_result_clearing: CompactionConfigToolResultClearingStrategy { preserve_recent_results }

ToolResultClearingStrategy configures clearing of older tool result content.

preserve_recent_results: Integer

Number of most recent tool call results to keep intact. Older tool results have their content replaced with “[result cleared]” while preserving the assistant tool call message (function name, arguments). Default: 2

formatint32
trigger_threshold: Float

Trigger threshold as a percentage of the model’s context window (0.0 to 1.0). When input tokens reach this percentage of the model’s limit, compaction triggers. Default: 0.75 (75%)

formatfloat
ReturnsExpand Collapse
class ObjectiveCompactResponse { context_window }

Compact objective response

context_window: ObjectiveContextWindowData { completion_tokens, objective_id, previous_window_continue_instructions, 2 more }

The new context window created by the compaction

completion_tokens: Integer

A calculated value for how many completion tokens (output tokens) have been used in this context window

formatint32
objective_id: String

The objective’s ID that this window belongs to

previous_window_continue_instructions: String

The instructions for this window to continue from a previous window’s chat history.

prompt_tokens: Integer

A calculated value for how many prompt tokens (input tokens) have been used in this context window

formatint32
sequence: Integer

sequence is a numeric representation of which context window this is. Sequences are useful to perform a max(sequence) on in order to calculate how many context windows an objective has.

formatint32

Compact an objective

require "cadenya"

cadenya = Cadenya::Client.new(api_key: "My API Key")

response = cadenya.objectives.compact("objectiveId", workspace_id: "workspaceId")

puts(response)
{
  "contextWindow": {
    "completionTokens": 0,
    "objectiveId": "objectiveId",
    "previousWindowContinueInstructions": "previousWindowContinueInstructions",
    "promptTokens": 0,
    "sequence": 0
  }
}
Returns Examples
{
  "contextWindow": {
    "completionTokens": 0,
    "objectiveId": "objectiveId",
    "previousWindowContinueInstructions": "previousWindowContinueInstructions",
    "promptTokens": 0,
    "sequence": 0
  }
}