Skip to content
Get started

Compact an objective

client.Objectives.Compact(ctx, objectiveID, body) (*ObjectiveCompactResponse, error)
POST/v1/objectives/{objectiveId}/compact

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

ParametersExpand Collapse
objectiveID string
body ObjectiveCompactParams
CompactionConfig param.Field[AgentVariationSpecCompactionConfig]optional

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

ReturnsExpand Collapse
type ObjectiveCompactResponse struct{…}

Compact objective response

ContextWindow ObjectiveContextWindowDataoptional

The new context window created by the compaction

CompletionTokens int64optional

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

formatint32
ObjectiveID stringoptional

The objective's ID that this window belongs to

PreviousWindowContinueInstructions stringoptional

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

PromptTokens int64optional

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

formatint32
Sequence int64optional

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

package main

import (
  "context"
  "fmt"

  "github.com/cadenya/cadenya-go"
  "github.com/cadenya/cadenya-go/option"
)

func main() {
  client := cadenya.NewClient(
    option.WithAPIKey("My API Key"),
  )
  response, err := client.Objectives.Compact(
    context.TODO(),
    "objectiveId",
    cadenya.ObjectiveCompactParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.ContextWindow)
}
{
  "contextWindow": {
    "completionTokens": 0,
    "objectiveId": "objectiveId",
    "previousWindowContinueInstructions": "previousWindowContinueInstructions",
    "promptTokens": 0,
    "sequence": 0
  }
}
Returns Examples
{
  "contextWindow": {
    "completionTokens": 0,
    "objectiveId": "objectiveId",
    "previousWindowContinueInstructions": "previousWindowContinueInstructions",
    "promptTokens": 0,
    "sequence": 0
  }
}