Repository navigation
ADK: sub-agent transcripts live and die with their conversation - #321
Merged
Merged
Conversation
Each sub-agent run's transcript is a child session of its conversation, under the child app. ServiceSessions.delete, the manager's delete_session and a SessionReader's alike, now deletes them after the conversation's own delete (delete_children: the child app's sessions <conversation>/<instance> of that user, events and all), whatever that found, so a conversation already gone leaves none behind; its answer is still about the conversation. Covered on the memory store (where /new drops the conversation it leaves), on sqlite and through a reader.
AgentRuns.number_from(conversation, counts) raises each agent's instance count in that conversation to counts[agent], so run_for's next instance is numbered past the instances a conversation's store already keeps. A count is never lowered, and an open run keeps its name.
…e keeps Delegations takes stored=, a callable that says how many instances of each type a conversation's store keeps, and asks it once per conversation, before the conversation's first run is named; parallel first runs wait for the one ask. A store that cannot be read is logged and asked again at the next run, as after a cancel. The manager passes its _stored_instances hook, which keeps none on the base: a backend that stores sub-agent transcripts says what it keeps.
Instances are numbered per manager, so a new one (a restart, a switch of backend or store) numbered researcher-1 again and replaced its stored child session. The manager's _stored_instances reads the highest instance number of each type from the conversation's child session ids (stored_instances), so the next run is past them, and _child_session no longer deletes a session it meets: ADK refuses to make one that exists, and that run fails with the store's words, its transcript kept. A model switch between turns rebuilds the child runners and keeps the transcripts, the records and the numbering.
On both backends the manager's list_sessions, session_info, session_exists and recent_messages show the conversation alone after two delegations; on ADK neither a reader, nor the CLI's look at every backend's conversations, nor the app's list or --continue's newest conversation is ever a child session.
The CHANGELOG says deleting a conversation deletes its sub-agents' child sessions on ADK, and that a new manager numbers a conversation's instances past the stored ones (and lists number_from among agent_runs' methods); CLAUDE.md's structure lines and the Session identity paragraph describe delete_children, stored_instances, _stored_instances and Delegations' stored=; the README's child-session sentence says they are deleted with the conversation.
storing() answered without giving the loop a turn, so parallel first runs never met while one asked and the test of the one ask passed without the lock too. Each ask now yields before its answer is given, as a store's read does; without the lock the parallel first runs ask twice and one is numbered from 1.
…ning test_their_events_go_with_them now counts the child session's event before delete_children, so it cannot pass on a store that never held one. A store whose stored instances cannot be read is warned of in the log (subagent_instances_unread, with the error; its traceback at debug), and the run still completes: a test now says so.
…turn Delegations remembered for the manager's whole life that it had read a conversation's stored instances. A conversation the CLI lets go can be taken by another process, which delegates and gives it back; the first manager then numbered from its stale count, and each instance the other process had made cost one failed run (Session with id s/researcher-2 already exists). The mark is now the turn's span (workflow/sessions.py::current_turn_scope, new): each turn's first run asks the store again, its parallel first runs still wait for the one ask, and an ask that failed or was stopped is asked again at the next run. No other process holds the conversation during a turn (ConversationLock), and number_from never lowers a count, so asking again is safe; a delegating turn costs one listing of the child sessions. With no turn's span open, every run asks.
The CHANGELOG's child-session bullet and CLAUDE.md's agents/ and workflow/sessions.py structure lines and Session identity paragraph say that each turn's first run asks the store again, since another process may have run the conversation between two turns, and name current_turn_scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADK keeps each sub-agent run's transcript in a child session of its conversation (app
<app>--agents, session<conversation>/<instance>). With this change those sessions live and die with their conversation.adk/sessions.py::delete_childrendeletes a conversation's child sessions. It matches ids of the form<conversation>/<instance>with no further/, so no other conversation's children are touched.ServiceSessions.deletecalls it after the conversation's own delete, whatever that found; the answer stays about the conversation. This covers the manager, aSessionReader(/sessions --deleteon another backend), and the memory store (/newdrops the conversation it leaves). A reader that opens a database without ADK's tables still writes nothing.AgentRuns.number_from(conversation, counts)raises a conversation's counts and never lowers one.BaseWorkflowManager._stored_instancesis{}on the base; on ADK it is the highest stored number of each type.Delegations(stored=)asks once per conversation per turn, under a lock, and again after a failed ask. So a reopened conversation, a restart, a model switch, or a conversation another process used in between never reuses a stored child session. A clash fails that run and keeps the stored transcript.--continue's newest conversation;recent_messages.Tests: new tests written first and seen failing (sqlite and memory stores, a reader, two managers on one store taking turns, a model switch, a restart); the full offline suite passes in the worktree except
TestChildImportOrigin, which fails the same way on develop under the worktree wrapper.