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 understand the issue:
- The user is reporting a bug where
team.acontinue_runloses dependencies or session_state - When a team run is paused and resumed with
acontinue_run, thedependenciesparameter (which containssession_state) is not being properly passed to the team's agent runs - The suggested fix points to line 5145 in
_run.pywhere_aroute_requirements_to_members_streamdoesn't restore the run_context properly
Let me start by exploring the repository structure and finding the relevant file.
- The user is reporting a bug where
Assistant
Let me look at the team's _run.py file around line 5145 as suggested:
Assistant
Let me check the area around line 5145:
Assistant
I can see the issue. On line 5162 (around line 5145 based on the issue description), when calling
member.acontinue_run(), therun_contextis not being passed. Therun_contextvariable is available as a parameter to_aroute_requirements_to_members_stream, but it's not being passed to the member'sacontinue_run()call.Let me see more of this function and also check what parameters
acontinue_runaccepts:Assistant
Let me check what parameters
acontinue_runaccepts in the member agent:Assistant
Let me look at the agent's acontinue_run method:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '3561,3620p' /agno/libs/agno/agno/agent/_run.py </tool_call>
Assistant
I need to invoke the bash_terminal tool properly. Let me search for acontinue_run method in the agent module:
Assistant
Let me look for acontinue_run in the file more thoroughly. The issue might be in a different location or might be a class method.
Assistant
Let me look at the _acontinue_run_stream function to understand what parameters it takes:
Assistant
Now I can see the issue. The
_acontinue_run_streamfunction acceptsrun_contextas a parameter (line 4255), and it expects this to havesession_stateanddependenciesset (see lines 4287-4298). However, when the team callsmember.acontinue_run()from_aroute_requirements_to_members_stream, it doesn't pass therun_contextat all.Let me also look at the TeamSession and understand how run_context should be passed:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "class TeamSession" /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool with a proper format. Let me try again:
Assistant
The command failed to find TeamSession in the _run.py file. Let me search for TeamSession in a different way.
Assistant
Let me look at the TeamSession class:
<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/agno/session/team.py </tool_call>
Assistant
I need to properly use the bash_terminal tool with the correct format to execute the command.
Assistant
Now let me understand how the run_context is passed. Let me look at the Team's acontinue_run method and how it creates the run_context:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "def acontinue_run" /agno/libs/agno/agno/team/_run.py | head -10 </tool_call>
Assistant
I see the issue with my command. Let me try again with proper escaping.
Assistant
I apologize for the confusion. Let me continue exploring the code to understand how the team's acontinue_run works.
Assistant
Now I understand the issue better. The team's acontinue_run function creates a
run_contextwith thedependenciesparameter (around line 6541-6542), but when it calls_aroute_requirements_to_members_stream, therun_contextis passed (as seen in line 5108 of _run.py). However, inside_aroute_requirements_to_members_stream, when callingmember.acontinue_run()(lines 5170-5177 and 5179-5186), therun_contextis NOT passed.Let me look at the member's acontinue_run to see if it accepts run_context:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "def acontinue_run" /agno/libs/agno/agno/agent/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. The previous attempts seem to have had issues. Let me try again.
Assistant
Now I found the acontinue_run_dispatch function. Let me look at it and understand its signature.
Assistant
Now I can see that
acontinue_run_dispatchaccepts arun_contextparameter (line 3572). Let me continue reading to see how it uses the run_context.<tool_call> <function=bash_terminal> <parameter=command> sed -n '3630,3720p' /agno/libs/agno/agno/agent/_run.py </tool_call>
Assistant
I need to continue viewing the file. Let me try again with the proper tool call.
Assistant
Now I understand the issue. Let me look more closely at the
_aroute_requirements_to_members_streamfunction to see exactly whererun_contextshould be passed:Assistant
I've identified the issue. In the
_aroute_requirements_to_members_streamfunction, when callingmember.acontinue_run()(both on lines 5171-5177 and 5180-5186), therun_contextparameter is not being passed. This means that thedependenciesandsession_statefrom the team'srun_contextare not being propagated to the member agents.Let me also check if there's a non-streaming version of this function that might have the same issue:
Assistant
There are two versions - one non-streaming (line 5015) and one streaming (line 5110). Let me check the non-streaming version as well to see if it has the same issue.
Assistant
Now I can see that both functions have the same issue. In the non-streaming version (around lines 5064-5068 and 5070-5074),
run_contextis also not passed tomember.acontinue_run().Now I need to fix both functions by adding the
run_contextparameter to themember.acontinue_run()calls. Let me also check if there are other places where member.acontinue_run is called without run_context.Let me first check the exact lines that need to be modified:
-
_aroute_requirements_to_members(non-streaming):- Lines ~5064-5068: First call to member.acontinue_run
- Lines ~5070-5074: Second call to member.acontinue_run
-
_aroute_requirements_to_members_stream(streaming):- Lines ~5171-5177: First call to member.acontinue_run
- Lines ~5180-5186: Second call to member.acontinue_run
Let me now view more of the streaming version to get the exact lines:
-
Assistant
Now I understand the issue clearly. The
run_contextparameter containingdependenciesandsession_stateis passed to_aroute_requirements_to_membersand_aroute_requirements_to_members_stream, but it's not being passed when callingmember.acontinue_run(). This causes the member agents to lose thesession_stateanddependenciesthat were provided.Let me fix both functions:
Assistant
Let me check a bit more to see the full context of both calls in the non-streaming version.
Assistant
Now I have identified the exact locations. Let me fix the non-streaming version first by adding the
run_contextparameter:Assistant
Now I'll fix the non-streaming version first by adding
run_context=run_contextto bothacontinue_runcalls:Assistant
Now let me verify the change was made correctly:
Assistant
The first fix was applied. Now I need to fix the second call to
acontinue_runin the non-streaming version (the one withrun_id). Let me update it:Assistant
Now I need to fix the second
acontinue_runcall in the non-streaming version. I'll replace the line withsession_id=session.session_id,with one that also includesrun_context=run_context,.Assistant
Let me verify the changes in the non-streaming version:
Assistant
The non-streaming version is fixed. Now let me fix the streaming version. I need to update the two
acontinue_runcalls in_aroute_requirements_to_members_stream:<tool_call> <function=bash_terminal> <parameter=command> sed -n '5170,5195p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me check the lines in the streaming version.
Assistant
Now let me fix the streaming version. First, I'll fix the call with
run_response(around line 5173-5179):Assistant
Now let me verify the first streaming fix and then fix the second one:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '5173,5185p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me try again.
Assistant
The first streaming fix was applied. Now I need to fix the second streaming call (with
run_id). Let me check the current state:Assistant
Now I need to fix the second streaming call by adding
run_context=run_context. The line withsession_id=session.session_id,is around line 5186.Assistant
Let me verify all the changes have been applied correctly:
Assistant
Let me verify all the changes are correct by looking at both functions:
Assistant
Let me also verify the streaming version:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '5110,5200p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me use the bash_terminal tool properly to check the streaming version.
Assistant
Both functions have been fixed. Now let me check if there are any existing tests to verify the fix doesn't break anything:
Assistant
Let me look at the team tests to see if there are tests related to the team acontinue_run functionality:
<tool_call> <function=bash_terminal> <parameter=command> find /agno -name "test*.py" -type f | xargs grep -l "team.*acontinue_run|acontinue_run.*team" 2>/dev/null | head -10 </tool_call>
Assistant
Let me try a different approach to find relevant tests.
Assistant
Let me look at some of these test files to understand how the team acontinue_run is tested and to see if there are any tests that check for the run_context being passed correctly:
<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/tests/unit/team/test_continue_run_requirements.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me try again.
Assistant
I found the test file. Let me look at the team human-in-the-loop tests to see if there's a test that verifies session_state or dependencies are passed correctly through acontinue_run:
<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/tests/integration/teams/human_in_the_loop/test_team_confirmation_flows.py | head -200 </tool_call>
Assistant
Let me run the command properly to view the test file.
Assistant
Let me look for any tests that specifically test for session_state or dependencies being passed correctly during team continue_run. The issue description mentions that session_state should be passed to member agents when calling acontinue_run.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "session_state" /agno/libs/agno/tests/ 2>/dev/null | head -30 </tool_call>
Assistant
I need to properly use the bash_terminal tool. Let me try again.
Assistant
I can see that session_state is used in various tests. Let me look for tests that specifically involve teams and session_state or dependencies.
Now, let me check if there are any existing tests for the team's acontinue_run with session_state:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "dependencies" /agno/libs/agno/tests/ 2>/dev/null | grep -i team | head -20 </tool_call>
Assistant
The command failed. Let me try using the proper bash_terminal tool format.
Assistant
Now let me look at the test_team_runs.py test that mentions dependencies to understand how the test setup works:
<tool_call> <function=bash_terminal> <parameter=command> grep -B 20 -A 20 "assert run_context.dependencies" /agno/libs/agno/tests/integration/os/test_team_runs.py </tool_call>
Assistant
I need to properly use the bash_terminal tool to execute commands. Let me try again with the correct syntax.
Assistant
I see that there's a test that verifies
run_context.dependenciesis passed correctly to a team run. Now let me look at the test_hooks.py file which tests team hooks with session_state and dependencies:<tool_call> <function=bash_terminal> <parameter=command> grep -B 10 -A 50 "test_dependencies = " /agno/libs/agno/tests/integration/teams/test_hooks.py | head -100 </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me try again with the correct syntax.
Assistant
Now let me check the test_member_run_persistence.py file to see if there are any tests related to session_state being passed to member agents:
Assistant
Now I understand the test structure. The issue is that when a team run is paused and resumed with
acontinue_run, thedependenciesandsession_stateshould be passed to the member agents, but they currently aren't.Let me look at the specific location of the
_acontinue_run_streamfunction to see how it calls_aroute_requirements_to_members_stream:<tool_call> <function=bash_terminal> <parameter=command> grep -n "_aroute_requirements_to_members_stream" /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me search for the location of the call to _aroute_requirements_to_members_stream in the _acontinue_run_stream function.
Assistant
Let me look at the line 7072 and the context around it to see how the function is called and verify that run_context is being passed:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '7060,7085p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me check the context around line 7072 to see how _aroute_requirements_to_members_stream is called.
Assistant
Good, I can see that
run_context=run_contextis being passed correctly to_aroute_requirements_to_members_stream. Now let me also check the non-streaming version:<tool_call> <function=bash_terminal> <parameter=command> grep -n "_aroute_requirements_to_members(" /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me check for the non-streaming version of the function call.
Assistant
Let me check line 6740 to see how the non-streaming version is called:
Assistant
I can see that
run_context=run_contextis being passed correctly to both_aroute_requirements_to_members_streamand_aroute_requirements_to_members. The issue is that within these functions, when they callmember.acontinue_run(), they weren't passingrun_contextto the member'sacontinue_run().I've already fixed both functions. Let me verify my changes are correct by looking at the diff:
Assistant
Good, my changes look correct. I've added
run_context=run_contextto all fouracontinue_runcalls in the two functions:-
_aroute_requirements_to_members(non-streaming):- First call with
run_response=member_run_output - Second call with
run_id=member_run_id
- First call with
-
_aroute_requirements_to_members_stream(streaming):- First call with
run_response=member_run_output - Second call with
run_id=member_run_id
- First call with
Now let me run the existing tests to make sure I didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/unit/team/test_continue_run_requirements.py -v 2>&1 | head -100 </tool_call>
-
Assistant
I need to use the bash_terminal tool properly to run the tests. Let me try again.
Assistant
All 49 tests passed. Now let me also run some additional tests related to acontinue_run:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m pytest libs/agno/tests/unit/team/ -v 2>&1 | head -100 </tool_call>
Assistant
The command failed to execute properly. I need to use the bash_terminal tool with the correct format.
Let me try running the tests with the bash_terminal tool properly.
Assistant
The tests are running. Let me wait for them to complete and see if any fail:
Assistant
The test failures are unrelated to my changes - they're about db module attributes. Let me check if these tests were failing before my changes by looking at what they're testing.
My changes only affect the
_aroute_requirements_to_membersand_aroute_requirements_to_members_streamfunctions, addingrun_contextparameter toacontinue_runcalls. The failing tests are aboutTestTeamFromDict::test_from_dict_with_db_postgresandTestTeamFromDict::test_from_dict_with_db_sqlite, which are completely unrelated to my changes.Let me verify that the specific tests for acontinue_run are passing:
Assistant
All 55 tests related to
acontinue_runandcontinue_run_requirementspassed! The two failing tests are unrelated to my changes.Now let me also verify that the changes are syntactically correct by importing the module:
<tool_call> <function=bash_terminal> <parameter=command> python -c "from agno.team._run import _aroute_requirements_to_members, _aroute_requirements_to_members_stream; print('Import successful')" </tool_call>
Assistant
I need to use the bash_terminal tool properly to run the import check. Let me try again.
Assistant
Now let me create a simple script to verify that the fix works correctly:
Assistant
Let me check the RunRequirement class to see what parameters it accepts:
Assistant
I apologize for the error. Let me fix the test script by using the correct RunRequirement parameters.
Assistant
Let me fix the test script by patching the function where it's used (locally within the function):
Assistant
I need to fix the streaming test. Let me update the mock to properly handle the async iteration.
Assistant
I need to simplify the test to focus on the core issue - verifying that run_context is passed to the member.acontinue_run calls. The streaming test is failing due to mock setup issues. Let me just simplify it to focus on the call being made with the correct arguments.
Assistant
The tests pass! The warnings about "Member continue_run failed" are expected because we're using MagicMock objects and they don't have all the required attributes. But the important part is that the run_context is being passed correctly.
Now let me clean up and summarize what I've done:
-
I identified the issue: In the
_aroute_requirements_to_membersand_aroute_requirements_to_members_streamfunctions, therun_contextparameter (which containsdependenciesandsession_state) was being received but not passed to the member agents'acontinue_run()calls. -
I fixed the issue by adding
run_context=run_contextto all fourmember.acontinue_run()calls:_aroute_requirements_to_members: 2 calls (one withrun_response, one withrun_id)_aroute_requirements_to_members_stream: 2 calls (one withrun_response, one withrun_id)
-
I verified the fix by running:
-
Assistant
I need to use the bash_terminal tool properly to clean up and show the diff.
Assistant
The diff shows exactly the changes I made. Let me now verify there are no other places in the codebase where similar issues might exist by searching for other member.acontinue_run calls:
Assistant
All four occurrences have been fixed. Let me also check if there are any other places in the codebase that might call
member.acontinue_run:Assistant
I see there are also
continue_run(non-async) calls. Let me check those to see if they need the same fix. The issue description specifically mentionsacontinue_run, but let me verify the sync version as well:Assistant
I see there are also sync versions of these functions (
_route_requirements_to_membersand_route_requirements_to_members_stream) that have the same issue. Let me fix those as well.Assistant
Let me fix the sync
_route_requirements_to_membersfunction by addingrun_context=run_contextto bothcontinue_runcalls:<tool_call> <function=bash_terminal> <parameter=command> sed -n '4865,4885p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me try again with the correct syntax.
Assistant
Let me fix the sync
_route_requirements_to_membersfunction by addingrun_context=run_contextto bothcontinue_runcalls:<tool_call> <function=bash_terminal> <parameter=command> sed -i '4871,4873s/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
Let me verify my changes with proper bash_terminal tool usage.
Assistant
Let me verify the change was applied correctly and then fix the second call.
Assistant
The first sync call was fixed. Now let me fix the second sync call (the one with
run_id). Let me first check the exact line number:Assistant
Now let me fix the second sync call by adding
run_context=run_contextto thecontinue_runcall withrun_id. The line withsession_id=session.session_id,is around line 4881.Assistant
Let me verify this change was applied correctly.
Assistant
Good, the sync non-streaming version is fixed. Now let me fix the sync streaming version (
_route_requirements_to_members_stream). Let me first check the current state:Assistant
Let me fix the sync streaming version by adding
run_context=run_contextto bothcontinue_runcalls.Assistant
Let me verify the first sync streaming fix and then fix the second one.
Assistant
Let me verify the change and then fix the second sync streaming call.
Assistant
Now let me fix the second sync streaming call by adding
run_context=run_contextto thecontinue_runcall withrun_id. The line withsession_id=session.session_id,is around line 4976.Assistant
Let me verify all the changes were applied correctly by viewing the full diff.
Assistant
Now the diff shows all 8 locations have been fixed:
_route_requirements_to_members(sync, non-streaming) - 2 calls_route_requirements_to_members_stream(sync, streaming) - 2 calls_aroute_requirements_to_members(async, non-streaming) - 2 calls_aroute_requirements_to_members_stream(async, streaming) - 2 calls
Let me run the existing tests to make sure my changes don't break anything.
Assistant
All 49 tests passed. Let me also run the tests for the acontinue_run background stream to make sure those still work.
Assistant
All tests passed. Let me also verify that the code can be imported correctly:
Assistant
All tests pass and imports work correctly. Let me verify the final state of my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.