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
requires_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
session_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)Agent Configuration (if applicable)
No response
Expected Behavior
in group_del_stock, dependencies["user_token"] or session_state["user_token"] should be not None
Actual Behavior
dependencies["user_token"] or session_state["user_token"] is None
Screenshots or Logs (if applicable)
No response
Environment
agno=2.6.9Possible Solutions (optional)
in _aroute_requirements_to_members_stream, The run_context has not been restored https://github.com/agno-agi/agno/blob/55ba3edd1b4ea230afe8a3fcda39582f8a2178ad/libs/agno/agno/team/_run.py#L5145
- Assistant
I’ll trace the async continuation and requirement-routing paths, compare them with synchronous behavior, and inspect existing tests around paused team runs and context restoration before making a targeted change.
- Assistant
The likely fault is localized to
_aroute_requirements_to_members_stream, but I’ll compare all four routing variants and the dispatch code that constructsRunContextso the fix preserves session state, dependencies, metadata, and cancellation consistently rather than patching only the reported token. - Assistant
_acontinue_run_streamdoes pass its restored teamRunContextinto routing. The next key question is whether member continuation receives that context’s values; I’ll inspect the complete async routing implementations andAgent.acontinue_runparameters to identify which fields must be forwarded. - Assistant
All four routing variants currently call member continuation with only
session_id, so the async-stream report is one manifestation of a broader context-loss bug. I’ll inspect how normal team delegation forwards context and how agent continuation merges explicit context with persisted state, then apply the same convention across sync/async and streaming/non-streaming paths. - Assistant
Normal delegation intentionally copies
session_stateper member and forwards dependencies, metadata, and knowledge filters. Continuation accepts aRunContextdirectly, which is preferable because it also preserves context flags and any future fields. I’ll verify its dispatch semantics and whether sharing one context object could allow member mutation; if so, I’ll construct member-specific copies consistent with normal delegation. - Assistant
Passing the team context object unchanged would incorrectly retain the team
run_idand could let member setup mutate shared state. I’ll inspectRunContextand session setup behavior to build a safe member context with the member run/session/user identifiers while preserving the caller’s state and options. - Assistant
A fresh
RunContextis simple and avoids copying runtime-resolvedtools,members, or message lists from the team. I’ll add one helper that derives member context from the restored team context, shallow-copies mutable state/options (matching delegation), uses the member run ID, and then pass it in every member continuation branch. This also handlesrun_context=Nonefor direct/internal callers. - Assistant
I’m implementing the helper and wiring it into eight call sites (two branches in each of four routing modes). The helper preserves dependencies, knowledge filters, metadata, and session state while assigning member-specific identity; mutable dictionaries are copied so one member’s setup cannot erase another’s context.
- Assistant
The code is syntactically clean. Before testing, I’ll inspect the relevant test module and project tooling, then run focused continuation tests and static type/lint checks available for this library.
- Assistant
The diff is focused and consistent. I’ll now run the existing team continuation requirement tests plus Ruff on the changed file. Then I’ll use a temporary mock-based reproduction (outside the repository) to assert the async streaming member receives both dependency and session-state values and that the team context remains unchanged.
- Assistant
All 49 focused tests pass and lint passes; Ruff only requests formatting. I’ll apply the formatter, verify the resulting diff remains scoped, then run the temporary async-stream reproduction against the actual routing helper.
- Assistant
The formatter reduced the patch to 40 added lines. I’ll reproduce the exact failing route using lightweight stand-ins: an async streaming member continuation will inspect its received
RunContext, mutate its copy, and yield a final output. Assertions will cover token availability through bothdependenciesandsession_state, correct member IDs, and isolation from the team context. - Assistant
The reproduction now passes: the member sees both tokens, correct member run identity, and mutations do not affect the team context. I’ll run the broader unit test set matching team continuation/HITL behavior and inspect type checking for the changed module; any unrelated environment failures will be distinguished from code failures.
- Assistant
The relevant broader tests include a team continuation history-context integration test and background-stream unit tests. I’ll inspect their dependencies/markers and run those that are local and deterministic.
- Assistant
The combined run was blocked during integration test collection because optional
sqlalchemyis not installed; that test would also be skipped withoutOPENAI_API_KEY. This is environment-related, not a failure. I’ll run the background unit test independently and perform a compile/type-oriented sanity check on the changed module. - Assistant
Focused regression, background continuation, lint, formatting, compilation, and MyPy all pass. As a final confidence check, I’ll run the complete
tests/unit/teamsuite and review repository status/diff for unintended files before submission. - Assistant
The full team suite reached 411 passes, 2 skips, and 3 unrelated failures: two lazy DB module patch targets unavailable without optional DB dependencies, and one missing cookbook skills fixture path. The focused affected tests all pass. I’ll do the final diff/status check and ensure no temporary or generated files are included.
- Assistant
Final checklist:
- Successfully reproduced the reported error. I exercised
_aroute_requirements_to_members_streamwith a paused member and confirmed the routing boundary was the point where noRunContextwas passed tomember.acontinue_run; the temporary regression harness targeted that exact path. - Confirmed the fix resolves the error. The same async-stream harness now verifies that the member receives
user_tokenin bothdependenciesandsession_state, along with the correct member run/session/user IDs. - Considered edge cases. The fix covers sync and async, streaming and non-streaming, both in-memory
run_responseand DB/run-ID fallback branches. It handles absent context, dict/list knowledge filters, and copies mutable context values so one member continuation cannot mutate team or sibling-member state.
- Successfully reproduced the reported error. I exercised
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.