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 and the code path mentioned in the issue around
_aroute_requirements_to_members_streamandacontinue_run. - Assistant
Let me look at the specific file mentioned in the issue and search for acontinue_run related code.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me search for acontinue_run and the specific function mentioned around line 5145.
- Assistant
Let me examine
_aroute_requirements_to_members_streamand related functions. - Assistant
Comparing with non-stream routing and how members receive run_context.
- Assistant
Checking agent continue_run signatures and how run_context is restored.
- Assistant
Let me look at the agent acontinue_run and how team's acontinue_run passes things. Also looking at how team's acontinue_run handles session_state and dependencies.
- Assistant
Looking at how team's acontinue_run sets up run_context and whether it gets passed to routing.
- Assistant
Checking team's acontinue_run signature and how session_state is handled in continue flow.
- Assistant
Checking how member agents receive run_context during normal runs vs continue.
- Assistant
Let me look at how members are called during regular arun/run (delegate), specifically for passing session_state.
- Assistant
Hmm, the _tools.py might delegate through a different mechanism. Let me search more broadly.
- Assistant
Inspecting how member runs get session_state, and comparing continue_run paths.
- Assistant
Looking at how
_acontinue_runand_acontinue_run_streamload session state. - Assistant
Let me continue reading to see where _aroute_requirements is called and how session_state is loaded in _asetup_session.
- Assistant
Checking how agent's acontinue_run uses run_context and session_state.
- Assistant
Let me look at agent acontinue_run_dispatch
- Assistant
Let me continue reading acontinue_run_dispatch for how run_context is built
- Assistant
Understanding how member agents share session state with the team.
- Assistant
Checking related tests and git history for previous similar fixes.
- Assistant
Let me look at unit tests for continue_run_requirements and also check git blame around the routing functions. Also check if agent version of continue from team members handled this before.
- Assistant
Let me read the routing tests in this unit test file.
- Assistant
Let me look at TestAsyncGatherErrorHandling and also the code around line where website run_context is passed to refresh/determine tools etc in continue_run path.
- Assistant
Checking if continuing members merges session_state back and how cerrado similar agent-level codelooks.
- Assistant
Checking the RunContext class structure.
- Assistant
Let me read the RunContext class
- Assistant
Looking at how session_state is typically shared - delegates use
copy(run_context.session_state)and then merge back. For continue without merge back, sharing the same dict might actually be better ... - Assistant
Checking whether session_state is persisted when the team pauses.
- Assistant
Let me read the pause handlers to see if run_context.session_state is saved.
- Assistant
Let me check cleanup_and_store for how session_state is saved.
- Assistant
Also looking at continue_run_dispatch around line 5404 for how it sets up run_context:
- Assistant
Checking if in-memory sessions are cleared on initialize_team.
- Assistant
Let me check read_or_create_session without DB.
- Assistant
Checking how agent continue registers runs.
- Assistant
Checking
_initialize_session_stateto understand run_id usage. - Assistant
I'll implement the fix across all four routing functions by passing
run_contextinto member continue calls. - Assistant
I'll create a helper function to build member run_context的, and use it in all four places. Or simply pass run_context and dependencies. I understand the issue you're facing with
team.acontinue_runlosing dependencies orsession_statein member tools. The problem stems from howRunContextis restored in_aroute_requirements_to_members_stream(and similar methods), where the session state isn't properly propagated to member agents.To fix this, I'll implement a helper function to build the
RunContextfor members, ensuring dependencies and session_state are preserved. I'll also update the calls toacontinue_runto pass therun_contextcorrectly.Here's the plan: 1.
- Assistant
Now I'll implement the fix by adding a helper and updating all four routing functions.
- Assistant
Adding a helper and updating all four route functions to pass restored run_context.
- Assistant
Updating
_route_requirements_to_membersto pass the member run context. - Assistant
Updating the sync streaming route function.
- Assistant
I'll update the stream version now.
- Assistant
Updating the async non-streaming route function.
- Assistant
Update _aroute_requirements_to_members
- Assistant
Removing the duplicate comment and updating the async stream function.
- Assistant
Updating the async stream routing function next.
- Assistant
Update _aroute_requirements_to_members_stream
- Assistant
I should also check if acontinue_run_dispatch properly loads session_state. Looking at earlier code - it starts with empty session_state and relies on _asetup_session. That's fine for when user had se...I think the core issue is that
acontinue_run(and the underlying dispatch) doesn't properly restoresession_statefrom the team's persisted context when the user passesdependencies=session_stateas a workaround. The tool code expectsrun_context.session_state["user_token"], but the streaming path loses the team session'ssession_stateafter the pause (especially without DB, or even with DB if_cached_sessionis cleared). - Assistant
Interesting - looking at my earlier grep result:
- Assistant
Let me check line 402 in _init.py
- Assistant
Writing a temporary script to verify that run_context is forwarded, and running related unit tests.
- Assistant
Running unit tests for continue_run requirements.
- Assistant
Checking whether agent cleanup strips transient keys from the shared session_state.
- Assistant
The path might be different - list dir
- Assistant
I'm in libs/agno already.
- Assistant
Updating the helper to copy session_state like delegate does, and merging back after member continue.
- Assistant
Need full path or relative from cwd.
- Assistant
Using a session_state copy per member (required for concurrent async) and merging changes back after continue.
- Assistant
Confirming
merge_dictionariesimport path, then adding merge calls after each member continue. - Assistant
Adding merge-after-continue in all four route functions.
- Assistant
Let me update each function carefully to merge after continue.
- Assistant
I'll add merge after member_response_handling and before.clear for all 4.
- Assistant
Now stream version - after the stream loop and_before clear.
- Assistant
Add merge to stream version
- Assistant
There's a duplicate
)on line 5068 - I made an error when editing. Let me fix that. - Assistant
Good. Now fix async non-stream version.
- Assistant
Add merge for async non-stream and async stream
- Assistant
Now async stream version.
- Assistant
Add merge for async stream
- Assistant
Re-running verification and unit tests.
- Assistant
Verifying None run_context still works, then reviewing the final diff.
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 →