Repository navigation
fix(sequentialagent): recurse task_completed injection and rebind Agent in Run and RunLive - #1510
Conversation
…nt in Run and RunLive Fixes google#1491 For a nested sequential agent like seq(llmA, seq(llmB)), RunLive previously only inspected the immediate sub-agents of ctx.Agent() without recursing into nested sub-agents, leaving the inner LLM agent without the task_completed tool or instruction suffix needed to signal completion. Additionally, invoking the sub-agent's Run and RunLive passed ctx directly without rebinding Agent, causing nested sequential agents to read the outer agent's sub-agent list instead of their own. - Recurse into sub-agents during task_completed injection when subAgent has sub-agents. - Introduce subInvocationContext to rebind Agent to subAgent during sub-agent Run and RunLive invocations. - Add regression unit tests TestSequentialAgent_RunLive_NestedSequentialInjection and TestSequentialAgent_RunLive_NestedSequentialOrchestration verifying injection and event routing for nested pipelines. Signed-off-by: SOUMYAJIT GHOSH <[email protected]>
|
Summary for the review I just submitted — the body did not come through with it. Changes requested. The nested- Breaking changes: 2 (both behavioral, both in the inline comments) — injection now permanently rewrites the tools and system instruction of LLM agents nested under a non-live composite, and I A/B'd both against
Applying just the two inline suggestions clears both, keeps every test in this PR green, and still passes the nested repro from #1491. |
…nner gating, and test hardening - Revert Run to pass ctx directly to sub-agents, preserving commonContext fields (Path, RunID, SubScheduler) without zeroing. - Gate task_completed injection recursion in RunLive on liveRunner interface with a visited set to avoid mutating sub-agents under non-live composites. - Rebind agent in RunLive using ctx.WithICDelta rather than subInvocationContext, eliminating subInvocationContext entirely. - Add WithICDelta to mockInvocationContext in tests. - Change non-fatal assertion to t.Fatalf on author check and guard channel receives with select on ctx.Done(). - Add TestSequentialAgent_RunLive_NonLiveCompositeNotMutated verifying non-live composite children are not mutated. Signed-off-by: Soumyajit Ghosh <[email protected]>
|
Thank you @wojtas000 for the thorough and high-signal review! All review feedback items have been addressed in commit
All package unit tests and the full repository test suite ( |
wojtas000
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the quick and complete turnaround on this.
I re-checked the two breaking changes on this head: seq(loop(llmB)) now leaves llmB untouched, and a sub-agent under seq.Run() keeps its Path() and RunID(). NonLiveCompositeNotMutated fails against the previous head and passes here, so it pins the gate rather than just describing it. The new tests also fail on base in 0.086s now, instead of running into the package timeout.
One aside, nothing to change: the select guards you added use t.Context(), which only cancels at test cleanup, so they cannot fire while a receive is actually stuck. The t.Fatalf above each one is what prevents the hang — which is why the base run fails fast.
…nt in Run and RunLive (google#1510) * fix(sequentialagent): recurse task_completed injection and rebind Agent in Run and RunLive Fixes google#1491 For a nested sequential agent like seq(llmA, seq(llmB)), RunLive previously only inspected the immediate sub-agents of ctx.Agent() without recursing into nested sub-agents, leaving the inner LLM agent without the task_completed tool or instruction suffix needed to signal completion. Additionally, invoking the sub-agent's Run and RunLive passed ctx directly without rebinding Agent, causing nested sequential agents to read the outer agent's sub-agent list instead of their own. - Recurse into sub-agents during task_completed injection when subAgent has sub-agents. - Introduce subInvocationContext to rebind Agent to subAgent during sub-agent Run and RunLive invocations. - Add regression unit tests TestSequentialAgent_RunLive_NestedSequentialInjection and TestSequentialAgent_RunLive_NestedSequentialOrchestration verifying injection and event routing for nested pipelines. Signed-off-by: SOUMYAJIT GHOSH <[email protected]> * fix(sequentialagent): address review feedback on Run context, live runner gating, and test hardening - Revert Run to pass ctx directly to sub-agents, preserving commonContext fields (Path, RunID, SubScheduler) without zeroing. - Gate task_completed injection recursion in RunLive on liveRunner interface with a visited set to avoid mutating sub-agents under non-live composites. - Rebind agent in RunLive using ctx.WithICDelta rather than subInvocationContext, eliminating subInvocationContext entirely. - Add WithICDelta to mockInvocationContext in tests. - Change non-fatal assertion to t.Fatalf on author check and guard channel receives with select on ctx.Done(). - Add TestSequentialAgent_RunLive_NonLiveCompositeNotMutated verifying non-live composite children are not mutated. Signed-off-by: Soumyajit Ghosh <[email protected]> --------- Signed-off-by: SOUMYAJIT GHOSH <[email protected]> Signed-off-by: Soumyajit Ghosh <[email protected]> Co-authored-by: SOUMYAJIT GHOSH <[email protected]> Co-authored-by: Jan Wojtas <[email protected]>
…nt in Run and RunLive (google#1510) * fix(sequentialagent): recurse task_completed injection and rebind Agent in Run and RunLive Fixes google#1491 For a nested sequential agent like seq(llmA, seq(llmB)), RunLive previously only inspected the immediate sub-agents of ctx.Agent() without recursing into nested sub-agents, leaving the inner LLM agent without the task_completed tool or instruction suffix needed to signal completion. Additionally, invoking the sub-agent's Run and RunLive passed ctx directly without rebinding Agent, causing nested sequential agents to read the outer agent's sub-agent list instead of their own. - Recurse into sub-agents during task_completed injection when subAgent has sub-agents. - Introduce subInvocationContext to rebind Agent to subAgent during sub-agent Run and RunLive invocations. - Add regression unit tests TestSequentialAgent_RunLive_NestedSequentialInjection and TestSequentialAgent_RunLive_NestedSequentialOrchestration verifying injection and event routing for nested pipelines. Signed-off-by: SOUMYAJIT GHOSH <[email protected]> * fix(sequentialagent): address review feedback on Run context, live runner gating, and test hardening - Revert Run to pass ctx directly to sub-agents, preserving commonContext fields (Path, RunID, SubScheduler) without zeroing. - Gate task_completed injection recursion in RunLive on liveRunner interface with a visited set to avoid mutating sub-agents under non-live composites. - Rebind agent in RunLive using ctx.WithICDelta rather than subInvocationContext, eliminating subInvocationContext entirely. - Add WithICDelta to mockInvocationContext in tests. - Change non-fatal assertion to t.Fatalf on author check and guard channel receives with select on ctx.Done(). - Add TestSequentialAgent_RunLive_NonLiveCompositeNotMutated verifying non-live composite children are not mutated. Signed-off-by: Soumyajit Ghosh <[email protected]> --------- Signed-off-by: SOUMYAJIT GHOSH <[email protected]> Signed-off-by: Soumyajit Ghosh <[email protected]> Co-authored-by: SOUMYAJIT GHOSH <[email protected]> Co-authored-by: Jan Wojtas <[email protected]>
Fixes #1491
Problem
For a nested sequential agent pipeline like
seq(llmA, seq(llmB)):SequentialAgent.RunLivepreviously only inspected immediate sub-agents ofctx.Agent()when injectingtask_completedand the exit instruction suffix. Because the inner sequential agent is not anllminternal.Agent, its nested LLM sub-agents were never injected, leavingllmBwith no mechanism to signal completion during a live run.RunLiveandRun, the existingctxwas passed without rebindingAgent. Consequently, when the inner sequential agent executed, callingctx.Agent().SubAgents()read the outer pipeline's sub-agents rather than its own, causing duplicate execution of outer agents or recursive loops.Solution
injectSubAgentsrecurses intosubAgent.SubAgents()so all nested LLM agents receive thetask_completedtool and instruction suffix prior to live session execution.subInvocationContextwrappingInvocationContextto overrideAgent()with the specificsubAgentbeing invoked during bothRunandRunLive.TestSequentialAgent_RunLive_NestedSequentialInjectionverifying that nested LLM agents receivetask_completedtool injection.TestSequentialAgent_RunLive_NestedSequentialOrchestrationverifying event propagation and live request routing through nested sequential pipelines.Verification
go test -v -race ./agent/workflowagents/sequentialagent/...passed cleanly with zero data races.gofmtandgo vetpassed with 0 warnings.