fix(go-adk): add per-call session isolation for Agent tools#2153
Open
yashrajshuklaaa wants to merge 1 commit into
Open
fix(go-adk): add per-call session isolation for Agent tools#2153yashrajshuklaaa wants to merge 1 commit into
yashrajshuklaaa wants to merge 1 commit into
Conversation
Signed-off-by: Yashraj Shukla <shuklayashraj68@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in isolateSessions flag for Agent-type tools so each sub-agent invocation can use a fresh A2A context_id (and therefore a distinct sub-agent session), fixing the “parallel fan-out collapses into one shared worker session” bug described in #2137.
Changes:
- Introduces
Tool.IsolateSessions(CRD + CEL validation) and threads it through translation intoRemoteAgentConfig.IsolateSessions. - Updates the Go remote A2A tool to mint per-call
context_idwhen isolation is enabled and to avoid pre-stamping a single subagent session id for isolated tools. - Adds translation fixture coverage and a unit test for the new context-id selection logic; adds Python schema parity field.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/packages/kagent-adk/src/kagent/adk/types.py | Adds isolate_sessions field for config/schema parity (no runtime behavior change in Python). |
| helm/kagent-crds/templates/kagent.dev_sandboxagents.yaml | Regenerates CRD template to include isolateSessions and CEL rule. |
| helm/kagent-crds/templates/kagent.dev_agents.yaml | Regenerates CRD template to include isolateSessions and CEL rule. |
| go/core/internal/controller/translator/agent/testdata/outputs/agent_with_isolated_session_tool.json | Adds golden output asserting isolate_sessions: true is emitted into config.json. |
| go/core/internal/controller/translator/agent/testdata/inputs/agent_with_isolated_session_tool.yaml | Adds translator input fixture exercising isolateSessions: true. |
| go/core/internal/controller/translator/agent/compiler.go | Threads tool.IsolateSessions into RemoteAgentConfig.IsolateSessions. |
| go/api/v1alpha2/zz_generated.deepcopy.go | Regenerates deepcopy to include Tool.IsolateSessions. |
| go/api/v1alpha2/agent_types.go | Adds Tool.IsolateSessions *bool and CEL validation restricting it to Agent tools. |
| go/api/config/crd/bases/kagent.dev_sandboxagents.yaml | Regenerates CRD base to include isolateSessions schema + validation. |
| go/api/config/crd/bases/kagent.dev_agents.yaml | Regenerates CRD base to include isolateSessions schema + validation. |
| go/api/adk/types.go | Adds RemoteAgentConfig.IsolateSessions (isolate_sessions) to runtime config. |
| go/adk/pkg/tools/remote_a2a_tool.go | Implements per-call context id minting for isolated tools and reports back per-call session id. |
| go/adk/pkg/tools/remote_a2a_tool_test.go | Adds unit test for nextContextID() isolation semantics. |
| go/adk/pkg/agent/agent.go | Passes isolation flag into tool creation and skips pre-stamp map entry when isolated. |
Files not reviewed (1)
- go/api/v1alpha2/zz_generated.deepcopy.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+372
to
376
| // session that actually ran the call — critical when isolateSessions is true | ||
| // and every call has a different id. | ||
| func (s *remoteA2AState) processResult(ctx adkagent.ToolContext, contextID string, result a2atype.SendMessageResult) (map[string]any, error) { | ||
| switch r := result.(type) { | ||
| case *a2atype.Message: |
Author
|
PTAL @EItanya |
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.
Summary
Fixes #2137
The bug : every call a parent agent makes to a sub-agent (Agent tool) reuses the same A2A context_id since it's minted once when the tool is built. worker just uses that context_id as its session id directly ( executor.go: sessionID := reqCtx.ContextID ) so if a coordinator fires off N parallel calls to the same sub-agent in one turn , they all pile into a single shared session instead of getting their own.
Fix is an opt-in IsolateSessions flag on Agent-type tools :
Default behavior (flag unset/false) doesn't change
one context_id for the tool's whole lifetime so stateful sub-agents keep their session continuity. with the flag on we mint a fresh context_id on every call so each invocation is isolated.
Doesn't touch the x-kagent-root-context-id header stuff. that's still what carries cross-turn continuity and it stays stable either way.
What changed
agent_types.go: addedTool.IsolateSessions *boolplus a CEL rule so it can only be set whentype: Agentadk/types.go:RemoteAgentConfig.IsolateSessions boolcompiler.go: passes the flag through intoRemoteAgentConfigagent.go: forwards the flag toNewKAgentRemoteA2ATool. also skips adding an entry tosubagentSessionIDswhen isolated since there's no single session id to pre-stamp function_call parts with anymoreremote_a2a_tool.go: addedisolateSessionsplus a smallnextContextID()helper that either returns the stable id or mints a new one. This gets reported back assubagent_session_idtypes.py: addedisolate_sessionsfor schema parity only, it doesn't do anything on that side yet (matches what the issue scoped out)make controller-manifestsagent_with_isolated_session_tool) to check it flows through the whole translation pipelineAbout the UI
Isolated tools don't have one fixed session id, so the executor can't pre-populate the stamp map for them at startup. Instead the UI grabs the session id per call from
subagent_session_idin the function_response.AgentCallDisplayalready reads that field, so nothing new needed there.Not doing in this PR
max-concurrency.md)Tests
Ran
go test ./adk/pkg/tools/... ./adk/pkg/agent/... ./api/...and the golden translator tests. Everything passes.Confirmed
isolate_sessions: trueshows up correctly in the generatedconfig.jsonfor the new fixture.One small thing I noticed
In
handleResume,processResultnow setssubagent_session_idfrom the contextID I pass in, but there's older code right after it that sets the same key again with a fallback tolastContextID. Not wrong, just a bit redundant now since it writes the same value twice in the normal case. Left it as is since it's harmless but flagging it in case someone wants it cleaned up.