Skip to content

feat(memory): preserve Agent tool history with bounded context - #8003

Merged
icecrasher321 merged 16 commits into
stagingfrom
codex/durable-agent-memory
Sep 20, 2026
Merged

icecrasher321 merged 16 commits into
stagingfrom
codex/durable-agent-memory

Conversation

@icecrasher321

@icecrasher321 icecrasher321 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Agents preserve assistant tool-call batches, original arguments, terminal results, and final responses in ordered conversation history. Existing retries and model fallbacks continue from recorded outcomes without repeating completed tools. Uncertain outcomes remain at-least-once.
  • Keep conversation storage, invocation checkpoints, and provider adaptation separate. The existing large-value service stores encrypted payloads; compact checkpoints reference each immutable step/result instead of repeatedly rewriting accumulated payloads.
  • Budget complete history groups before every provider generation against the actual model, reserving instructions, tools, attachments, and output. Default recalled history targets 16,000 estimated tokens. Estimates trim optional history without rejecting required prompts or tool results; the provider enforces its actual context limit. Large results use bounded previews; authorized agent_memory_read retrieves omitted details. Bounded, metered summaries preserve useful older context without replacing original records.
  • Preserve legacy conversations and plain-message Memory API, Memory block, and Pi contracts. Update Agent docs and add an additive migration, version-aware writers, capture controls, and rollback guidance. Drain old workers before enabling new storage/checkpoint writes.

Type of Change

  • New feature
  • Documentation

Testing

  • 3,138 memory, Agent, and provider regression tests passed; 60 gated tests skipped. Five protocol families have adapter/streaming fixtures.
  • 55 isolated PostgreSQL tests passed, including migration, concurrent appends/CAS, immutable legacy prefixes, provenance, deletion/recreation, bounded reads, artifact ownership, and encrypted summary-cache projection. These suites are included in PostgreSQL CI.
  • Lint, all 47 repository audits, all 26 workspace type checks, generated-doc checks, migration safety, and Drizzle metadata validation passed.
  • Ran bun run dev:full and synthetic workflows through V2 APIs. OpenAI Responses, Chat Completions, Anthropic, and Gemini verified persisted tool-result recall. Anthropic/Gemini streamed tool turns and subsequent recall passed; Chat Completions streaming recall was verified separately from its existing settled tool loop.
  • Injected failures after a completed tool result: Responses, Anthropic, and Gemini fallbacks each received the result with one tool execution. A streamed fallback and subsequent recall also completed with one tool execution. Large-result retrieval recovered a tail detail from a 140 KB result without rerunning the tool. A six-stage live tool loop summarized active history, preserved receipts, and included summary usage exactly once.
  • Live context-pressure tests passed for Chat Completions, Anthropic, and Gemini; summaries remained encrypted and absent from public memory responses. Bedrock has fixture coverage only. Live tests used synthetic data and an isolated local database.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 19, 2026 10:43pm UTC

Request Review

@icecrasher321 icecrasher321 changed the title feat(memory): preserve durable Agent tool history feat(memory): preserve Agent tool history with bounded context Sep 19, 2026
@icecrasher321
icecrasher321 marked this pull request as ready for review September 19, 2026 18:57
@greptile-apps

greptile-apps Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previous findings are resolved and no actionable new regression was established in the changes since the prior review.

Summary

This PR adds durable, bounded Agent conversation history that records completed tool exchanges and reuses their outcomes across retries and model fallbacks.

  • Introduces immutable conversation steps, checkpoints, encrypted summaries, bounded large-result previews, and authorized detail retrieval.
  • Adds context budgeting and provider-specific history adaptation across the supported protocol families.
  • Preserves legacy plain-message memory projections while extending internal rich history.
  • Adds database storage, migration metadata, extensive provider and persistence tests, documentation, feature controls, and rollback guidance.
Diagram
sequenceDiagram
  participant Agent as Agent Handler
  participant Memory as Durable Memory
  participant Model as Provider Model
  participant Tool as Tool Runtime

  Agent->>Memory: Open invocation turn and load bounded history
  Memory-->>Agent: Complete prior message/tool groups
  Agent->>Model: Generate with selected history
  Model-->>Agent: Assistant tool-call batch
  Agent->>Memory: Checkpoint assistant calls
  Agent->>Tool: Execute unresolved calls
  Tool-->>Agent: Results or terminal errors
  Agent->>Memory: Persist immutable completed exchange
  Agent->>Model: Continue with recorded results
  alt provider failure
    Agent->>Model: Retry or fallback with same recorded outcomes
  end
  Model-->>Agent: Final response
  Agent->>Memory: Finalize turn
Loading

Reviews (6) · Last reviewed commit: "fix(memory): admit only complete stored ..."

Comment thread apps/sim/executor/handlers/agent/agent-handler.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread apps/sim/executor/handlers/agent/types.ts
Comment thread apps/sim/providers/anthropic/utils.ts
Comment thread apps/sim/providers/bedrock/request-history.ts Outdated
Comment thread apps/sim/providers/conversation-generation.ts
Comment thread apps/sim/providers/together/index.ts
Comment thread apps/sim/providers/openai/streaming-tool-loop.ts
Comment thread apps/sim/providers/index.ts Outdated
Comment thread apps/sim/providers/groq/index.ts
Comment thread packages/testing/src/mocks/schema.mock.ts
Comment thread apps/sim/lib/memory/retrieval.ts Outdated
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 177 files

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread apps/sim/lib/memory/conversation-store.ts
Comment thread apps/sim/providers/openrouter/index.ts
Comment thread apps/sim/lib/memory/artifacts.ts
Comment thread apps/sim/executor/handlers/agent/memory.ts Outdated
Comment thread apps/sim/providers/index.ts
Comment thread apps/sim/providers/conversation-history.ts
Comment thread apps/sim/lib/memory/turn-state.ts
Comment thread apps/sim/lib/memory/history-window.ts
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/providers/openrouter/index.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 178 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/executor/handlers/agent/memory.ts
Comment thread apps/sim/providers/bedrock/request-history.ts Outdated
Comment thread apps/sim/lib/memory/conversation-store.ts Outdated
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 178 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/executor/handlers/agent/memory.ts
Comment thread apps/sim/executor/handlers/agent/memory.ts Outdated
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/executor/handlers/agent/memory.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 178 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Re-trigger cubic

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 180 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Re-trigger cubic

@icecrasher321
icecrasher321 merged commit 4e72b2b into staging Sep 20, 2026
35 checks passed
@icecrasher321
icecrasher321 deleted the codex/durable-agent-memory branch September 20, 2026 00:25

This branch was previously deployed

1 inactive deployment
Preview 7ccce6a0 Deployed Sep 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant