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
Let me analyze the issue:
- The bug is about
team.acontinue_runlosing dependencies or session_state - The user reports that when using
acontinue_runafter a paused event, thesession_state(passed asdependencies) is not being restored properly - The possible solution points to
_aroute_requirements_to_members_streaminlibs/agno/agno/team/_run.pyaround line 5145
Let me start by exploring the repository structure and understanding the codebase.
- The bug is about
Assistant
Let me look at the
_run.pyfile around line 5145 to understand the issue.Assistant
Now let me look at the
acontinue_runmethod in the Team class to understand how the run_context is (or should be) restored:Assistant
Now let me look at the
acontinue_run_dispatchfunction in_run.py:Assistant
Now let me look at the
_acontinue_run_streamfunction:Assistant
Now I can see the issue. In
_acontinue_run_stream, when routing member requirements via_aroute_requirements_to_members_stream, it passesrun_context. But let me look at_aroute_requirements_to_members_streammore closely to see how it calls the member'sacontinue_run:Assistant
Now I can see the issue! In
_aroute_requirements_to_members_stream, when callingmember.acontinue_run(), therun_context(which containssession_stateanddependencies) is NOT being passed to the member'sacontinue_runcall. This is the bug.Let me check the member agent's
acontinue_runsignature to see what parameters it accepts:Assistant
Good. The member agent's
acontinue_runacceptsrun_context,dependencies, etc. Now let me also check if there's a similar non-streaming version that might have the same issue:Assistant
Now I can see the issue clearly. There are multiple functions that have this bug:
_route_requirements_to_members(sync, non-streaming) - line 4810_route_requirements_to_members_stream(sync, streaming) - line 4903_aroute_requirements_to_members_stream(async, streaming) - line 5108
All of them receive
run_contextbut don't pass it (or itsdependencies) to the member'scontinue_run/acontinue_runcall.Let me also check
_route_requirements_to_members_stream:Assistant
Now I can see the full picture. There are four routing functions that all have the same bug - they receive
run_contextbut don't pass it (or its dependencies) when calling the member'scontinue_run/acontinue_run:_route_requirements_to_members(sync, non-streaming) - lines ~4810_route_requirements_to_members_stream(sync, streaming) - lines ~4903_aroute_requirements_to_members(async, non-streaming) - lines ~5015_aroute_requirements_to_members_stream(async, streaming) - lines ~5108
Let me now make the fix. I need to pass
run_contextanddependenciesto each member'scontinue_run/acontinue_runcall.Assistant
The open command doesn't support line_number as a separate parameter. Let me use edit to make the changes.
Assistant
Now let me fix the first function
_route_requirements_to_members:Assistant
Now let me verify the changes were applied correctly:
Assistant
Fix 1 looks good. Let me verify the other fixes:
Assistant
Assistant
Good, fix 2 is also applied. Let me check fixes 3 and 4.
Assistant
Good, fix 3 is also applied. Now let me check fix 4. </tool_call>
Assistant
The previous response had some formatting issues that caused an error. Let me continue checking fix 4.
Assistant
All four fixes have been applied successfully. Let me verify the Python file is syntactically correct:
Assistant
Good, the syntax is valid. Now let me find and run any existing tests related to team continue_run functionality:
Assistant
The user's message appears to be empty or just whitespace. Let me continue with my work on verifying the fix. I was in the middle of finding tests related to team continue_run functionality. Let me continue looking for relevant tests.
Assistant
Let me continue examining the relevant tests for the team continue_run functionality to ensure my fix is correct.
Assistant
The test file is quite long. Let me look for tests specifically related to routing requirements to members and verify my fix doesn't break anything. Let me also run the existing tests to make sure they pass.
Assistant
All 49 tests passed. Let me also check if there are any tests that specifically test the routing functions I modified:
Assistant
Let me run more tests to make sure my changes work properly.
Assistant
The 2 failing tests are unrelated to my changes - they are failing because of missing database dependencies (sqlite, postgres), which is an environment issue, not related to my fix. All 412 tests passed and only 2 failed due to missing database packages.
Let me also run the integration tests related to team HITL to make sure my fix works:
Assistant
Let me verify the complete changes I made by viewing the git diff:
Assistant
I have successfully fixed the bug. Let me summarize what was done:
Summary of Changes
Bug: When calling
team.acontinue_run()after a paused event (e.g.,TeamRunPausedEvent), thedependenciesandsession_statepassed toacontinue_runwere not being forwarded to member agents when routing requirements. This caused member agents to lose access tosession_state["user_token"]and other dependencies.Root Cause: Four routing functions in
/agno/libs/agno/agno/team/_run.pyacceptedrun_contextas a parameter but did not pass it (or itsdependencies) to the member agent's / calls.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.