ISSUE DESCRIPTION [Bug] team.acontinuerun loss dependencies or sessionstate Description…
- User
ISSUE DESCRIPTION
[Bug] team.acontinue_run loss dependencies or session_state
Description
team.acontinue_run loss dependencies or session_state
Steps to Reproduce
pythonrequires_confirmation_tools = [ "group_del", "group_del_stock", ] async def group_del_stock(self, group_id: str, stock_list: list[dict], run_context: RunContext) -> Dict[str, Any]: url = f"{self.live_base_url}/cloud/api/optional/stock/code/del" headers = { "Content-Type": "application/json", "X-Access-Token": run_context.session_state["user_token"] } data = {"targetStockGroupId":group_id,"delVoList":stock_list}example code
pythonsession_id = str(uuid.uuid4()) user_id= '00bgh2' session_state = {"user_token":"Bearer "} asyncio.run(main()) async def main(): async for run_event in stock_team.arun( "将茅台从优质股中删除", stream=True, session_id=session_id, user_id=user_id, session_state=session_state ): from agno.run.team import RunPausedEvent as TeamRunPausedEvent # Use isinstance to check for team's pause event (not the member agent's) if isinstance(run_event, TeamRunPausedEvent): print("Team paused - requires confirmation") for req in run_event.active_requirements: if req.needs_confirmation: print(f" Tool: {req.tool_execution.tool_name}") print(f" Args: {req.tool_execution.tool_args}") req.confirm() # Use apprint_run_response for async streaming response = stock_team.acontinue_run( run_id=run_event.run_id, session_id=run_event.session_id, requirements=run_event.requirements, stream=True, user_id=user_id, dependencies=session_state, ) await pprint.apprint_run_response(response) - Assistant
I’ll trace the async continuation and requirement-routing paths, compare them with synchronous and non-streaming implementations, then reproduce the missing context with the narrowest existing tests or a temporary script. First I’ll inspect the repository structure and relevant symbols.
- Assistant
The relevant implementation is centralized in
team/_run.py. I’ll inspect both routing variants and the continuation setup/call sites to identify whichRunContextfields are dropped and how the non-streaming path preserves them. - Assistant
Both async routing variants call
member.acontinue_runwithout forwardingdependenciesorsession_state; the streaming function merely receives arun_contextfor dynamic member lookup. I’ll now inspect how continuation constructs that context and how analogous sync routing forwards state, so the fix follows established API semantics rather than adding only the reported field ad hoc. - Assistant
The team continuation context correctly stores the caller’s
dependencies, but all four member-routing variants (sync/async × streaming/non-streaming) discard them. Session state is separately restored by_setup_sessioninto the team context, so member continuation should receive both fields just like initial delegation does. I’ll verify the agent continuation signature and setup behavior, then locate focused team HITL tests to build a regression reproduction without modifying tests. - Assistant
The setup confirms persisted team session state is loaded into
run_contextbefore routing. I’ll inspect exact parameter names and existing delegation calls, then implement consistent forwarding in all four routing paths (the reported async stream path plus sibling paths, preventing the same loss under other continuation modes). - Assistant
Agent continuation does not expose a
session_statekeyword, but it does accept a fullrun_context. Passing the team’s same context directly would be unsafe because run IDs and session-state mutation belong to different runs. The established initial delegation passes a deep copy of team session state plus dependencies/metadata/filter options. I’ll inspect agent context initialization precedence to decide whether to construct a member-specificRunContextor forward supported public options only. - Assistant
Agent precedence preserves a supplied context’s session state while explicit dependency arguments override context dependencies. Therefore the robust approach is a fresh member context containing the member run ID, shared session/user IDs, a deep-copied team state, and continuation options. I’ll locate the
RunContextmodel and check whether helpers already encapsulate this copy pattern before editing. - Assistant
No continuation helper exists. I’ll inspect
RunContextfields and then add a small helper near routing that creates an isolated member context. Using a helper avoids eight duplicated argument sets and ensures sync/async paths behave identically. - Assistant
A fresh context is viable, but agent continuation’s deeper session setup may merge/overwrite it. I’ll inspect that setup and the
RunOutput.session_statecaptured at pause. If the paused member output already carries the exact member state, that should be preferred over team state; otherwise use a deep copy of restored team state. - Assistant
The agent merges supplied context state with stored session state and resolves supplied dependencies, so a member-specific context fixes both reported channels. I’ll implement a helper using the paused member run’s ID and a deep copy of team continuation state, forwarding dependencies, metadata, and knowledge filters as well. Then each
continue_runcall will receive it; explicit member run IDs remain correct in fallback flows. - Assistant
The code now supplies isolated contexts in every branch. I’ll run a focused temporary regression harness against the reported async-stream router: it will emulate a paused member, capture
member.acontinue_runarguments, and assert the member receives dependencies and session state, with a distinct context and correct member run ID. I’ll also verify state mutation cannot leak back to the team context. - Assistant
The focused reproduction passes and confirms dependency/state availability plus isolation. Next I’ll inspect the final diff carefully, run the existing team continuation unit suite and relevant HITL tests that do not require external model credentials, and run the repository’s configured formatter/type lint on the changed file if available.
- Assistant
All 55 focused unit tests pass. The diff is limited to production code, and all continuation variants now match. I’ll run Ruff formatting/checks and mypy is likely huge; then run the async member persistence tests, which exercise the actual routing paths with the repository’s mock model/database fixtures.
- Assistant
Ruff check and format both pass via the already installed direct binary;
uvdependency resolution itself failed due an unrelated incompatible extras matrix. The integration test collection then found SQLAlchemy missing. I’ll install only that test dependency into the active environment, ensureuvcreated no tracked artifacts, and rerun the persistence tests. - Assistant
The persistence module is environment-gated and all five tests skipped (likely requiring a configured database), but collection succeeds after installing its base dependency. To increase confidence, I’ll run the complete team unit test directory and inspect how in-memory session loading merges caller state, specifically checking that a supplied member context survives when no DB is configured.
- Assistant
The full team unit suite reached 411 passes and 2 skips before one unrelated skills fixture failed because running from
libs/agnomade its hard-codedcookbook/...path resolve incorrectly; this does not touch continuation code. I’ll directly inspect the merge function, then run the suite’s remaining regression file from repository root and perform final status/diff checks. - Assistant
Final verification is clean: only
libs/agno/agno/team/_run.pyis modified,git diff --checkpasses, session loading confirms caller context has precedence, and all targeted tests pass.Checklist:
- Reported error reproduced: Yes. The focused async-stream routing harness modeled the reported paused member flow; source tracing confirmed the member continuation previously received no context, and the harness now captures the corrected member context.
- Fix confirmed: Yes. The harness verifies
user_tokenin both dependencies and session state, the correct member run ID, and state-copy isolation. - Edge cases considered: Yes. The fix covers sync/async and streaming/non-streaming routing, both retained member output and run-ID fallback paths, optional missing contexts, persisted state merging, and nested/dynamic member lookup.
- Existing tests run: Yes. 55 focused continuation tests passed, 12 session-state regression tests passed, Ruff check/format passed, and the broader team suite reached 411 passes/2 skips before an unrelated cwd-sensitive skills fixture failure. Five DB-gated persistence tests collected but skipped.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.