feat(ai-chat): support resuming delegation sessions via sessionId - #17965
feat(ai-chat): support resuming delegation sessions via sessionId#17965safisa wants to merge 1 commit into
Conversation
The delegation tool result now ends with a '[delegation sessionId: <id>]' line, and the tool accepts an optional sessionId to send follow-up requests into an existing delegated session, so the worker agent keeps its previous conversation context instead of starting from scratch.
sahilempire
left a comment
There was a problem hiding this comment.
This is a nice addition, reusing the session for follow-ups should save a lot of redundant context setup.
Two things I noticed:
The three validation failures all log at error level. Unknown session id and "still processing" both feel like things a model will hit routinely during a normal agentic loop, especially if it's holding a stale id from earlier in the conversation. Since the tool already returns an actionable message the model can recover from, warn or info might keep the logs cleaner for those two. The agentId mismatch feels closer to a real error.
The tool description tells the model that a resumed session grows with every round, which is good guidance, but there doesn't seem to be anything bounding it. If an orchestrator keeps resuming the same worker across a long task, does the delegated session eventually hit the context limit, or does compaction apply to delegated sessions the same way it does to normal ones? Not necessarily something for this PR, just wondering whether it's covered.
Nice coverage on the resume paths, particularly asserting that rootSessionId and parentSessionId stay put.
What it does
Every
delegateToAgentcall currently creates a fresh chat session, so a follow-up request to the same worker (e.g. asking it to fix findings after reviewing its result) re-pays the full context setup — the delegated agent re-reads files and re-derives context it already had.This PR lets the orchestrating agent continue an existing delegation session:
[delegation sessionId: <id>]line.sessionId; when provided, the follow-up request is sent into the existing session, so the delegated agent keeps its previous conversation context.agentIdthat does not match the session's pinned agent.rootSessionId/parentSessionIdstay as set at creation;taskContextIdcan also be passed on resume (deduplicated byaddVariables).Note: the tool result string now carries the trailing session id marker in all cases; adopters post-processing the raw delegation result string may need to account for it.
How to test
npx lerna run test --scope @theia/ai-chat— 8 new specs inagent-delegation-tool.spec.tscover the marker, the resume path (session reuse, event bubbling, id preservation, task context) and the three error cases.[delegation sessionId: <id>]line. Then instruct the agent to send a follow-up to the same delegate passing that sessionId and verify in the delegated session's UI that the new request landed in the same session with prior context, and that the delegate answers with awareness of the earlier exchange.Follow-ups
Breaking changes
Attribution
Review checklist
nlsservice (for details, please see the Internationalization/Localization section in the Coding Guidelines)Reminder for reviewers