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
I'll start by exploring the repository to understand the structure and locate the relevant code. First, let me check the current directory and see what's available.
- Assistant
Let me look at the specific file mentioned in the issue: libs/agno/agno/team/_run.py line 5145. First, let's find that file.
- Assistant
Good, I found the file. Let me also look at the issue description more carefully. The issue is about
team.acontinue_runlosing dependencies or session_state. The user says that when usingacontinue_run, the dependencies or session_state are not properly restored in the run_context.The issue points to line 5145 of
_run.pyand mentions_aroute_requirements_to_members_stream. Let me examine the file to understand the problem. First, let me open the file and look at the relevant section. Let's search foracontinue_runand_aroute_requirements_to_members_stream. - Assistant
Let me look at the
_aroute_requirements_to_members_streamfunction around line 5145 as mentioned in the issue. - Assistant
Now let me check the
acontinue_runmethod of Team to understand how it's called and how it passes dependencies/session_state. - Assistant
It seems
acontinue_runis not a direct method but is dispatched. Let me look at the Team class to find theacontinue_runmethod. Let me search more broadly. - Assistant
Let me check the Team.acontinue_run method to see if it's passing dependencies/session_state properly to the underlying implementation.
- Assistant
Now let me look at the
acontinue_run_dispatchfunction to see how it handles dependencies: - Assistant
Now let me look at
_acontinue_run_streamto see how it passesrun_contextto_aroute_requirements_to_members_stream: - Assistant
Let me look at the
_acontinue_run_streamfunction to see how it passesrun_contextto_aroute_requirements_to_members_stream. - Assistant
Now I can see the issue. Let me look at the
_aroute_requirements_to_members_streamfunction again and specifically look at lines around 5145 to understand the problem:The issue is in
_aroute_requirements_to_members_stream. When it callsmember.acontinue_run(), it's not passing therun_contextfrom the team level. This means the member agent'srun_contextwon't have thedependenciesorsession_statethat was passed to the team'sacontinue_run.Let me look at the actual lines around 5145 and see the full function:
- Assistant
Now I see the problem! In
_aroute_requirements_to_members_stream, when callingmember.acontinue_run(), it's not passing therun_contextparameter. This means the member agent won't have access to therun_contextthat was created inacontinue_run_dispatchwhich contains thedependenciesandsession_state.Let me check what the
run_contextparameter is used for inmember.acontinue_run(). Let me also look at the agent'sacontinue_runmethod to see if it accepts arun_contextparameter.Let me search for the agent's acontinue_run method:
- Assistant
Let me look at the sync counterpart
_route_requirements_to_membersto see if it passesrun_context: - Assistant
Let me check the non-streaming async version
_route_requirements_to_members(not the stream one): - Assistant
Now I understand the issue. Let me look at the member's
acontinue_runmethod on the Agent class: - Assistant
Let me search for
def acontinue_runon the Agent class. - Assistant
Let me check the Agent's acontinue_run method signature:
- Assistant
Now let me look at the
_aroute_requirements_to_members_streamfunction more carefully to see what's passed tomember.acontinue_run: - Assistant
Now I understand the issue! In
_aroute_requirements_to_members_stream, when callingmember.acontinue_run(), it doesn't pass therun_contextparameter. Therun_contextcontainsdependenciesandsession_state, which are needed by the member agents.The fix should be to pass the
run_contextparameter when callingmember.acontinue_run()in_aroute_requirements_to_members_stream.Let me also check the non-streaming version
_route_requirements_to_membersto see if it has the same issue. - Assistant
Yes, the sync version also doesn't pass
run_context. Let me check the_route_requirements_to_members_stream(sync streaming version) too. - Assistant
Let me look at the rest of the
_aroute_requirements_to_membersfunction: - Assistant
Now I understand the issue. In
_aroute_requirements_to_members_streamand other routing functions, therun_context(which containsdependenciesandsession_state) is received as a parameter but not passed through to the member'sacontinue_runcall. Let me check all four routing functions. - Assistant
Now I have a clear understanding of the issue. All four routing functions receive
run_contextbut don't pass it to the member'scontinue_runoracontinue_runcalls. This means the member's dependencies and session_state are lost.Let me also check how
adelegate_task_to_memberhandles this: - Assistant
Let me search for "delegate_task_to_member" functions
- Assistant
Let me look at how delegate_task_to_member works to understand how it passes run_context. Let me search for the delegate_task_to_member function.
- Assistant
Let me look at the team
_tools.pyto understand the delegate flow: - Assistant
Let me search more broadly for delegate functions in the team module.
- Assistant
Now I understand the issue. Looking at the code:
- In
_aroute_requirements_to_members_stream(line 5110),run_contextis received as a parameter - When calling
member.acontinue_run()(lines 5171 and 5180), therun_contextis NOT passed to the member'sacontinue_runcall - The same issue exists in the non-streaming variant
_aroute_requirements_to_members(lines 5069, 5075)
The fix is to pass
run_context=run_contextwhen calling member.acontinue_run() in these functions.Let me also check the sync counterparts to see if they have the same issue:
- In
- Assistant
Now I have a clear picture of the issue. There are 4 functions that route requirements to member agents, and all of them receive
run_contextbut don't pass it to the member'scontinue_run/acontinue_runcalls. Let me also look at the sync versions: - Assistant
Now I have a clear understanding of the issue. The problem is in four functions that route requirements to member agents:
_route_requirements_to_members(sync, non-streaming) - lines 4870, 4877_route_requirements_to_members_stream(sync, streaming) - lines 4959, 4968_aroute_requirements_to_members(async, non-streaming) - lines 5069, 5075_aroute_requirements_to_members_stream(async, streaming) - lines 5171, 5180
All four functions receive
run_contextas a parameter but don't pass it to the member'scontinue_run/acontinue_runcalls. Let me first reproduce the issue, then create the fix.Let me first look at the sync streaming version too:
- Assistant
Let me see the full context of lines 4970-4980 for the sync streaming version:
- Assistant
Now I have a clear picture of the issue and the fix needed. I need to pass
run_context=run_contextto all the member'scontinue_run/acontinue_runcalls in all four functions. Let me also verify the fix is correct by looking at thecontinue_runmethod on the Agent class: - Assistant
Let me check the signature of
continue_runon the Agent class to make sure it acceptsrun_context: - Assistant
Good, both
continue_runandacontinue_runacceptrun_contextanddependenciesparameters. Now I'll apply the fix. The fix is to passrun_context=run_contextto allmember.continue_run()andmember.acontinue_run()calls in the four routing functions.Let me start with
_aroute_requirements_to_members_stream(the one mentioned in the issue): - Assistant
Now I'll add
run_context=run_contextto the firstmember.acontinue_run()call in_aroute_requirements_to_members_stream: - Assistant
Now I need to edit the second
member.acontinue_run()call in the same function (theelsebranch): - Assistant
Good, both
member.acontinue_runcalls in_aroute_requirements_to_members_streamnow passrun_context=run_context. Now let me also fix the non-streaming async version_aroute_requirements_to_memberswhich has the same issue: - Assistant
Now I'll edit the
_aroute_requirements_to_membersfunction. First call: - Assistant
Now let me fix the second call in
_aroute_requirements_to_members: - Assistant
Now let me also fix the sync versions. First
_route_requirements_to_members: - Assistant
Now let me fix the sync
_route_requirements_to_membersfunction: - Assistant
Now let me fix the second call in
_route_requirements_to_members: - Assistant
Now let me fix the sync streaming version
_route_requirements_to_members_stream. Let me look at the relevant lines: - Assistant
Now let me fix the sync streaming version
_route_requirements_to_members_stream. First call: - Assistant
I see there's a duplicate line issue. Let me fix this:
- Assistant
I see the issue - there's a duplicate line and the structure is messed up. Let me fix this properly:
- Assistant
I see there's still an issue - the
member_response_streamline is missing a leading blank line before it. Let me check the exact context: - Assistant
The file looks correct now. Let me verify all the changes are correct by checking the diff:
- Assistant
The diff looks correct. All 8 call sites (4 functions × 2 branches each) now pass
run_context=run_contextto the member'scontinue_run/acontinue_runcalls. There's one minor whitespace change (removed a blank line in the sync streaming version), but that's just formatting and doesn't affect functionality.Let me now run the existing tests to make sure the changes don't break anything:
- Assistant
Let me check if there are tests related to continue_run:
- Assistant
Let me run the relevant unit tests to make sure the changes don't break anything:
- Assistant
All tests pass. Let me also run the other related test files:
- Assistant
Let me also run the test_run_context_precedence test:
- Assistant
Let me also run the team run regressions test:
- Assistant
All tests pass. Let me run a broader test to make sure I haven't broken anything:
- Assistant
Let me just run without the timeout flag.
- Assistant
The failure is unrelated to my changes - it's a missing postgres dependency. Let me confirm by checking if this test fails without my changes too:
- Assistant
Good, the test fails without my changes too. Let me restore my changes:
- Assistant
The failing test is pre-existing and unrelated to my change. Let me run all team unit tests excluding that one:
- Assistant
All 352 tests pass, 2 skipped. Now let me also check if there's a similar issue in the agent's
_run.pyfor thecontinue_run/acontinue_runflow. The issue specifically mentions team, but let me verify the agent flow is also handlingrun_contextproperly: - Assistant
Let me also check how
session_stateflows through the dispatch. The user example passessession_stateinarun()anddependenciesinacontinue_run(). Let me verify theacontinue_run_dispatchfunction handles this: - Assistant
Good. The
run_contextis properly set up inacontinue_run_dispatchwithdependencies. The issue is that when routing to members, therun_contextwas not passed to the member'sacontinue_runcall. My fix addresses this.Let me verify the final state of my changes one more time:
- Assistant
The fix is minimal and correct - 8 insertions (adding
run_context=run_contextto 8 call sites) and 1 deletion (an unnecessary blank line). Let me now verify the fix once more with the full diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.