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
Let me start by understanding the issue. The problem is about
team.acontinue_runlosingdependenciesorsession_state. The user reports that when usingacontinue_runafter a paused event (for confirmation), therun_context.session_stateordependenciespassed toacontinue_runare not available in the tool functions.The issue points to a specific file and line:
libs/agno/agno/team/_run.pyaround line 5145, in_aroute_requirements_to_members_stream, whererun_contexthas not been restored.Let me explore the repository structure first.
Assistant
Let me look at the relevant file mentioned in the issue
Assistant
Let me look at the area around line 5145 in that file:
Assistant
Let me look at the function
_aroute_requirements_to_members_streamaround line 5145.Assistant
Let me try the open command differently.
Assistant
Now I can see the function. Let me understand the issue better. The
_aroute_requirements_to_members_streamfunction callsmember.acontinue_runbut doesn't passrun_contextto it. Let me look at howarunsets up the run_context and howacontinue_runusesAssistant
Let me look at the
acontinue_runmethod and see how it passes run_context to the member agents:Assistant
Let me look at
acontinue_runin team.pyAssistant
The open command seems to require a different syntax. Let me try with the open command as described in the system prompt.
Assistant
Let me look at
acontinue_run_dispatchto see how it processes the runAssistant
Now let me look at
_acontinue_run_streamand understand how it resolves session_state:Assistant
Let me look at
_acontinue_run_streamstarting at line 695Assistant
Now I can see the issue! In
_aroute_requirements_to_members_stream, themember.acontinue_runcalls don't passrun_context. Let me verify by looking at how the non-continue case handles this:Assistant
Let me compare with the non-streaming version and also look at how
adelegate_task_to_memberpasses run_context:Assistant
Let me look at how
adelegate_task_to_memberpassesrun_contextto members:Now let me look at how member delegation handlesrun_contextproperlyAssistant
Let me search for "def adelegate_task_to_member" or "def _adelegate_task_to_member"
Assistant
Let me search more broadly:
Assistant
Let me look at how delegation calls members in the main run flow
Assistant
Let me look at how the team arun function calls member agents with run_c
Assistant
Let me look at the delegation pattern more carefully. Let me search for where member agents get their run_context
Assistant
Let me search for the delegation tool to see how members get called initially
Assistant
Let me look at the delegate_task_to_member function to understand the full flow
Assistant
Now let me check the agent's
acontinue_runmethod to see if it acceptsrun_context,dependencies, orsession_state:Assistant
Now let me check
acontinue_run_dispatchfor agents to confirm it uses run_context:Assistant
Now I have a clear understanding of the issue. Let me verify the exact lines where the fix is needed. The issue is in two functions:
_aroute_requirements_to_members_stream(streaming path)_aroute_requirements_to_members(non-streaming path)
Both call
member.acontinue_runwithout passingrun_context, which means the member agent creates a new RunContext without the originaldependenciesandsession_state.Let me look at the exact lines to edit:
Assistant
Now let me look at the non-streaming version too:
Assistant
Let me also check if there's a sync version that might need fixing:
Assistant
Let me also check the sync versions for the same issue:
Assistant
Let me check the sync streaming version too:
Assistant
Now I have a complete picture. All four routing functions have the same issue - they don't pass
run_contextto the member'scontinue_run/acontinue_runcalls. Let me also verify thatcontinue_runacceptsrun_context:Assistant
Now I have full understanding. Let me fix all four functions. I'll start with the async streaming version (the one mentioned in the issue), then fix the other three as well.
Let me first open the file and make the changes
Assistant
Now let me fix all the issues. Starting with
_aroute_requirements_to_members_stream- first call (withrun_responseAssistant
Let me try using the replace command instead:
Assistant
Let me use sed directly instead:
Assistant
Now fix the async non-streaming version
_aroute_requirements_to_members:Assistant
Now fix the sync streaming version `_route_requirements_to_members_stream
Assistant
Now fix the sync non-streaming version `_route_requirements_to
Assistant
All four fixes are done. Let me verify the changes look correct:
Assistant
The diff looks correct. Let me also verify that the agent's
acontinue_run_dispatchproperly uses the passedrun_context. Let me check `opts.apply_to_contextAssistant
Let me search for
apply_to_contextmore broadly.Assistant
Let me check the agent's
apply_to_contextto see if it would override the provided values:Assistant
Let me check how
apply_to_contextis called inacontinue_run_dispatch:Assistant
Let me also check how
_asetup_sessionupdatesrun_context:Assistant
Let me also verify if there are any other calls to
member.acontinue_runormember.continue_runin the team context that might have the same issue:Assistant
All 8 calls are now covered. Let me verify the corrected lines again:
Assistant
All changes look correct. Now let me see if there are any tests to run:
Assistant
Let me look at the team HITL tests to see if they test
acontinue_run:Assistant
Let me search for team-specific HITL tests:
Assistant
Let me look at the unit tests for team continue_run:
Assistant
Let me try running the unit tests related to team continue_run:
Assistant
All unit tests pass. Let me also run the other team unit test:
Assistant
All tests pass. Let me now think about edge cases and verify completeness.
Let me also check that the sync functions'
run_contextparameter is properly available (it should be, since all four functions receive it as a paramAssistant
Let me verify the function signatures to confirm all four have
run_contextas a parameter:Assistant
All four functions have
run_contextas a parameter and all four now properly forward it. Let me confirm no other calls are missing:Assistant
Let me verify all eight calls now have
run_context=run_contextadded:Assistant
All eight calls now pass
run_context=run_context. The fix is complete and consistent across all four functions (sync/async, streaming/non-streaming).Now let me run the broader unit tests to make sure nothing is broken:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.