Untitled conversation
- User
[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
Additional Context
No response
Interface
No new interfaces are introduced.
- Assistant
Now let me check the top imports of
team/_run.py: - Assistant
Now I'll implement the fix. First, add a helper that builds the member's
RunContext: - Assistant
Now update the sync non-streaming variant
_route_requirements_to_members: - Assistant
Now the sync streaming variant
_route_requirements_to_members_stream: - Assistant
Add the merge-back in the sync streaming variant after the loop:
- Assistant
Now the async non-streaming variant
_aroute_requirements_to_members: - Assistant
Now the async streaming variant
_aroute_requirements_to_members_stream(the one the issue points at): - Assistant
Now verify the call sites pass
run_contextto all routing functions: - Assistant
Let me check how session state restoration works without a DB, to understand the full flow:
- Assistant
Now let's find and run existing tests covering team HITL continue_run:
- Assistant
All 49 pass. Let me look at how existing tests mock members, so I can add a regression test:
- Assistant
Now let me check the end of the test file and add a regression test class:
- Assistant
All 55 pass. Run the broader team and agent test suites:
- Assistant
Same 7 failures pre-exist on the clean tree — unrelated to this fix. Now run formatting/validation:
- Assistant
Now the Team overloads:
- Assistant
All remaining failures pre-exist on a clean tree (environment-related: missing db drivers, skills snippet). Final review of the diff:
- Assistant
All checks pass. Summary of the fix:
Problem
When a team run paused for HITL (e.g., tool confirmation on a member agent) and was resumed via
team.acontinue_run(...), the member'scontinue_run/acontinue_runwas invoked with onlyrun_response/run_idandsession_id(libs/agno/agno/team/_run.py). The member then built a freshRunContextwith emptysession_stateand nodependencies, so member tools readingrun_context.session_state["user_token"](ordependencies) gotNone— exactly what the issue reports at_aroute_requirements_to_members_stream.Fix (
libs/agno/agno/team/_run.py)- Added
_build_member_continue_run_context()— builds a memberRunContextcarrying the team run'ssession_state(a copy),dependencies,metadata,user_id, andknowledge_filters, mirroring whatdelegate_task_to_memberpasses on the initial run. - Added
_merge_member_session_state()— merges membersession_statechanges back into the teamrun_contextafter the member finishes, mirroring_process_delegate_task_to_member. - Wired both into all four routing variants:
_route_requirements_to_members,_route_requirements_to_members_stream,_aroute_requirements_to_members,_aroute_requirements_to_members_stream— covering both therun_responsepath and therun_idfallback path. - Added the (already-implemented)
run_contextparameter to thecontinue_run/acontinue_runoverload signatures onAgent(agent.py) andTeam(team.py) so the calls type-check.
Tests
Added
TestMemberContinueRunContext(6 tests) inlibs/agno/tests/unit/team/test_continue_run_requirements.pyverifying: context carries state/dependencies as a copy,Nonepassthrough, merge-back, and that all sync/async/stream routing variants pass a populatedrun_contextto the member and merge member state back.Results:
tests/unit/team/test_continue_run_requirements.py: 55 passedtests/unit/team+tests/unit/agent: 756 passed; the 5 failures (test_team_config,test_agent_config,test_team_skills) also fail on the clean tree — pre-existing environment issues (missing sqlite/postgres db drivers), unrelated to this changeruff format/ruff check: clean;mypyon all modified files: no issues
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →