JavaScript
import Cerca from '@cerca-dev/sdk';
const client = new Cerca({
apiKey: process.env['CERCA_API_KEY'], // This is the default and can be omitted
});
const thread = await client.threads.compact('agent_abc123', 'thread_abc123');
console.log(thread.id);import os
from cerca import Cerca
client = Cerca(
api_key=os.environ.get("CERCA_API_KEY"), # This is the default and can be omitted
)
thread = client.threads.compact(
agent_id="agent_abc123",
thread_id="thread_abc123",
)
print(thread.id)package main
import (
"context"
"fmt"
"github.com/matrices/cerca-go"
"github.com/matrices/cerca-go/option"
)
func main() {
client := cercago.NewClient(
option.WithAPIKey("My API Key"),
)
thread, err := client.Threads.Compact(
context.TODO(),
"agent_abc123",
"thread_abc123",
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", thread.ID)
}
require "cerca"
cerca = Cerca::Client.new(api_key: "My API Key")
thread = cerca.threads.compact("agent_abc123", "thread_abc123")
puts(thread)cerca threads compact \
--api-key 'My API Key' \
--agent-id agent_abc123 \
--thread-id thread_abc123curl --request POST \
--url https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact")
.header("Authorization", "Bearer <token>")
.asString();{
"agentId": "<string>",
"completedAt": "<string>",
"createdAt": "<string>",
"depth": 123,
"error": "<string>",
"id": "<string>",
"instructions": "<string>",
"model": "<string>",
"parentThreadId": "<string>",
"result": "<string>",
"scheduleId": "<string>",
"scheduleSeq": 123,
"status": "idle",
"updatedAt": "<string>",
"message": "<string>",
"compiledContext": {
"enabledTools": [
"get_time"
],
"systemPrompt": "<string>",
"turnId": "<string>"
},
"compactionSummary": "<string>",
"compactionThroughSeq": 123,
"composedSystemPrompt": "<string>",
"contextWindow": {
"compacted": true,
"compactionThroughSeq": 123,
"contextWindowTokens": 123,
"estimationMethod": "heuristic_request_v1",
"llmEstimatedTokens": 123,
"model": "<string>",
"rawEstimatedTokens": 123
},
"hasMoreMessages": true,
"lastTurnStatus": "completed",
"messageCursor": 123,
"messages": [
{
"content": [
{
"text": "Hello",
"type": "text"
}
],
"createdAt": "<string>",
"role": "user",
"seq": 123
}
],
"subThreads": [
{
"completedAt": "<string>",
"createdAt": "<string>",
"id": "<string>",
"messageCount": 123,
"model": "<string>",
"parentThreadId": "<string>",
"result": "<string>",
"scheduleId": "<string>",
"scheduleSeq": 123,
"state": "pending",
"stepCount": 123,
"toolUseId": "<string>"
}
],
"tools": [
"get_time"
],
"turns": [
{
"completedAt": "<string>",
"endMessageSeq": 123,
"error": "<string>",
"id": "<string>",
"result": "<string>",
"seq": 123,
"startMessageSeq": 123,
"startedAt": "<string>",
"status": "running",
"threadId": "<string>",
"tokenUsage": {
"inputTokens": 123,
"outputTokens": 123
},
"message": "<string>"
}
],
"externalToolNamespaces": "all",
"activeTurnModel": "<string>"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}Threads
Compact thread
Force context compaction for an idle thread. Compacting a running thread returns a lifecycle conflict.
POST
/
agents
/
{agentId}
/
threads
/
{threadId}
/
compact
JavaScript
import Cerca from '@cerca-dev/sdk';
const client = new Cerca({
apiKey: process.env['CERCA_API_KEY'], // This is the default and can be omitted
});
const thread = await client.threads.compact('agent_abc123', 'thread_abc123');
console.log(thread.id);import os
from cerca import Cerca
client = Cerca(
api_key=os.environ.get("CERCA_API_KEY"), # This is the default and can be omitted
)
thread = client.threads.compact(
agent_id="agent_abc123",
thread_id="thread_abc123",
)
print(thread.id)package main
import (
"context"
"fmt"
"github.com/matrices/cerca-go"
"github.com/matrices/cerca-go/option"
)
func main() {
client := cercago.NewClient(
option.WithAPIKey("My API Key"),
)
thread, err := client.Threads.Compact(
context.TODO(),
"agent_abc123",
"thread_abc123",
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", thread.ID)
}
require "cerca"
cerca = Cerca::Client.new(api_key: "My API Key")
thread = cerca.threads.compact("agent_abc123", "thread_abc123")
puts(thread)cerca threads compact \
--api-key 'My API Key' \
--agent-id agent_abc123 \
--thread-id thread_abc123curl --request POST \
--url https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact \
--header 'Authorization: Bearer <token>'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.cerca.dev/agents/{agentId}/threads/{threadId}/compact")
.header("Authorization", "Bearer <token>")
.asString();{
"agentId": "<string>",
"completedAt": "<string>",
"createdAt": "<string>",
"depth": 123,
"error": "<string>",
"id": "<string>",
"instructions": "<string>",
"model": "<string>",
"parentThreadId": "<string>",
"result": "<string>",
"scheduleId": "<string>",
"scheduleSeq": 123,
"status": "idle",
"updatedAt": "<string>",
"message": "<string>",
"compiledContext": {
"enabledTools": [
"get_time"
],
"systemPrompt": "<string>",
"turnId": "<string>"
},
"compactionSummary": "<string>",
"compactionThroughSeq": 123,
"composedSystemPrompt": "<string>",
"contextWindow": {
"compacted": true,
"compactionThroughSeq": 123,
"contextWindowTokens": 123,
"estimationMethod": "heuristic_request_v1",
"llmEstimatedTokens": 123,
"model": "<string>",
"rawEstimatedTokens": 123
},
"hasMoreMessages": true,
"lastTurnStatus": "completed",
"messageCursor": 123,
"messages": [
{
"content": [
{
"text": "Hello",
"type": "text"
}
],
"createdAt": "<string>",
"role": "user",
"seq": 123
}
],
"subThreads": [
{
"completedAt": "<string>",
"createdAt": "<string>",
"id": "<string>",
"messageCount": 123,
"model": "<string>",
"parentThreadId": "<string>",
"result": "<string>",
"scheduleId": "<string>",
"scheduleSeq": 123,
"state": "pending",
"stepCount": 123,
"toolUseId": "<string>"
}
],
"tools": [
"get_time"
],
"turns": [
{
"completedAt": "<string>",
"endMessageSeq": 123,
"error": "<string>",
"id": "<string>",
"result": "<string>",
"seq": 123,
"startMessageSeq": 123,
"startedAt": "<string>",
"status": "running",
"threadId": "<string>",
"tokenUsage": {
"inputTokens": 123,
"outputTokens": 123
},
"message": "<string>"
}
],
"externalToolNamespaces": "all",
"activeTurnModel": "<string>"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}{
"error": "<string>",
"code": "MONTHLY_TOKEN_BUDGET_EXCEEDED"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Minimum string length:
1Example:
"agent_abc123"
Minimum string length:
1Example:
"thread_abc123"
Response
Compacted thread detail.
idle threads can accept a new turn or be closed. running threads have an active turn. awaiting threads are paused on external input such as approvals. closed threads are terminal.
Available options:
idle, running, awaiting, closed Show child attributes
Show child attributes
Show child attributes
Show child attributes
Available options:
completed, failed, null Show child attributes
Show child attributes
Show child attributes
Show child attributes
Available options:
get_time, sub_thread, wait, tool.call, tool.discover, artifact.read, agent.threads.list, agent.threads.get, agent.approvals.cancel, agent.approvals.grant_thread, agent.approvals.grant_agent, agent.create, agent.approvals.update, tool.connect, sandbox.exec, sandbox.read, sandbox.write_file, sandbox.read_file, sandbox.spawn, sandbox.stdin, sandbox.session_read, sandbox.kill, sandbox.list_sessions, sandbox.sync_artifact, memory.read, memory.list, memory.search, memory.write, memory.delete, db.query, web.search, web.fetch, agent.schedule.list, agent.schedule.create, agent.schedule.update, agent.schedule.delete, agent.schedule.trigger Show child attributes
Show child attributes
Available options:
all