---
title: "Compact an objective"
method: POST
path: "/v1/workspaces/{workspaceId}/objectives/{objectiveId}:compact"
tags: ["ObjectiveService", "Objectives"]
---

# Compact an objective

`POST /v1/workspaces/{workspaceId}/objectives/{objectiveId}:compact`

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

## Path parameters

- `workspaceId` string, required
- `objectiveId` string, required

## Request body

- CompactObjectiveRequest — Compact objective request — triggers compaction on a running objective.
  - `workspaceId` string
  - `objectiveId` string — The ID of the objective. Supports "external_id:" prefix for external IDs.
  - `compactionConfig` AgentVariationSpecCompactionConfig — CompactionConfig defines how context window compaction behaves for objectives using this variation.
    - `triggerThreshold` number, 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%)
    - `summarization` CompactionConfigSummarizationStrategy — 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."
    - `toolResultClearing` CompactionConfigToolResultClearingStrategy — ToolResultClearingStrategy configures clearing of older tool result content.
      - `preserveRecentResults` 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

## Response `200`

OK

- CompactObjectiveResponse — Compact objective response
  - `contextWindow` ObjectiveContextWindowData
    - `objectiveId` string — The objective's ID that this window belongs to
    - `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.
    - `promptTokens` integer — A calculated value for how many prompt tokens (input tokens) have been used in this context window
    - `completionTokens` integer — A calculated value for how many completion tokens (output tokens) have been used in this context window
    - `previousWindowContinueInstructions` string — The instructions for this window to continue from a previous window's chat history.

## Other responses

- `default` — Default error response

---

[API](https://skmtc.net/cadenya/apis/cadenya-api.md) · [All operations](https://skmtc.net/cadenya/apis/cadenya-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/cadenya/cadenya-api/versions/ac1a7f084068/schema)
