Skip to content

Sub-agents: records name every transcript; bounded ADK records; Deep Agents messages as deltas - #343

Merged
shoom1 merged 9 commits into
developfrom
fix/subagent-storage
Nov 26, 2026
Merged

shoom1 merged 9 commits into
developfrom
fix/subagent-storage

Conversation

@shoom1

@shoom1 shoom1 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Sub-agent storage and Deep Agents checkpoints now grow with what a conversation holds:

  • The conversation's records name every sub-agent transcript.
  • Numbering and a delete read those records alone, with no scan of the checkpointer's instance threads and no listing of every ADK session of the user.
  • ADK's records session stops growing without bound.
  • A Deep Agents conversation's checkpoints grow with its length, not its square.

There is no public API change.

A run's transcript is made only once its start is stored (both backends)

  • A run that is about to make its transcript first waits for its start record to be written:
    • a first run;
    • a follow-up whose transcript is gone, so its ADK child session or its Deep Agents instance thread must be made anew.
  • A store that failed that write fails the run before any transcript exists, with RECORDS_NOT_STORED: "The conversation's sub-agent records could not be stored, so this run was not started." Its slot is given back.
  • A follow-up whose transcript exists does not wait.
  • A conversation whose stored records are another version's starts runs without waiting, as before.

Numbering and a delete read the records

  • The records now name every transcript, so they alone are read:
    • for numbering (ADK child sessions, Deep Agents instance threads);
    • for a conversation's delete.
  • A conversation without records has no transcripts, so nothing more is read.
  • The store is still scanned (Deep Agents) or listed (ADK) only for records that cannot be read, another version's. In that case nothing else names what the store keeps.

Records are written at a run's start and end

  • A run's working statuses are no longer written: a restart reads any working status as interrupted, so the stored one was never used.
  • On a busy conversation this removes most writes.

ADK: the records session is rewritten past a bound

  • After 100 writes appended to one records session, the next write rewrites the whole records into a second session (<conversation>/), then deletes the first. The two alternate by a generation number.
  • A crash between the rewrite and the delete leaves both. The higher generation is read, and the next rewrite removes the older.
  • A conversation's delete removes both.
  • A conversation id too long for a second id keeps appending to its one session.

Deep Agents: messages stored as deltas

  • AgentCliState now builds on Deep Agents' DeepAgentState, whose messages is LangGraph's DeltaChannel. Each checkpoint stores its new messages, with a full copy every 50 updates.
  • The session hooks read messages through a one-node graph of that state compiled over the saver, which puts them together. This covers listing, opening, recent_messages, the session index's backfill and a SessionReader, all reading through the saver.
  • Measured: 40 turns of 1,000-character prompts and answers stored 8.2 MB before and 0.33 MB now, on both the env's and CI's library versions.
  • Threads stored before, with the whole message list per checkpoint, read as before.

Tests: written first and seen failing (each RED is in the review record).

  • The shared contract suite covers, on ADK and Deep Agents:
    • a first run whose start cannot be stored, including two in parallel;
    • a follow-up that makes its transcript while the store fails, and once it recovers;
    • records that do not read, numbered and deleted through the store.
  • Unit tests cover:
    • the start check;
    • numbering and delete without records and with records naming no instance;
    • ADK's rewrite: events bounded, the rewrite's contents, a crash between rewrite and delete, a delete after a crash, a too-long id, and the rewrite under the loop guard;
    • Deep Agents deltas: the stored size below 1 MB for 40 turns, the hooks, a cancelled turn then a new one, the backfill, a reader without a manager, and a thread stored with plain values.
  • Reviewed, with two rounds of review fixes. The first added the check for a follow-up that makes its transcript; the second made the cancelled-turn test check every message.

The full offline suite passes in the worktree (11127 passed), except TestChildImportOrigin::test_child_resolves_the_checkout, which fails the same way on develop under the worktree wrapper. On CI's library versions (deepagents 0.7.41, langgraph 1.2.24, google-adk 2.15.0), the contract suites, tests/workflow/deepagents, the ADK child-session tests and every touched file pass.

A first run's transcript (ADK's child session, Deep Agents' instance thread) is now made only after its start is in the conversation's stored records, so the records name every transcript the conversation keeps. A store that failed that write fails the run with RECORDS_NOT_STORED, before any transcript exists; a follow-up, whose instance is named already, never checks, and a conversation whose stored records do not read starts runs without waiting.
A first run's transcript is made only once its start is in the records, so the records name every transcript a conversation keeps. Numbering and a delete read them alone: ADK's listing of the user's child sessions and Deep Agents' scan of the instance threads remain only for records that do not read (another version's), and a conversation without records has no transcripts.
A run's working statuses (queued, running, input_required) still change its record in memory but no longer tell the records writer: a restart reads any working status as interrupted, so the stored one is never used, and each one cost a write. A run's start, its end, an instance's status change and interrupt_open are written.
A conversation's records session gained an event per write for the life of the conversation. Past RECORDS_REWRITE_AFTER (100) writes the next one now writes the records whole into the other of two sessions (the conversation's id and that plus a slash), one generation on, and deletes the first, so the events stay bounded. A crash between the rewrite and the delete leaves both, a read takes the newer, and the next rewrite removes the older; a delete removes both.
AgentCliState now subclasses Deep Agents' DeepAgentState, whose messages are a delta channel: a checkpoint stores the messages its step added and a full copy every 50 updates, so a conversation's checkpoints grow with its length, not its square. The session hooks read messages through a one-node graph of that state compiled over the saver, which puts them together; a conversation stored with whole copies reads and continues as before.
… too

An instance whose first run failed RECORDS_NOT_STORED is left idle and can be followed up. That follow-up made its transcript with no check, so no records named it: a conversation's delete left it behind and a restart's next first run of the type clashed with it. A run now waits for its start to be stored whenever it is about to make its transcript, a first run or a follow-up whose transcript is gone; a follow-up whose transcript exists makes none and does not check.
The docstring and comment lines this PR added that ran over 88 columns are wrapped,
with a word changed in three of them to keep the sentence whole.
@shoom1
shoom1 merged commit a59fda2 into develop Nov 26, 2026
6 checks passed
@shoom1
shoom1 deleted the fix/subagent-storage branch November 26, 2026 01:44
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