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
Now let's find
acontinue_run_dispatchand_aroute_requirements_to_members_streamcall chain to see how run_context is built and passed down.Assistant
Good, so
_acontinue_runand_acontinue_run_streamdo call_asetup_session. Let's check those call sites at 6648 and 6989.Assistant
No
copyimport yet. Let's add it and add the helper function. First let's view the exact code around_route_requirements_to_members(line 4800-4810) to insert helper before it.Assistant
Now let's add the helper function right before
_route_requirements_to_members.Assistant
I accidentally duplicated the
_has_team_level_requirementsline. Let me fix that and add a blank line before_route_requirements_to_members.Assistant
Good, now let's add a blank line before
def _route_requirements_to_members(.Assistant
Now let's check syntax with python compile.
Assistant
Now let's update the four call sites (member.continue_run, member.acontinue_run) in each of the four routing functions to pass the built run_context.
Assistant
Leftover duplicate lines 4928-4930. Let me remove those.
Assistant
Let's fix the dangling comment on line 4893.
Assistant
That first function is fixed. Now let's view the sync-stream function
_route_requirements_to_members_stream.Assistant
I accidentally lost the "stream_events=..." line in the else branch when replacing but it looks like it merged fine (line 5028
yield_run_output=Trueright after stream=True, but stream_events line is missing in else branch). Let's check.Assistant
I need to add back the missing
stream_events=line in that else branch.Assistant
Now let's handle
_aroute_requirements_to_members(async non-stream) starting at line 5068.Assistant
Duplicate line 5102-5103 and leftover lines 5139-5142. Let's fix both.
Assistant
Now let's handle
_aroute_requirements_to_members_stream(async streaming) - the actual issue target.Assistant
Leftover duplicate lines 5249-5254. Let's remove them.
Assistant
Now let's compile and check the full diff for sanity.
Assistant
I accidentally removed the
_, member = route_resultline in the async streaming function. Let's check and fix.Assistant
Indeed missing. Let's add it back.
Assistant
Now there's a duplicate line 5212-5213. Remove it.
Assistant
Now let's verify final diff and compile again.
Assistant
Good, diff looks clean (only expected removed/moved
member_run_idlines). Let's view the whole diff once more for full confirmation.Assistant
This diff is now clean and consistent across all 4 functions. Now let's write a reproduction script to test the actual scenario described in the issue.
Assistant
Let's search for tests that specifically test
_route_requirements_to_members/_aroute_requirements_to_members_streamfunctions to see how they mockmember.continue_run.Assistant
I'll just leave status default (not paused) instead of setting is_paused directly.
Assistant
This confirms the fix works. Now let's verify the fix would have failed before the change (sanity check by reverting temporarily).
Assistant
Confirmed: without the fix,
run_contextisNone, reproducing the bug. With the fix, it's properly populated withsession_stateanddependencies.Now let's run the existing test suite for team continue_run / HITL flows to make sure nothing is broken.
Assistant
All pass. Let's run broader unit tests for team module and integration tests for HITL flows (if they can run without external API keys, likely mocked).
Assistant
Confirmed pre-existing failures unrelated to our change. Now let's also run agent unit tests to ensure nothing broke there (since we didn't modify agent code, but let's double check).
Assistant
Same pre-existing unrelated failures. Now let's check integration tests related to HITL flows that don't require a live LLM (maybe use mocked models).
Assistant
Good, run_context is always populated by this point. Now let's double check
_build_member_continue_run_contexthandles the case whererun_context.session_stateisNoneanddependenciesisNonegracefully (returns None for session_state, keeps dependencies=None). That's fine.Let's view the final diff once more fully to double check correctness, then clean up temp file.
Assistant
Now let's run a broader sanity check with mypy/ruff if configured, to ensure no lint/type issues introduced.
Assistant
Extra stray
)at line 4930. Let's remove.Assistant
Now let's rerun mypy and full syntax check.
Assistant
No more
_run.pymypy errors. Let's also run ruff again and the unit test suite once more.Assistant
Now let's re-run the repro script again to make sure everything still works after the mypy comment tweak.
Assistant
Now let's do a final full diff review.
Assistant
This is clean and consistent. Now let's run the full unit test suite once more (whole repo) to be safe, then finalize.
Assistant
These are pre-existing, unrelated failures (missing
sqlitemodule dependency), not introduced by our change. Good — our change doesn't affect the workflow module at all.Assistant
Only the same pre-existing, unrelated
sqlite/postgresdb config failures remain — all team/agent related tests pass. Let's finalize by reviewing the checklist.Assistant
Summary
Root cause: When a Team's paused (HITL) run is continued via
team.acontinue_run()(or the sync/non-streaming variants), the team correctly restoresrun_context.session_stateandrun_context.dependenciesfrom the DB/passed values via_asetup_session/resolve_run_options. However, when routing member-agent requirements back to the member viamember.continue_run()/member.acontinue_run()in_route_requirements_to_members[_stream]/_aroute_requirements_to_members[_stream], the team never forwarded thatrun_context(orsession_state/dependencies) to the member call. This is inconsistent with the initial delegation path (delegate_task_to_member(s)in_default_tools.py), which explicitly forwardssession_state=(a copy) anddependencies=run_context.dependenciestomember.run()/member.arun().Since
continue_run()/acontinue_run()don't accept asession_state=kwarg directly (onlyrun_context), the member's own continuation logic fell back to loading an empty/fresh session_state, causing tools like the reportedgroup_del_stockto seerun_context.session_state["user_token"]as missing/None.Fix: Added a helper
_build_member_continue_run_context()inlibs/agno/agno/team/_run.pythat builds aRunContextfor the member call, carrying over a copy of the team'ssession_state, plusdependencies,metadata, andknowledge_filters(following the same precedence rule used bydelegate_task_to_member), with the correct memberrun_id/session_id/user_id. This context is now passed asrun_context=to all fourmember.continue_run()/member.acontinue_run()call sites (sync/async, streaming/non-streaming).Verification:
- Wrote a temporary reproduction script directly exercising
_aroute_requirements_to_members_streamwith a mocked member; confirmed it failed (run_context is None) before the fix and passed (session_state/dependenciescorrectly forwarded) after the fix. - Added
# type: ignore[call-overload]where needed to keep mypy clean (verified no new mypy errors introduced in_run.py). ruff checkpasses.- Ran
libs/agno/tests/unit/teamandlibs/agno/tests/unit/agent— all pass except two pre-existing, unrelated failures (missing optionalsqlite/postgresdb extras), confirmed to fail identically before my change too. - Removed the temporary reproduction script before submitting (no test files were added/modified in the repo).
- Wrote a temporary reproduction script directly exercising
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 →
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 →