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 analyze this issue. The problem is that when
team.acontinue_runis called, thedependenciesorsession_stateare not being properly passed through to the agent's context. Specifically, theuser_tokenthat was passed insession_stateis not available in therun_context.session_statewhengroup_del_stockis called.The issue description points to a possible location:
_aroute_requirements_to_members_streaminagno/team/_run.pyaround line 5145.Let me first explore the repository structure and understand the codebase.
Assistant
Let me search for the
_aroute_requirements_to_members_streamfunction and understand the issue:Assistant
Let me look at the
_aroute_requirements_to_members_streamfunction starting around line 5110 to understand how it handles dependencies and session_state:Assistant
I need to look at the _aroute_requirements_to_members_stream function around line 5145 to understand how it handles dependencies and session_state. Let me use the bash terminal to search for relevant code.
Assistant
I see the issue now. In the
_aroute_requirements_to_members_streamfunction, when callingmember.acontinue_run(), therun_contextis not being passed. Let me check theacontinue_runmethod to understand what parameters it accepts:Assistant
The issue mentions that when
acontinue_runis called, the dependencies or session_state are lost. Let me search for the acontinue_run method in the agent code to see what parameters it accepts.Assistant
Let me look at the signature of the
acontinue_runmethod to understand what parameters it accepts, and specifically whether it can handledependenciesandsession_state:Assistant
Let me continue looking at the acontinue_run method to see how it uses the dependencies parameter. Also, let me search for how run_context is handled and whether dependencies/session_state are properly passed through.
Assistant
I can see that in
acontinue_run_dispatch, aRunContextis created with dependencies and session_state. Now let me check the_aroute_requirements_to_members_streamfunction in the team's_run.pyto see how it callsmember.acontinue_run()and whether it passes the run_context.Let me look at the specific lines in the team _run.py where member.acontinue_run is called:
Assistant
I found the issue! In the
_aroute_requirements_to_members_streamfunction, when callingmember.acontinue_run(), therun_contextparameter is NOT being passed. Therun_contextis available as a function parameter (line 5110), but it's never forwarded to the member'sacontinue_run()call.Let me also check the non-streaming version and similar functions:
Assistant
I found the same issue in the non-streaming version
_aroute_requirements_to_members. Both functions acceptrun_contextas a parameter but don't pass it tomember.acontinue_run(). Let me also search for other similar functions to ensure I fix all of them.Assistant
I found the same issue in the non-streaming version
_aroute_requirements_to_members. Both functions acceptrun_contextas a parameter but don't pass it tomember.acontinue_run(). Let me also search for other similar functions to ensure I fix all of them.Assistant
The grep shows there are many places where run_context is passed. Let me search specifically for the calls to member.acontinue_run() to see if there are other places that need fixing.
Assistant
Now I need to look at all these locations to see if they all have the same issue. Let me check each one:
- Line 4818 - group requirements by member_agent_id, calls member.continue_run()
- Line 4870/4877 - continue_run call
- Line 4961/4970 - continue_run stream call
- Line 5069/5075 - acontinue_run call in _aroute_requirements_to_members (non-streaming)
- Line 5171/5180 - acontinue_run call in _aroute_requirements_to_members_stream (streaming)
Let me examine each of these locations to understand the context. Let me look at the first two (line 4870 and 4877):
Assistant
Let me check each location where member.acontinue_run() or member.continue_run() is called:
Assistant
I need to see the full context of the _route_requirements_to_members function to understand if it has run_context available. Let me check around line 4818.
Assistant
Now let me check the streaming versions (lines 4961 and 4970):
Assistant
Now I understand the issue clearly. There are four functions that have the same problem - they all accept
run_contextas a parameter but don't pass it to the member'scontinue_run()oracontinue_run()calls:_route_requirements_to_members(sync, non-streaming)_route_requirements_to_members_stream(sync, streaming)_aroute_requirements_to_members(async, non-streaming)_aroute_requirements_to_members_stream(async, streaming)
Let me create a simple script to demonstrate the issue first, then fix it:
Assistant
Now I understand the issue. All four functions have
run_contextas a parameter but don't pass it to the member'scontinue_run()oracontinue_run()calls. Let me fix all four locations:Location 1:
_aroute_requirements_to_members(lines 5069 and 5075)Assistant
Now let me fix all four functions. I'll add
run_context=run_contextto all the memberacontinue_run()andcontinue_run()calls:Assistant
I need to use the edit function with the proper arguments format. Let me check the correct format.
Assistant
I need to use the special edit command for this environment. Let me try with the --file option:
<tool_call> <function=bash_terminal> <parameter=command> edit /agno/libs/agno/agno/team/_run.py 5069:5076 << 'EOF' member_response = await member.acontinue_run( # type: ignore[misc] run_response=member_run_output, # type: ignore[arg-type] session_id=session.session_id, run_context=run_context, ) else: member_run_id = reqs[0].member_run_id if reqs else None member_response = await member.acontinue_run( # type: ignore[misc] run_id=member_run_id, requirements=reqs, session_id=session.session_id, run_context=run_context, ) EOF </tool_call>
Assistant
I need to use sed to edit the file. Let me use sed to add
run_context=run_context,to all the member continue_run/acontinue_run calls:Assistant
I need to use sed commands to make the edits. Let me add
run_context=run_context,aftersession_id=session.session_id,in the relevant lines.I'll use sed to:
- First, let me check the exact line numbers where these calls are
- Then make the edits
Assistant
The lines I need to fix are:
- 4872, 4880 (member.continue_run in _route_requirements_to_members)
- 4963, 4973 (member.continue_run in _route_requirements_to_members_stream)
- 5071, 5078 (member.acontinue_run in _aroute_requirements_to_members)
- 5173, 5183 (member.acontinue_run in _aroute_requirements_to_members_stream)
Let me first look at the context of each line to understand the exact pattern:
Assistant
I need to add
run_context=run_context,to the member.continue_run and member.acontinue_run calls. Let me use sed carefully to only modify the relevant lines:Assistant
Now I'll use sed to add
run_context=run_context,to the appropriate lines. I'll add it aftersession_id=session.session_id,on the specific lines that need it.For lines 4872, 4880, 4963, 4973, 5071, 5078, 5173, 5183:
Assistant
I need to continue with the remaining lines. Let me add the run_context parameter to the remaining member.continue_run/acontinue_run calls.
Assistant
Let me continue fixing the remaining lines. The line numbers have shifted by 2 due to the two insertions I made.
Assistant
Let me check the current line numbers since they've shifted with each edit.
Assistant
Now I can see the updated line numbers. I need to fix lines 4976, 5074, 5081, 5176, and 5186.
Let me continue:
Assistant
<tool_call> <function=bash_terminal> <parameter=command> grep -n "session_id=session.session_id," /agno/libs/agno/agno/team/_run.py | grep -E "507[56]:|5082:|5177:|5187:" </tool_call>
Assistant
The grep returned no results, which means the line numbers might have shifted again. Let me check the current line numbers for the remaining lines.
Assistant
Now let me fix the remaining lines: 5083, 5178, and 5188.
Assistant
Now let me fix the remaining lines 5179 and 5189 (they shifted by 1).
Assistant
The line number shifted again. Let me fix the last remaining line: 5190.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "session_id=session.session_id," /agno/libs/agno/agno/team/_run.py | grep -E "518[0-9]:|519[0-9]:" </tool_call>
Assistant
The grep returned no results for 518[0-9]: or 519[0-9]:, which means line 5189 was likely the last one to fix and may have shifted. Let me check the context around where the remaining member.continue_run/acontinue_run calls should be.
Assistant
The line 5187 is the last member.acontinue_run call. Let me check if it already has run_context or if I need to add it:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '5185,5195p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me use bash_terminal to check if the last member.acontinue_run call has run_context or not.
Assistant
Now I can see that line 5190 needs to be fixed. Let me find the exact line number:
Assistant
<tool_call> <function=bash_terminal> <parameter=command> sed -i '5190s/session_id=session.session_id,/session_id=session.session_id,\n run_context=run_context,/' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Now let me verify that all the fixes were applied correctly by checking if all member.continue_run/acontinue_run calls have run_context=run_context:
Assistant
I need to check if the sed command worked. Let me look at the specific lines in the file to see if run_context was added. The sed command should have inserted
run_context=run_context,aftersession_id=session.session_id,. Let me check the current state. <tool_call> <function=bash_terminal> <parameter=command> sed -n '5187,5196p' /agno/libs/agno/agno/team/_run.py </tool_call>Assistant
Let me try the sed command to verify if the changes were applied. I'll use bash_terminal instead.
Assistant
The sed command didn't work. Let me check if it was applied correctly. The sed command should have inserted a new line with
run_context=run_context,aftersession_id=session.session_id,. Let me verify by checking the lines around 5190.Let me try using sed again to add run_context=run_context, to line 5190.
Assistant
Let me check if the sed command worked for line 5190. I need to add
run_context=run_context,after thesession_id=session.session_id,line in the last member.acontinue_run call.Assistant
Let me verify that all the fixes were applied correctly by checking all the member.continue_run/acontinue_run calls:
Assistant
Great! I can see that lines 4873, 4882, 4966, 4977, 5076, 5084, 5180, and 5191 now have
run_context=run_context,in them. These are the lines I fixed for the member.continue_run/acontinue_run calls.Now let me verify that the syntax is correct by checking the context of one of the fixed lines:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '4870,4890p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
The command didn't invoke properly. Let me use bash_terminal to check the context of the fixed lines.
Assistant
The first two fixes in
_route_requirements_to_memberslook correct. Let me check the other fixed lines as well:Assistant
The fixes in
_route_requirements_to_members_streamlook correct. Let me check the async streaming version:Assistant
The fixes in
_aroute_requirements_to_members_streamlook correct. Let me also check the async non-streaming version: <tool_call> <function=bash_terminal> <parameter=command> sed -n '5070,5095p' /agno/libs/agno/agno/team/_run.py </tool_call>Assistant
Let me try the bash_terminal command properly to check the async non-streaming version.
Assistant
All the fixes look correct. Now let me run a Python syntax check to make sure there are no syntax errors in the file:
<tool_call> <function=bash_terminal> <parameter=command> python -m py_compile /agno/libs/agno/agno/team/_run.py && echo "Syntax check passed!" </tool_call>
Assistant
The python command didn't seem to execute properly. Let me try again using bash_terminal.
Assistant
The syntax check passed! Now let me run the test script again to verify that the fix was applied correctly: <tool_call> <function=bash_terminal> <parameter=command> python /tmp/test_run_context.py </tool_call>
Assistant
I need to use bash_terminal to run the test script. Let me try that.
Assistant
Now let me check if there are any existing tests that might be affected by this change:
Assistant
Let me run some existing tests to make sure the fix doesn't break anything:
Assistant
Let me run more tests to make sure the fix doesn't break anything:
Assistant
The tests pass. Let me also run the team run regression tests: <tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/unit/team/test_team_run_regressions.py -v 2>&1 | head -100 </tool_call>
Assistant
I need to run the command properly with bash_terminal.
Assistant
All tests pass! Let me also run a few more relevant tests to ensure the fix is solid:
Assistant
The two failures are unrelated to my changes - they're about SQLite database configuration issues that were already present. All the team run-related tests pass.
Now let me create a test script to reproduce the original issue and verify that my fix resolves it:
Assistant
Let me fix the import and simplify the test:
Assistant
The test shows that 4 member.continue_run and 4 member.acontinue_run calls have run_context=run_context. The 5th member.continue_run call is in a different context (probably not the route functions I fixed). Let me verify this by checking what the 5th member.continue_run call is:
Assistant
The 5th member.continue_run call is at line 4818, which is a comment, not an actual call. So all 4 actual member.continue_run calls have run_context, and all 4 member.acontinue_run calls have run_context.
Now let me verify the fix more thoroughly by looking at the git diff:
Assistant
The diff shows exactly the changes I made - adding
run_context=run_context,to all 8 member.continue_run/acontinue_run calls in the four route functions.Now let me verify that the existing tests still pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/unit/team/test_run_context_precedence.py libs/agno/tests/unit/team/test_continue_run_requirements.py libs/agno/tests/unit/team/test_team_run_regressions.py -v 2>&1 | tail -20 </tool_call>
Assistant
Let me run the test command properly.
Assistant
All 63 tests pass! The fix is working correctly.
Now let me also check if there are any integration tests that test the acontinue_run functionality to make sure my fix doesn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/integration/teams/human_in_the_loop/ -v 2>&1 | head -50 </tool_call>
Assistant
The command wasn't executed because I need to use the bash_terminal tool properly. Let me try again.
Assistant
The integration test has missing dependencies (sqlalchemy). Let me just run the unit tests that are available. The unit tests all pass.
Let me also verify that the agent-level acontinue_run method can properly accept and use the run_context parameter:
<tool_call> <function=bash_terminal> <parameter=command> grep -A 10 "def acontinue_run_dispatch" /agno/libs/agno/agno/agent/_run.py | head -15 </tool_call>
Assistant
Let me try to check the acontinue_run method signature in the agent module.
Assistant
Good. The
acontinue_run_dispatchmethod acceptsrun_contextas a parameter (as we saw earlier in the code). Let me also verify that the agent's continue_run/acontinue_run methods properly pass the run_context to the internal implementation. Let me search for how the agent method handles run_context:Assistant
Now let me make sure there are no other places in the codebase where member.continue_run/acontinue_run is called without run_context:
Assistant
All the member.continue_run/acontinue_run calls are in the _run.py file, and I've already fixed all of them.
Let me now summarize the changes I made and verify that everything is correct:
- I fixed the
_route_requirements_to_membersfunction (lines 4872 and 4881) to passrun_context=run_contextto member.continue_run() calls - I fixed the
_route_requirements_to_members_streamfunction (lines 4965 and 4976) to passrun_context=run_contextto member.continue_run() calls - I fixed the
_aroute_requirements_to_membersfunction (lines 5076 and 5084) to passrun_context=run_contextto member.acontinue_run() calls - I fixed the
_aroute_requirements_to_members_streamfunction (lines 5180 and 5191) to passrun_context=run_contextto member.acontinue_run() calls
All unit tests pass, and the fix addresses the issue described in the bug report where
session_state["user_token"]was None when usingteam.acontinue_run.Let me run one final comprehensive test to ensure the fix is working correctly:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/unit/team/ -v --tb=short 2>&1 | tail -15 </tool_call>
- I fixed the
Assistant
I need to wait for the test output to complete.
Assistant
The fix is complete. Let me provide a summary of what was done:
Summary
Issue:
team.acontinue_runwas losingdependenciesandsession_statewhen continuing runs. Specifically, when callingagent.acontinue_run()from within the team's_aroute_requirements_to_members_streamfunction, therun_contextparameter was not being passed, causingrun_context.session_state["user_token"]to beNone.Root Cause: In
/agno/libs/agno/agno/team/_run.py, the four functions that route requirements to member agents were acceptingrun_contextas a parameter but not passing it to the member'scontinue_run()oracontinue_run()calls:_route_requirements_to_members(sync, non-streaming)_route_requirements_to_members_stream(sync, streaming)_aroute_requirements_to_members(async, non-streaming)_aroute_requirements_to_members_stream(async, streaming)
Fix: Added
run_context=run_context,parameter to all 8 member / calls in the four functions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.