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
Additional Context
No response
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /agno, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files.
- Assistant
Let me explore the structure more systematically.
- Assistant
Let me explore the libs directory to find the agno package.
- Assistant
Let me explore the agno package structure.
- Assistant
Now let me look at the issue mentioned in the bug report - the
_aroute_requirements_to_members_streamfunction in_run.py. Let me first check what line 5145 contains: - Assistant
Let me look at the function mentioned in the issue:
_aroute_requirements_to_members_streamaround line 5145. - Assistant
Let me see more context around this function. Let me search for the function name:
- Assistant
Let me see the full function definition:
- Assistant
Now let me look at the
acontinue_runmethod in the Team class: - Assistant
Let me look at the acontinue_run method in team.py.
- Assistant
Now let me look at
acontinue_run_dispatchin_run.py: - Assistant
Let me check the acontinue_run_dispatch function.
- Assistant
Let me see more of this function and then look at
_acontinue_run_stream: - Assistant
Now let me look at
_acontinue_run_stream: - Assistant
Let me look at the
_acontinue_run_streamfunction. - Assistant
Let me look at the RunContext class to understand the structure:
- Assistant
Let me check the RunContext class.
- Assistant
Now let me look at how the initial
arunhandlessession_state: - Assistant
Let me check the arun method to see how it handles session_state.
- Assistant
Let me look at how
arun_dispatchhandlessession_state: - Assistant
Let me check the arun_dispatch function.
- Assistant
Now let me look at
_aroute_requirements_to_members_streammore carefully to see how it calls memberacontinue_run: - Assistant
Let me look at the
member.acontinue_run()call in the function to see what parameters are being passed: - Assistant
Now I can see the issue! In
_aroute_requirements_to_members_stream, when callingmember.acontinue_run(), therun_contextis not being passed. Let me also check the synchronous version: - Assistant
Let me check the synchronous version to see if it has the same issue:
- Assistant
Now I can see the issue. In both
_aroute_requirements_to_members_streamand_route_requirements_to_members_stream, when callingmember.acontinue_run()ormember.continue_run(), therun_context(which containssession_stateanddependencies) is NOT being passed. Let me also check the non-streaming versions: - Assistant
Let me check the non-streaming versions too:
- Assistant
Let me also check the async non-streaming version:
- Assistant
Let me check the async non-streaming version:
- Assistant
Now I understand the issue clearly. In all four
_route_requirements_to_members*functions, when callingmember.continue_run()ormember.acontinue_run(), they don't passrun_context. This means that when the member agent executes a tool that needs access tosession_stateordependencies, it won't have them. Let me also check thecontinue_runmethod signature in agent.py: - Assistant
Let me check the agent's continue_run method to see if it accepts run_context:
- Assistant
Let me check the agent's acontinue_run method signature:
- Assistant
Now I understand the issue! The
run_context(which containssession_stateanddependencies) is not being passed to the member agents when routing requirements. Let me also check thecontinue_run_dispatchfor sync version: - Assistant
Let me also check the
acontinue_runsignature on the team: - Assistant
Now I have a clear picture of the issue. Let me also check if there's a
session_stateparameter on the teamacontinue_run(the user example usessession_state): - Assistant
Now I need to understand the full picture. Let me also check how the initial
arunsets up the session state and how it gets stored: - Assistant
Let me look at how
adelegate_task_to_memberpasses context to member agents during normal runs: - Assistant
Let me find where
adelegate_task_to_memberis defined to see how it passes context. - Assistant
Let me search in the _task_tools.py file instead.
- Assistant
Let me search more broadly.
- Assistant
Let me look at
adelegate_task_to_memberto see how it passes dependencies/session_state: - Assistant
Now I can see the fix needed. In
adelegate_task_to_member, the code properly passesrun_context.session_state,run_context.dependencies, etc. to the member agent. But in_aroute_requirements_to_members_stream, therun_contextis not being passed tomember.acontinue_run().Let me now look at how
acontinue_run_dispatchinitializes therun_contextwhen a session already exists (thesession_statemay need to be loaded from storage): - Assistant
Let me look at
_asetup_sessionto understand how session_state is loaded: - Assistant
Now let me understand the flow. When
acontinue_run_dispatchcreates theRunContext, it setssession_state={}. But the user passesdependencies=session_state. The issue is that when routing to member agents in_aroute_requirements_to_members_stream, therun_context(which hasdependenciesandsession_state) is NOT being passed. Let me verify this by looking at theacontinue_run_dispatchfunction more carefully: - Assistant
Let me also check how
_acontinue_run_streamis called and how it usesrun_context: - Assistant
Now I understand the complete picture. The issue is that in
_aroute_requirements_to_members_stream(and its sync counterpart), therun_context(which containssession_stateanddependencies) is NOT being passed to the member agent'sacontinue_run()call. Therun_contextis properly passed to the function, but not forwarded to the member agent.Let me also check how this is done in the
adelegate_task_to_memberfunction to understand the correct pattern: - Assistant
Now I have a clear understanding of the issue. Let me create a simple test to verify the bug:
- Assistant
The test confirms the issue. When
_aroute_requirements_to_members_streamcallsmember.acontinue_run(), it does NOT passrun_context,dependencies, orsession_state. This is the root cause of the bug.Now let me fix all four routing functions. I need to pass
run_contextto the member'scontinue_run()/acontinue_run()calls. Let me first fix the async streaming version: - Assistant
Now let me apply the fix. I'll edit
_aroute_requirements_to_members_streamto passrun_contextto member'sacontinue_run(): - Assistant
Now let me fix the first
member.acontinue_run()call to passrun_context: - Assistant
Now let me fix the second
member.acontinue_run()call (the else branch): - Assistant
Now I need to fix the sync streaming version
_route_requirements_to_members_stream: - Assistant
Now let me fix the sync streaming version. First the
run_responsebranch: - Assistant
Now let me fix the sync streaming version:
- Assistant
Now I need to also fix the non-streaming versions. Let me look at
_aroute_requirements_to_members(async non-streaming): - Assistant
Now let me fix the async non-streaming version. First the
run_responsebranch: - Assistant
Now let me fix the async non-streaming version:
- Assistant
Now I need to fix the sync non-streaming version
_route_requirements_to_members: - Assistant
Now let me fix the sync non-streaming version:
- Assistant
Now let me fix the sync non-streaming version:
- Assistant
Now let me also check the
acontinue_run_dispatchto see if we need to fix thesession_stateinitialization there. Let me look at howsession_stateis handled: - Assistant
Let me look at the RunContext creation in acontinue_run_dispatch:
- Assistant
Let me check how the session_state is handled in
acontinue_run_dispatch. I need to look at the code that initializes the run_context there. - Assistant
Now I need to also look at the
acontinue_run_dispatchfunction. I see thatsession_state={}is initialized as empty. This means that when a team run continues, the session state from the initialaruncall isn't being loaded. Let me check how_asetup_sessionhandles session state loading. - Assistant
Now let me run the test again to verify the fix:
- Assistant
Let me fix the test script:
- Assistant
Let me find the correct import path for RunOutput
- Assistant
Let me fix the test script with the correct import.
- Assistant
The async streaming fix is working. Now let me verify the sync streaming fix:
- Assistant
Now let me verify the non-streaming async version:
- Assistant
Now let me verify the sync non-streaming version:
- Assistant
Now I need to also address the second part of the issue. Looking at
acontinue_run_dispatch, I see that whenrun_contextis created,session_state={}. But the user passesdependencies=session_state. This means that:run_context.session_statestarts as{}run_context.dependenciesgets set to the user'ssession_statedict- When
_asetup_sessionis called, it loads session_state from the database
The issue is that the user's
session_statedict is passed asdependencies, not assession_state. But the tool accessesrun_context.session_state["user_token"]. Let me check if we also need to handle thesession_stateparameter inacontinue_run_dispatch: - Assistant
Now let me also check how the session_state is loaded in
_asetup_session: - Assistant
Let me check how the session_state is loaded:
- Assistant
Now let me check how
_acontinue_run_streamcalls_asetup_sessionand when_aroute_requirements_to_members_streamis called relative to it: - Assistant
Good, I can see that
_asetup_sessionis called before_aroute_requirements_to_members_stream, which means thesession_stateshould be loaded from the DB. But there might be a second issue - the user'ssession_stateis passed asdependencies, notsession_state. Let me also check if we need to handle thesession_stateparameter inacontinue_run_dispatch: - Assistant
Now I need to understand the second part of the issue. The
acontinue_runmethod doesn't have asession_stateparameter. Let me check if we need to add it: - Assistant
Now let me also check the
_acontinue_runnon-streaming version to see if it also routes to members: - Assistant
Let me check how
_aroute_requirements_to_membersis called to make sure it passesrun_context: - Assistant
Let me also check the sync non-streaming call site:
- Assistant
Let me check the call site for the sync non-streaming version:
- Assistant
Good. Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
Let me find tests related to team or continue_run:
- Assistant
Let me look for unit tests related to team or continue_run.
- Assistant
Let me run the unit tests related to team continue_run:
- Assistant
All tests pass. Let me also run the other team tests:
- Assistant
The 2 failures are pre-existing and related to SQLite/Postgres DB configuration, not related to my changes. Let me also run the background stream test:
- Assistant
Let me also check if there's a sync version of the streaming dispatch that needs fixing:
- Assistant
Let me also check the sync
continue_run_dispatchto see if it has the samesession_state={}issue: - Assistant
Let me see how the sync
continue_run_dispatchcreates the RunContext: - Assistant
I see the sync version properly loads
session_statefrom the DB. Now let me verify the final state of all the fixes I've made by looking at the git diff: - Assistant
Let me see the full diff to verify all the changes:
- Assistant
The diff looks clean. Let me run the full unit test suite to ensure nothing is broken:
- Assistant
The errors are due to missing dependencies, not my changes. Let me run just the team tests and agent tests to verify:
- Assistant
All failures are pre-existing (DB configuration tests failing). Let me also run the workflow tests:
- Assistant
Let me run the specific workflow HITL tests:
- Assistant
The failures are all pre-existing - related to missing
sqlalchemymodule or DB config issues, not my changes. Let me clean up the temporary test files: - Assistant
Let me also check if there's a
_acontinue_run_background_streamfunction that also needs the same fix: - Assistant
Let me check if the background stream function also routes to members:
- Assistant
The background stream function calls
_acontinue_run_stream, which in turn calls_aroute_requirements_to_members_stream. My fix covers this case.Now let me also check if there's an issue with the
session_statenot being loaded properly in the async path. Looking at the issue description again, the user mentions that therun_contexthas not been restored. Let me check if we need to also passsession_statethrough toacontinue_run_dispatch: - Assistant
The fix is complete. Let me now create a final comprehensive test to verify the fix:
- Assistant
All tests pass. Let me clean up and run the existing tests one more time:
- Assistant
All 55 tests pass. Let me now verify my checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →