Skip to content

feat(ai-chat): support resuming delegation sessions via sessionId - #17965

Open
safisa wants to merge 1 commit into
eclipse-theia:masterfrom
safisa:delegation-session-resume
Open

feat(ai-chat): support resuming delegation sessions via sessionId#17965
safisa wants to merge 1 commit into
eclipse-theia:masterfrom
safisa:delegation-session-resume

Conversation

@safisa

@safisa safisa commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What it does

Every delegateToAgent call 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:

  • Each delegation result now ends with a [delegation sessionId: <id>] line.
  • The tool accepts an optional sessionId; when provided, the follow-up request is sent into the existing session, so the delegated agent keeps its previous conversation context.
  • The resume path validates the session and returns actionable errors instead of silently falling back to a fresh session: unknown/deleted session id, a request still in progress, or an agentId that does not match the session's pinned agent.
  • Parent/child event bubbling is re-established for each follow-up; rootSessionId/parentSessionId stay as set at creation; taskContextId can also be passed on resume (deduplicated by addVariables).

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 in agent-delegation-tool.spec.ts cover the marker, the resume path (session reuse, event bubbling, id preservation, task context) and the three error cases.
  • Manually: in a chat with an agent that delegates (e.g. via the orchestrator), observe that a delegation result ends with the [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

  • Orchestrator prompt templates could explicitly encourage the resume flow for verify→fix loops; currently the behavior is discoverable through the tool description only.

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

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.
@github-project-automation github-project-automation Bot moved this to Waiting on reviewers in PR Backlog Aug 27, 2026

@sahilempire sahilempire left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on reviewers

Development

Successfully merging this pull request may close these issues.

2 participants