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 start by understanding the issue. The bug report mentions that when calling
team.acontinue_run, thedependenciesorsession_stateare lost or not passed correctly. This causes therun_contextto not have theuser_tokenwhen the functiongroup_del_stockis called.The issue description points to a specific file:
/libs/agno/agno/team/_run.pyat line 5145 in the_aroute_requirements_to_members_streammethod
Let me first explore the repository structure and then look at the relevant code.
Assistant
Now let me look at the specific file mentioned in the issue:
Assistant
The file has 7502 lines. Let me look at line 5145 and the surrounding context to understand the issue better:
Assistant
Let me search for the
acontinue_runfunction in the team module to understand how it handles dependencies:Assistant
Let me also check for
acontinue_runin the team class:Assistant
Let me look at the
_acontinue_run_streamfunction around line 5145 which is where the issue was reported:<tool_call> <function=bash_terminal> <parameter=command> sed -n '6953,7050p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me search for
_aroute_requirements_to_members_streamwhich was mentioned in the issue description:Assistant
Now let me see the
_aroute_requirements_to_members_streamfunction which starts at line 5110:<tool_call> <function=bash_terminal> <parameter=command> sed -n '5110,5280p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
It seems like the tool didn't get invoked correctly. Let me try again with a proper tool call:
Assistant
Now I can see the issue. The
_aroute_requirements_to_members_streamfunction is called from_acontinue_run_streamand it doesn't pass thedependenciesorsession_stateto the member agents'acontinue_runmethod. Let me look at the_acontinue_run_streamfunction to see how it's called:<tool_call> <function=bash_terminal> <parameter=command> sed -n '6953,7100p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
The tool call doesn't seem to be working. Let me try again to view the
_acontinue_run_streamfunction:Assistant
Now I can see the issue more clearly. The
_acontinue_run_streamfunction is called with arun_contextparameter, and it passes thisrun_contextto_aroute_requirements_to_members_stream. However, the_aroute_requirements_to_members_streamfunction doesn't pass therun_contextto themember.acontinue_run()calls.Let me look at how
member.acontinue_run()is called in the_aroute_requirements_to_members_streamfunction:<tool_call> <function=bash_terminal> <parameter=command> sed -n '5165,5185p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
The tool call isn't working as expected. Let me try a different approach - maybe I should use the open tool instead:
Assistant
It seems like the open tool requires specific arguments. Let me try to just look at the code using grep and sed more carefully. Let me look at the specific lines around the member.acontinue_run calls:
Assistant
Let me check what parameters are being passed to
member.acontinue_runin the_aroute_requirements_to_members_streamfunction (lines 5171 and 5180):<tool_call> <function=bash_terminal> <parameter=command> sed -n '5171,5190p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
The sed command is not working as expected. Let me try a different approach - maybe I need to check if the file exists first:
Assistant
Now I can see the issue! Looking at the code around lines 5171-5187, there are two calls to
member.acontinue_run(), but neither of them passes therun_contextor any session state to the member.Let me check what parameters the member's
acontinue_runaccepts to see what should be passed:Assistant
Let me check the Agent's
acontinue_runmethod signature to see what parameters it accepts:Assistant
Now I can see that the Agent's
acontinue_runmethod accepts:run_context: Optional[RunContext] = Nonedependencies: Optional[Dict[str, Any]] = None
Looking at the issue, when
team.acontinue_runis called withdependencies=session_state, thisdependenciesparameter should be passed through to the member agents'acontinue_runcalls.Let me check how the Team's
acontinue_runfunction handles thedependenciesparameter and if it passes it to_aroute_requirements_to_members_stream:<tool_call> <function=bash_terminal> <parameter=command> grep -n "dependencies" /agno/libs/agno/agno/team/_run.py | head -50 </tool_call>
Assistant
The tool call isn't working correctly. Let me try again with a simpler approach.
Assistant
I see that the codebase has many uses of
dependencies. Let me check how_acontinue_run_streamis called and if it handles thedependenciesparameter:<tool_call> <function=bash_terminal> <parameter=command> grep -n "dependencies" /agno/libs/agno/agno/team/_run.py | grep -E "(acontinue_run|_acontinue_run)" | head -20 </tool_call>
Assistant
Let me try a different approach - I need to look at the function signatures more carefully. Let me search for where acontinue_run is defined for the team.
Assistant
Let me check the signature of
_acontinue_runat line 6620: <tool_call> <function=bash_terminal> <parameter=command> sed -n '6620,6680p' /agno/libs/agno/agno/team/_run.py </tool_call>Assistant
The
sedcommand doesn't seem to be working properly with the tool. Let me try to usecatwith line range instead.Assistant
I notice that
_acontinue_runreceives arun_contextparameter, but doesn't havedependenciesas a direct parameter. However,run_contextshould contain the dependencies.Let me check how
_acontinue_run_streamhandles this and what it passes to_aroute_requirements_to_members_stream:Assistant
Now let me see where
_aroute_requirements_to_members_streamis called in_acontinue_run_stream:Assistant
Now I can see that
_aroute_requirements_to_members_streamreceives therun_contextparameter. The issue is that when it callsmember.acontinue_run(), it doesn't pass therun_contextto the member agent.Looking at the code at lines 5171-5187, the
member.acontinue_run()calls don't include therun_contextparameter. This means that when the member agent runs the tool, it doesn't have access to therun_context.dependencieswhich should contain theuser_tokenfromsession_state.Let me also check if
run_contexthas the properdependenciesset up when_aroute_requirements_to_members_streamis called. I need to trace back to see whererun_contextis set up in_acontinue_run_stream:<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/agno/team/_run.py | sed -n '6990,7000p' </tool_call>
Assistant
Let me check where run_context is created in _acontinue_run_stream:
Assistant
Let me check where run_context is passed into _acontinue_run_stream from the dispatch function:
Assistant
Now I understand the flow:
acontinue_run_dispatchcreates arun_contextwithdependenciesset fromopts.dependencies- It passes
run_contextto_acontinue_run_stream _acontinue_run_streampassesrun_contextto_aroute_requirements_to_members_stream_aroute_requirements_to_members_streamshould passrun_contexttomember.acontinue_run()
The issue is that in
_aroute_requirements_to_members_stream, when callingmember.acontinue_run(), therun_contextis NOT being passed. This means the member agent doesn't have access to the dependencies (likeuser_token).Let me now look at the
_aroute_requirements_to_members_streamfunction to fix it. The fix should be to pass therun_contextparameter to both calls tomember.acontinue_run():<tool_call> <function=bash_terminal> <parameter=command> sed -n '5165,5190p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me try a different approach - using grep to get the specific lines and then view them:
Assistant
Now I can see the issue clearly. The
member.acontinue_run()calls at lines 5170-5176 and 5179-5185 don't include therun_contextparameter.Looking at the Agent's
acontinue_runsignature I saw earlier, it acceptsrun_context: Optional[RunContext] = Noneanddependencies: Optional[Dict[str, Any]] = None. Therun_contextshould be passed to ensure the member has access to thesession_stateanddependencies.Let me fix this by adding the
run_contextparameter to bothmember.acontinue_run()calls. I also need to check if there's a similar issue in the synchronous version (lines 5069 and 5075).Let me first check the synchronous version:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '5065,5090p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me try a different approach to view the lines around the synchronous version.
Assistant
Now I can see both the synchronous and asynchronous versions have the same issue. Let me also check which function these belong to:
Assistant
Now I understand the issue. Both the async streaming version (
_aroute_requirements_to_members_stream) and the async non-streaming version (_aroute_requirements_to_members) callmember.acontinue_run()but neither passes therun_contextparameter. This means that when the member runs, it doesn't have access to thesession_stateanddependenciesthat were passed in viarun_context.Let me now check what parameters are expected by the Agent's
acontinue_runmethod to ensure I'm fixing it correctly:From my earlier review, the Agent's
acontinue_runaccepts:run_context: Optional[RunContext] = Nonedependencies: Optional[Dict[str, Any]] = None
Since
run_contextalready contains thedependenciesin it, I should passrun_contextto the member'sacontinue_runcall.Now let me also check if there's a
_aroute_requirements_to_membersfunction (non-streaming) that also needs the same fix:<tool_call> <function=bash_terminal> <parameter=command> grep -n "def _aroute_requirements_to_members" /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me search for the function definitions properly.
Assistant
Now I understand the issue. Both
_aroute_requirements_to_membersand_aroute_requirements_to_members_streamfunctions receive arun_contextparameter but don't pass it to themember.acontinue_run()calls. This causes the member agents to not have access to thesession_stateanddependencies(likeuser_token).Let me fix both functions by adding the
run_contextparameter to themember.acontinue_run()calls:Assistant
Let me fix the
_aroute_requirements_to_membersfunction first (lines 5069-5080):Assistant
Now I'll edit the file to add
run_context=run_contextto bothmember.acontinue_run()calls in the_aroute_requirements_to_membersfunction.Assistant
Now let me verify the changes were applied correctly:
Assistant
Now let me verify the changes for the streaming version as well:
Assistant
Now let me check if there are existing tests related to this functionality that I should run:
Assistant
Let me run some tests to verify my fix doesn't break existing functionality. First, let me check if there are tests that specifically test the
acontinue_runfunctionality with dependencies or session_state:Assistant
Let me check the test_hitl.py file to see if it tests the HITL scenario mentioned in the issue:
Assistant
Now let me check if there are tests related to team HITL that test
acontinue_run:<tool_call> <function=bash_terminal> <parameter=command> grep -n "acontinue_run" /agno/libs/agno/tests/integration/workflows/test_hitl.py | head -20 </tool_call>
Assistant
Let me try again with the grep command to find acontinue_run references.
Assistant
These are tests for workflow, not team. Let me check if there are tests for team HITL:
Assistant
Let me check if there are tests specifically for team HITL and session state:
Assistant
Let me look for tests that test team acontinue_run with dependencies or session_state:
Assistant
Let me check the test_team_runs.py file to see if there are any tests related to acontinue_run:
Assistant
Now let me run the existing tests 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/workflows/test_hitl.py -v -x 2>&1 | head -100 </tool_call>
Assistant
Let me try to run the tests with the correct command. The issue might be that the test needs certain dependencies to run.
Let me first check what testing infrastructure exists and then run a simpler test to verify the syntax of my changes is correct.
Assistant
The command failed because of bash history expansion with '!'. Let me escape it.
Assistant
The import works fine. Now let me verify the fix more thoroughly by looking at the diff of what I changed:
Assistant
The diff shows that I've added to all four calls in both and functions.
Assistant
The grep didn't return anything, which means there's no synchronous version of these functions (without the "aroute" prefix). The async versions I fixed should be sufficient.
Let me also verify the fix by checking if there are any other places where
member.acontinue_runis called withoutrun_context:Assistant
Now I see that there are also synchronous calls to
member.continue_run()at lines 4870-4877 and 4961-4970. Let me check if these also need therun_contextparameter.Let me look at the context around lines 4870-4877 and 4961-4970 to see if they're in functions that receive
run_context:Assistant
I can see that lines 4870-4877 are in a function that also has
member.continue_run()calls. Let me check which function this is and if it receivesrun_context:Assistant
I see! The
_route_requirements_to_membersfunction (synchronous, line 4810) also receivesrun_contextand callsmember.continue_run()at lines 4870 and 4877 without passingrun_context. I need to fix this as well.Let me also check the
_route_requirements_to_members_streamfunction at lines 4961-4970:Assistant
Let me check the function signature of
_route_requirements_to_members_stream:<tool_call> <function=bash_terminal> <parameter=command> sed -n '4905,4935p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me try to view the function signature of
_route_requirements_to_members_stream.Assistant
Now let me view the function signature:
Assistant
I see that there are also synchronous versions of these functions that need the same fix. Let me fix all four additional
member.continue_run()calls:Assistant
Now let me verify all the changes were applied correctly:
Assistant
The diff shows that I've added
run_context=run_contextto all 8member.continue_run()andmember.acontinue_run()calls in the following functions:_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
Now let me verify the import works correctly after the changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -c "from agno.team._run import _aroute_requirements_to_members, _aroute_requirements_to_members_stream, _route_requirements_to_members, _route_requirements_to_members_stream; print('Import successful')" </tool_call>
Assistant
The import is still failing. Let me check what error is happening.
Assistant
The import works. Now let me verify the syntax of the modified functions by checking each of them:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '4870,4890p' /agno/libs/agno/agno/team/_run.py </tool_call>
Assistant
Let me verify the changes by looking at specific lines:
Assistant
The changes look correct. Now let me also check the other functions:
Assistant
The changes look correct. Now let me also verify the async versions:
Assistant
All the changes look correct. Now let me run some tests to verify the fix doesn't break existing functionality:
Assistant
Let me find the correct test files:
Assistant
I see there's a test file for session_state specifically for teams! Let me check that test file to see if it has any tests related to
acontinue_run:Assistant
Now let me look for tests related to HITL with team to see if there are tests for the scenario described in the issue:
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "acontinue_run" /agno/libs/agno/tests/integration/teams/ 2>/dev/null | head -10 </tool_call>
Assistant
The grep command didn't return any results. Let me try a different approach to search for team HITL tests.
Assistant
Let me look at the test_team_tool_hitl.py file to see if it tests the scenario described in the issue:
<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/tests/integration/teams/human_in_the_loop/test_team_tool_hitl.py </tool_call>
Assistant
I'll run the test file with cat and then analyze its content.
Assistant
Now let me check the
test_member_run_persistence.pyfile to see if it tests member-level HITL with session_state:Assistant
Now I understand the existing tests. The tests don't specifically test for the scenario where
dependenciesorsession_stateare passed toacontinue_runand need to be available in the member agent'srun_context. Let me run the existing tests to make sure my fix doesn't break them.Let me run a simpler unit test to verify the import works:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -c " from agno.team._run import _aroute_requirements_to_members, _aroute_requirements_to_members_stream, _route_requirements_to_members, _route_requirements_to_members_stream print('All imports successful') " </tool_call>
Assistant
The command failed. Let me try a different approach.
Assistant
The imports work correctly. Now let me verify the fix by checking if the changes are syntactically correct by compiling the module:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && python -m py_compile libs/agno/agno/team/_run.py && echo "Syntax is correct" </tool_call>
Assistant
The command failed, let me try a different approach to verify the syntax.
Assistant
Great, the syntax is correct. Now let me also check if there are any other places where member agents are called that might need the same fix. Let me search for other usages:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "member.(a)?continue_run|member.(a)?run" /agno/libs/agno/agno/team/_run.py | head -30 </tool_call>
Assistant
Let me try again with the grep command.
Assistant
The grep command is working now. I see all the member method calls have already been fixed. Let me also check if there are any other places where the team delegates to members that might need the
run_contextfix:<tool_call> <function=bash_terminal> <parameter=command> grep -n "member." /agno/libs/agno/agno/team/_run.py | grep -v "member_id|member_agent_id|member_response|member_results|member_req|member_runs|member_run_id|member_run_output" | head -30 </tool_call>
Assistant
The grep command is not working correctly. Let me try a simpler approach to see if there are other places where members are called.
Assistant
The grep output shows only one reference to
member.store_mediawhich is unrelated to the HITL issue. The fix I've made covers all the cases wheremember.acontinue_run()ormember.continue_run()is called.Let me also verify that my fix is complete by looking at the full context of the changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /agno && git diff --stat libs/agno/agno/team/_run.py </tool_call>
Assistant
The command is failing again. Let me try a simpler approach to check the git diff.
Assistant
The fix adds 8 lines (one
run_context=run_contextparameter to each of the 8member.continue_run()andmember.acontinue_run()calls).Now let me verify that the fix is complete by reviewing the logic flow one more time:
-
Issue: When
team.acontinue_run(dependencies=session_state, ...)is called, thesession_stateshould be available in the member agent'srun_contextwhen the member runs a tool. -
Root cause: The
_aroute_requirements_to_members_streamfunction (and its synchronous counterparts) receivesrun_contextbut doesn't pass it to the member'sacontinue_run()calls. This means the member agent doesn't have access to thesession_stateordependencies. -
Fix: Add
run_context=run_contextto all and calls in:
-
Assistant
Let me check if there are any existing tests that specifically test the
dependenciesparameter in the context ofacontinue_run:Assistant
There are no existing tests that specifically test
dependencieswithacontinue_run. This is likely because the bug was not caught by tests before.Let me also verify that the Agent's
acontinue_runmethod acceptsrun_contextand handles it correctly:Assistant
Let me check the Agent's
acontinue_runsignature more specifically:Assistant
The Agent's
acontinue_runmethod accepts bothrun_contextanddependenciesparameters. Whenrun_contextis passed, it should contain thedependenciesandsession_state.Now let me verify that my fix is correct by looking at how the Agent handles
run_context:<tool_call> <function=bash_terminal> <parameter=command> sed -n '3640,3680p' /agno/libs/agno/agno/agent/_run.py </tool_call>
Assistant
Let me try a different approach to view the relevant code:
<tool_call> <function=bash_terminal> <parameter=command> cat /agno/libs/agno/agno/agent/_run.py | sed -n '3640,3680p' </tool_call>
Assistant
The tool seems to have issues running commands. Let me try again.
Assistant
I see that the Agent's
acontinue_run_dispatchmethod:- If
run_contextis provided, it uses that (line 3660:run_context = run_context or RunContext(...)) - The
run_contextcontainssession_stateanddependencies - These are passed to the tool execution via the tool's
run_contextparameter
This confirms that my fix is correct. By passing
run_contextto the member agent'sacontinue_runmethod, the member agent will have access to thesession_stateanddependenciesthrough therun_contextparameter.Now let me summarize the fix:
Summary of Changes:
The bug was that when
team.acontinue_run(dependencies=session_state, ...)is called, thesession_stateis not passed to the member agents when they continue their run. This causes tools executed by the member agent to not have access to or .- If
Assistant
The tool call is having issues. Let me try a simpler command.
Assistant
The fix is complete. Let me submit it now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.