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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now let me look at the
_acontinue_run_streamfunction to see the full context and whererun_contextis created:Assistant
Now let me look at the
acontinue_run_dispatchfunction to understand how the run_context is initialized:Assistant
Now let me look at the
_asetup_sessionfunction to understand how the run_context is used:Assistant
Now let me find the corresponding sync version
continue_run_dispatchto see how it correctly handles this:Assistant
Now let me look at how the continue_run_dispatch passes the run_context:
Assistant
Now let me understand the issue. The user reported that in
_aroute_requirements_to_members_stream, therun_contextis not being passed properly. Let me look at the originalarunandarun_streamfor comparison:Assistant
Now I can see how
adelegate_task_to_membercorrectly passessession_state,dependencies, etc. to themember_agent.arun(...)call. Let me look at the_aroute_requirements_to_members_streamagain carefully:Assistant
Now let me check the
acontinue_runmethod on the agent to see how it can acceptdependencies,session_state, etc.:Assistant
Now I understand. The
acontinue_runmethod on a member agent acceptsrun_contextas a parameter. So the issue is in_aroute_requirements_to_members_streamand_aroute_requirements_to_members(also probably the sync version) whererun_contextis not being passed tomember.acontinue_run(...).Let me also check the sync version's
continue_runmethod to confirm:Assistant
Now let me see how the agent's
aruncorrectly passes dependencies. Let me look at the agent's run method (which would be the equivalent for non-HITL flow):Assistant
Now I understand. The
aruncalls do passsession_stateanddependenciesfrom therun_context, but theacontinue_runcalls in_aroute_requirements_to_members_streamand_route_requirements_to_members_stream(and probably sync versions too) do not.Let me look at the sync version
_route_requirements_to_members_streammore carefully:Assistant
Now let me also look at the non-streaming version
_route_requirements_to_members:Assistant
Now let me also check the async non-streaming version
_aroute_requirements_to_members:Assistant
Now I see the pattern. In
_aroute_requirements_to_members_stream,_aroute_requirements_to_members,_route_requirements_to_members, and_route_requirements_to_members_stream, the call tomember.continue_run()/member.acontinue_run()does NOT pass therun_context.The fix should pass
run_contextto these calls. Let me first verify the agent'sacontinue_runmethod acceptsrun_context:Assistant
Now let me check the agent's
arunto see how it usesrun_context:Assistant
Good, the
arun_dispatchof agent also supports passingrun_context. Now let me also check how_propagate_member_pauseworks and how_aroute_requirements_to_members_streamshould pass therun_context. First, let me understand the flow better by looking at a few more functions:Assistant
Now let me reproduce the issue first to understand it better. Let me first look at the existing tests to understand patterns:
Assistant
Let me see the actual run.py content to understand what
_aroute_requirements_to_members_streamdoes and howrun_contextis needed. Let me also see whatagent.acontinue_rundoes withrun_context:Assistant
Now I understand. The agent's
_acontinue_run_streamusesrun_contextto know aboutsession_stateanddependencies. So when we callmember.acontinue_run(...)from_aroute_requirements_to_members_streamand don't pass therun_context, the agent'sacontinue_run_dispatchwill create a newrun_contextwith empty session state and dependencies.Let me also check
acontinue_run_dispatchonce more:Assistant
Good. Now I have full clarity. The fix is to pass
run_contextto themember.continue_run/member.acontinue_runcalls in:_route_requirements_to_members(sync, non-streaming)_route_requirements_to_members_stream(sync, streaming)_aroute_requirements_to_members(async, non-streaming)_aroute_requirements_to_members_stream(async, streaming)
Now let me reproduce the issue first. Let me set up a simple reproduction:
Assistant
Now let me write a reproduction script:
Assistant
Now let me look at the existing tests for confirmation flows to understand the test pattern:
Assistant
Let me look for tests of
_aroute_requirements_to_membersor similar:Assistant
Now let me create a small reproduction script to confirm the issue:
Assistant
It's imported locally. Let me update the script:
Assistant
I need to make the mock return an async iterator, not a coroutine. Let me fix:
Assistant
I've reproduced the issue. The
member.acontinue_runcall is not receiving therun_context. Now let me fix the code. I need to pass therun_contextto all 4 functions:_route_requirements_to_members(sync, non-streaming)_route_requirements_to_members_stream(sync, streaming)_aroute_requirements_to_members(async, non-streaming)_aroute_requirements_to_members_stream(async, streaming)
Let me start by applying the fix to
_aroute_requirements_to_members_stream:Assistant
Now let me see how the existing arun() pattern works (which DOES pass session_state, dependencies):
Assistant
Now let me apply the fix. The cleanest approach is to pass
run_contexttomember.acontinue_run(). Let me start with_aroute_requirements_to_members_stream:Assistant
Now let me apply the fix. I'll add
run_context=run_contextto both calls in_aroute_requirements_to_members_stream:Assistant
Now let me apply the fix to
_aroute_requirements_to_members_stream:Assistant
Now let me apply the same fix to the async non-streaming version
_aroute_requirements_to_members:Assistant
Now let me apply the same fix to the sync versions:
Assistant
Now let me apply the fix to the sync streaming version
_route_requirements_to_members_stream:Assistant
Now let me verify all the changes:
Assistant
Let me verify each one of these has
run_context=run_context:Assistant
All 8 calls now have
run_context=run_context. Now let me run the reproduction script to confirm the fix:Assistant
The fix is working. Now let me write a more comprehensive test to verify all 4 routing functions pass the
run_context:Assistant
I need to be more careful with the mock. The
acontinue_runshould not be a coroutine but should return either a coroutine (for non-streaming) or an async iterator (for streaming). Let me fix the test:Assistant
The issue is that the
async_continue_runreturns a coroutine for stream=True case (because of the inner function). Let me simplify:Assistant
It seems my test is only catching the sync version's calls. Let me investigate why my mock wasn't called by the async versions:
Assistant
The fix works correctly for
_aroute_requirements_to_members_stream. The earlier test issue was the mock construction - the issue is that when I domember.acontinue_run = make_async_continue_run(captured_kwargs_list), the function returns a coroutine (since it hasawait). But for streaming, the function should return an async iterator. Let me run a cleaner test:Assistant
The issue is that
acontinue_runfor streaming returns a coroutine containing the async iterator. Let me look at howacontinue_runis defined for streaming. Looking back at the_aroute_requirements_to_members_streamcode, the call is:member_response_stream = member.acontinue_run(...) async for event in member_response_stream:So when
member.acontinue_run()is called withstream=True, the result should be directly an async iterator (not a coroutine).The issue is that the actual
acontinue_runmethod on anAgentreturns a generator-like object via the_acontinue_run_streamfunction which is decorated withAsyncIterator. Let me look more carefully:Assistant
OK, so when
stream=True, the agent'sacontinue_runreturns anAsyncIterator. So when the team callsmember.acontinue_run(stream=True, ...), the result is an AsyncIterator directly. My mock needs to return an AsyncIterator directly, not a coroutine.Let me make the test mock simpler by having two separate methods - one for stream=True and one for stream=False:
Assistant
All 4 routing functions correctly pass
run_contextwithsession_stateanddependencies. Now let me also look at the case wheremember_run_output is None- that usesrun_idto look up the run, which we also covered. But let me also verify by looking at the case:Assistant
The fallback case also works. Now let me also check if there's a similar issue elsewhere by searching for any other
continue_runcalls in the codebase that should passrun_context:Assistant
Let me also check
os/interfaces/slack/hitl.pysince it's similar context:Assistant
This is a top-level acontinue_run call from an external system, so it's not relevant.
Let me also check the team/team.py file for any other places that might call continue_run:
Assistant
Now let me run the existing tests to make sure nothing is broken:
Assistant
All 49 unit tests pass. Let me also run other tests related to the routing:
Assistant
These are integration tests that need API keys. Let me check what tests exist that don't require API keys:
Assistant
These 3 failures are unrelated to my changes (they're about sqlite db and skills snippets). Let me check that my changes haven't broken anything specific by running tests directly related to continue_run:
Assistant
All 55 tests pass. Now let me also run the agent tests for continue_run:
Assistant
All agent run regression tests pass. Let me also look at the team flow more carefully. I want to verify my understanding is correct by checking the flow once more. Let me re-read the issue:
The user says:
- They have a team with a member agent
- The member agent has a tool
group_del_stockthat usesrun_context.session_state["user_token"] - They use
acontinue_runafter confirming a paused run - But
session_state["user_token"]is None
The root cause is that the team was passing
session_statetoteam.arun(...), but whenacontinue_runwas called, the team didn't pass therun_contextto the member'sacontinue_run(). So the member agent would create a freshRunContextwith emptysession_state(loaded from the DB only).Wait, actually, the agent's
_acontinue_run_streamDOES loadsession_statefrom the DB in line 4313:run_context.session_state = load_session_state( agent, session=agent_session, session_state=run_context.session_state if run_context.session_state is not None else {}, )So even if
session_stateis empty, it should be loaded from DB. But the issue isdependencies, which is NOT loaded from DB. Let me verify:Assistant
OK, so
session_stateis loaded from the database. Butdependenciesis NOT stored in the database, it's runtime only. So if the user is passingdependencies={"user_token": "Bearer ..."}toteam.arun(...), and then callingteam.acontinue_run(dependencies=session_state), the dependencies would not be loaded from DB.The user's example code uses
dependencies=session_statewhich is just the dict{"user_token": "Bearer "}. So when they callacontinue_run(dependencies=session_state), that dict goes intorun_context.dependencies, but then when the member'sacontinue_runis called, the member gets a freshrun_contextwithdependencies=None.Now with my fix, the
run_contextis passed through, so the member agent'sacontinue_runwill receive thedependenciesfrom the team'srun_context.Let me also check that the issue isn't in another layer - specifically, in the
_aroute_requirements_to_members_streamcalling pattern. Let me also look at if there's a way therun_contextmight need to be modified before being passed:Assistant
Let me see how the agent's acontinue_run_dispatch handles an existing run_context to make sure passing it doesn't break anything:
Assistant
Good, the agent's
acontinue_run_dispatchwill use the providedrun_contextif it exists. So passing ourrun_contextfrom the team is fine.Now let me also verify the issue is indeed resolved by running an actual integration-style test:
Assistant
The issue is resolved. Let me also verify with the issue's actual scenario - where the user uses
team.arun(session_state=...)and thenteam.acontinue_run(dependencies=session_state).Let me trace through the flow:
-
team.arun(input="...", session_state={"user_token": "Bearer"})- This creates a
run_contextwithsession_state={"user_token": "Bearer"} - When delegating to member agent,
member_agent.arun(session_state=copy_of_run_context.session_state)is called - So the member has the session_state
- This creates a
-
During execution, the member calls
group_del_stock(...)which usesrun_context.session_state["user_token"]- The tool execution pauses for confirmation
-
User calls
team.acontinue_run(dependencies=session_state)- The team's
acontinue_run_dispatchcreates a newrun_contextwithdependencies=session_state(which is{"user_token": "Bearer"}) - Then it routes to the member's
acontinue_run - BEFORE FIX: The member's
acontinue_runis called WITHOUTrun_context, so it creates a freshRunContextwith nodependencies(and emptysession_statefrom DB) - AFTER FIX: The member's
acontinue_runreceives the team'srun_contextwithdependencies={"user_token": "Bearer"}
- The team's
Now let me also write a test that simulates the actual end-to-end flow (without actual LLM calls):
-
Assistant
Let me fix the test:
Assistant
The fix is verified end-to-end. The
run_contextwith bothsession_stateanddependenciesis now correctly passed to the member agent'sacontinue_run.Now let me also check the case where the user calls the function via the team's
acontinue_rundirectly. Let me also look at how the issue would manifest if there's a member agent that calls another team. The_find_member_route_by_idfunction returns a tuple with the path. Let me look at it:Assistant
Now I want to also check the case where the member is itself a Team. In that case,
member.acontinue_runwould be the team'sacontinue_run, which already acceptsrun_context. So the fix should work for nested teams too.Let me look at the team class to confirm:
Assistant
Both Agent and Team accept
run_contextin theiracontinue_runmethod. So my fix works for both.Now let me look at what other tests might be affected. Let me also run a quick sanity check on all the tests:
Assistant
All 347 tests pass. Let me also run the agent tests to make sure I didn't break anything:
Assistant
Only the 2 unrelated sqlite/postgres db tests fail. These are not related to my changes.
Let me also check that the workflow tests pass:
Assistant
This is a missing dependency, unrelated to my changes. Let me skip those:
Assistant
These are also due to missing sqlalchemy. They're not related to my changes. Let me also check the
osfolder:Assistant
Also unrelated to my changes. Now let me look at the test_run_regressions.py to see if there's a pattern I can use to add a regression test:
Assistant
Let me check the existing tests in
test_team_run_regressions.py:Assistant
Now let me also look at one of those tests to understand the pattern:
Assistant
Now let me also think about edge cases. What about when the member is a sub-Team? Let me see how that works:
Assistant
OK, so when a member is a sub-Team, it returns the sub-team and the sub-team's
acontinue_runis called, which would also receive therun_contextcorrectly with my fix.Let me also confirm my changes are syntactically correct by re-checking the file:
Assistant
All 4 functions still accept
run_context. Now let me verify the code compiles correctly:Assistant
Let me also see the full diff of my changes:
Assistant
The changes are clean and minimal - just adding
run_context=run_contextto all 8 calls (2 in each of the 4 functions). Let me also verify the whole file still loads and the tests still pass:Assistant
All 67 tests pass. Now let me also run the full agent test suite to be safe:
Assistant
All 339 tests pass. Now let me also look at one more edge case. Let me check the actual call patterns when
member_run_outputis None (fallback case) - I want to make sure the run_context is also passed in the fallback path.Let me also check if there are integration tests for dependencies passing through:
Assistant
No existing tests for this scenario. Let me also verify the cleanup - remove temp files:
Assistant
Let me run the reproduction script once more to make sure everything works:
Assistant
Let me also check what happens when
run_context=Noneis passed to the agent'sacontinue_run_dispatch:Assistant
Good. The
acontinue_run_dispatchhandles therun_context=Nonecase by creating a newRunContextwith appropriate defaults. So passingrun_context=Noneis safe.Now let me also clean up the reproduction script:
Assistant
Now let me also do a final check of the diff:
Assistant
The changes are minimal - 8 lines added, one for each of the 8
continue_run/acontinue_runcalls in the routing functions.Let me also do one final comprehensive check by reviewing the diff:
Assistant
The diff is clean and focused. Now let me address the checklist:
Checklist Review:
-
If an error was reported in the issue description, I have successfully reproduced it.
- ✅ I reproduced the issue by creating a script that calls
_aroute_requirements_to_members_streamand verified that therun_contextwas NOT being passed to the member'sacontinue_run()call.
- ✅ I reproduced the issue by creating a script that calls
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- ✅ After applying the fix, the same reproduction script confirms that
run_contextis now correctly passed withsession_stateanddependencies.
- ✅ After applying the fix, the same reproduction script confirms that
-
I have thought about edge cases and made sure my fix handles them as well.
- ✅ I considered:
- The fallback case (when
member_run_output is Noneandrun_idis used) - both calls in each function have the fix - All 4 routing functions (sync/async × stream/non-stream) are fixed
- The case where
run_context=None(the agent'sacontinue_run_dispatchhandles this) - When the member is a sub-Team (Team.acontinue_run also accepts run_context)
- The fallback case (when
- ✅ I considered:
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- ✅ I ran the following tests, all pass:
tests/unit/team/test_continue_run_requirements.py(49 tests)tests/unit/team/test_acontinue_run_background_stream.py(6 tests)tests/unit/team/test_team_run_regressions.py(12 tests)tests/unit/agent/test_run_regressions.py(29 tests)- All other unit/team/agent tests except 2 unrelated sqlite/postgres db tests
- ✅ I ran the following tests, all pass:
Let me submit the changes:
-
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 →