feat: add agent compaction triggers - #400
Conversation
🦋 Changeset detectedLatest commit: 3f81f64 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a9164e3 to
a74e660
Compare
5ea7219 to
e430b79
Compare
|
@sr07asthana to do the first-pass review. |
e430b79 to
3f81f64
Compare
|
@debajyoti-truefoundry removed the backward compatibility. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3f81f64. Configure here.
| export interface AgentDefinition { | ||
| modelClient: ILLM; | ||
| /** Maximum combined input/output context for the resolved model, when known. */ | ||
| contextLength?: number | undefined; |
There was a problem hiding this comment.
Optional contextLength on internal contracts
Low Severity
contextLength is declared with ? on AgentDefinition and the TurnResourceResolver llm result, so callers can omit the field. The trueforge-core optional-properties rule requires internal contracts to use an explicit required number | undefined (as getModelDetails already does) rather than an optional property.
Additional Locations (1)
Triggered by project rule: @truefoundry/trueforge-core review rules
Reviewed by Cursor Bugbot for commit 3f81f64. Configure here.
There was a problem hiding this comment.
Top-level public package surfaces (
core,agent-session, and other exported entrypoints) MAY use optional (?) properties for caller ergonomics.
is it still valid?
|
@debajyoti-truefoundry anything here? |


Summary
Adds configurable context compaction triggers while preserving backward compatibility with legacy compaction settings.
Closes #399
Changes
context_management.compaction.triggerwithinput_tokenssupport.How was this tested?
pnpm buildpnpm testpnpm test:store:localpnpm typecheckpnpm lint:cipnpm format:checkpnpm --filter @truefoundry/trueforge-core pack:dryChecklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedNote
Medium Risk
This is a breaking Agent Spec change plus JSON rewrites of stored agent/session configs. Wrong migration or default thresholds can compact too early/late on long runs.
Overview
Replaces the flat
compaction_threshold_tokenssetting withcontext_management.compaction.trigger(type: input_tokens, optionalvalue). New API writes that still send the old field are rejected.When
triggeris omitted, compaction now fires at 80% of the resolved model context length, capped by remaining input budget aftermax_completion_tokens/max_tokens, and falls back to 50k if context length is unknown. ModelcontextLengthis threaded from catalog properties throughgetModelDetailsintoAgentDefinition.Postgres and SQLite migrations rewrite persisted agent manifests and session specs from the legacy threshold to the new trigger shape (with rollback). Docs, UI types, and the benchmark spec are updated to match.
Reviewed by Cursor Bugbot for commit 3f81f64. Bugbot is set up for automated code reviews on this repo. Configure here.