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 understanding the issue.
Assistant
Let me look at the
acontinue_runmethod in the team.Assistant
Now let me look at the streaming version
_acontinue_run_stream:Assistant
Now let me look at the
_asetup_sessionfunction to understand how the run_context and session_state are handled:Assistant
Now let me look at the non-streaming version
_aroute_requirements_to_membersto compare:Assistant
Now let me understand the issue. When
acontinue_runis called, therun_contexthas the dependencies/session_state set. But when routing to members, the member'sacontinue_runis called without passing thedependencies/session_state/run_context.Let me look at how the member agent's
acontinue_runworks to understand what parameters it accepts and how it uses the run_context.But first, let me look at the
_find_member_route_by_idfunction to understand what run_context does there.Assistant
Now let me look at the member agent's
acontinue_runto understand its parameters:Assistant
Let me look at the agent's
acontinue_run_dispatchto understand how it handles session_state and dependencies:Assistant
Now let me look at how the team's
arunpasses dependencies/session_state to members during the initial run (delegate_task), to follow the same pattern:Assistant
Let me look at the agent's
_asetup_sessionto understand how session_state is loaded:Assistant
Let me look at the agent's
_acontinue_runto understand how the session_state is loaded during continue_run.Assistant
Let me check whether the member agent's
acontinue_runacceptssession_state:Assistant
Let me check how member agents save sessions when part of a team (team_id handling):
Assistant
This is key. Let me look at
aread_or_create_sessionfor the agent:Assistant
Let me look at
apply_to_contextandresolve_run_optionsfor the agent:Assistant
Let me look at the sync version
_route_requirements_to_members:Assistant
Let me look at the agent's sync
continue_runsignature:Assistant
Let me look at the RunContext class:
Assistant
Now I have a clear understanding of the issue. Let me write a reproduction script first to confirm the issue. Let me look at existing tests for team continue_run with HITL to understand the test patterns:
Assistant
Let me look at the test that tests member-level HITL with continue_run, to understand how member tools are tested.
Assistant
Let me check how unit tests use mock models for team HITL:
Assistant
Let me check the unit tests for team that might use mock models for HITL flows:
Assistant
Now let me write a reproduction script that directly tests the routing functions with mocks, to confirm the member's
acontinue_rundoesn't receive dependencies/session_state:Assistant
The
_find_member_route_by_idis inagno.team._tools. Let me look at how it's imported in_run.py. The routing functions import_find_member_route_by_idlocally:from agno.team._tools import _find_member_route_by_idSo I should patch
agno.team._tools._find_member_route_by_id. Let me fix the script. Theget_resolved_membersis inagno.utils.callables. But I'm patching_find_member_route_by_iddirectly, so I don't need to patchget_resolved_members.Assistant
My sed messed up the script. Let me rewrite the file cleanly:
Assistant
I've confirmed the issue. The
member.acontinue_runis called withoutdependenciesorrun_context. Now let me implement the fix. Let me check the imports at the top of_run.py:Assistant
Good,
RunContextis imported. Now let me check ifAgentis imported for type hints.Assistant
Let me look at the metadata resolution in
resolve_run_optionsfor the agent:Assistant
Now I understand the full picture. Let me implement the fix. First, I'll create a helper function that propagates the team's run_context to the member's
continue_run/acontinue_run. Let me view the exact location right before_route_requirements_to_members:Assistant
Now let me add the helper function right after
_has_team_level_requirements:Assistant
Now let me insert this helper function into the file after
_has_team_level_requirements:Assistant
Now let me update the 4 routing functions. Let me start with
_route_requirements_to_members(sync, non-streaming):Assistant
Now let me update the 4 routing functions. Let me find the exact line numbers for each call site:
Assistant
Let me view the exact content around each call site to do precise edits. First,
_route_requirements_to_members(sync, non-streaming):Assistant
Now let me edit the first call site (sync, non-streaming). I'll replace lines 4918-4929:
Assistant
Now let me edit the second call site (sync, streaming). Let me view it:
Assistant
I see there are leftover orphaned lines (5041-5044). Let me remove them:
Assistant
Now the sync streaming is fixed. Let me view the async non-streaming call site:
Assistant
There are issues - the edit removed a line and left an orphaned
). Let me view and fix:Assistant
I need to fix two issues: the missing
member_run_output.tools = ...line and an orphaned). Let me fix:Assistant
Now let me remove the orphaned
)at line 5151:Assistant
There's now a duplicate
**member_continue_kwargs,at lines 5149-5150. Let me fix it:Assistant
The async non-streaming is now correct. Now let me handle the last call site (async streaming). Let me view it:
Assistant
There are orphaned lines 5267-5268 again. Let me remove them:
Assistant
Now there's a duplicate
**member_continue_kwargs,at lines 5265-5266. Let me fix it:Assistant
All 4 call sites are now updated. Let me verify the file compiles correctly:
Assistant
Now let me run my reproduction script to verify the fix works:
Assistant
The fix works. Now let me run the relevant existing unit tests to make sure I didn't break anything:
Assistant
All passing. Now let me write a more comprehensive end-to-end test using a mock model to simulate the actual flow. Let me first check how tests mock the model for team delegation flows:
Assistant
Let me look at how agent HITL tests mock the model to produce tool calls requiring confirmation:
Assistant
Let me look for mock model patterns in unit tests that produce tool calls:
Assistant
Let me look for a test that does a full agent run with a mock model producing a tool call:
Assistant
Let me look at how ModelResponse represents tool calls (FunctionCall):
Assistant
Let me search for tests that mock model to return tool_calls in a full run:
Assistant
Let me write a comprehensive test that verifies all 4 routing functions propagate the kwargs correctly:
Assistant
All 4 routing functions work correctly. Now let me write an end-to-end test with a real agent member and a mock model to verify the actual tool receives the user_token. Let me look at how the agent runs tools from a model response:
Assistant
Let me look at how a ModelResponse with tool_calls is processed in the agent:
Assistant
Let me run the broader team and agent unit test suites to ensure nothing is broken:
Assistant
That failure is unrelated (postgres db not installed). Let me run the rest, deselecting the postgres test:
Assistant
Both failures are pre-existing (missing db backends). Let me confirm these are unrelated by checking git status and running the specific continue_run tests plus agent tests:
Assistant
Confirmed - these 2 failures are pre-existing (missing db backends), unrelated to my change. Now let me run the agent unit tests and the team HITL-related tests:
Assistant
Now let me run the agent unit tests to ensure the agent side still works:
Assistant
Only the 2 pre-existing db backend failures. Now let me write a full end-to-end test using a mock model to verify the actual tool receives the user_token. Let me look at how the agent processes a ModelResponse with tool_calls:
Assistant
Let me look at the non-streaming
handle_model_responseto understand howinvokeproduces an assistant message with tool_calls:Assistant
Let me look at the agent's
ahandle_tool_call_updates_streamto understand how confirmed tools are executed:Assistant
Let me look at
arun_toolto understand how the run_context is passed to the tool function:Assistant
Let me search for existing mock models that yield tool calls in a full run, to build an end-to-end test:
Assistant
Let me look at the base model's streaming
arunmethod to understand whatainvoke_streamshould yield for tool calls:Assistant
The full end-to-end mock model is complex; my routing tests comprehensively cover the fix. Let me verify edge cases of the helper and run the broader regression tests:
Assistant
Let me look at the team basic test to understand the minimum mock model interface for a full run:
Assistant
Let me look at
call_model_stream_with_fallbackandacall_model_with_fallbackto understand the model interface:Assistant
So
acall_model_stream_with_fallbackcallsmodel.aresponse_stream(**kwargs). Let me look at the base Model'saresponse_streamto understand the interface. The mock model needs to implementaresponse_stream.Let me look at the base Model's
aresponse_stream.Assistant
Let me verify the agent's
_acontinue_run_streamflow - does it execute confirmed tools before the model call?Assistant
Let me look at
aprocess_response_streamto understand how to build a mock model for a final text response:Assistant
Let me check how a member agent's
team_idis set when added to a team:Assistant
Now let me build a full end-to-end test through the team's
acontinue_runwith a mock model. Let me create it:Assistant
sqlalchemy isn't installed. Let me try without a DB. Let me check what happens in
_aread_or_create_sessionwithout a DB:Assistant
Without a DB it creates an in-memory session. Let me check
_normalize_requirements_payloadto ensure_member_run_responseis preserved:Assistant
Let me check what
acheck_and_apply_approval_resolutiondoes with a None db:Assistant
acheck_and_apply_approval_resolutionreturns early ifdb is None. Let me update the e2e test to not use a DB:Assistant
Let me check the
RunRequirement.confirmandrequires_confirmation:Assistant
Let me check
is_resolved:Assistant
Let me update the e2e test to set
confirmed=Truedirectly on the tool (simulating post-confirm state):Assistant
The error is because I need to pass
requirementstoacontinue_run(as the user does in the issue). Let me update the test:Assistant
Progress! Dependencies are now propagated. The session_state is None because I didn't store it (in the issue, the user passes
session_stateto the initialarun, which stores it). Let me setteam.session_stateto simulate the stored session_state from the initial run:Assistant
Let me debug why the session_state isn't being loaded. Let me check
_initialize_session_stateand_load_session_statefor the team:Assistant
Let me check the team's
_initialize_session_state:Assistant
Let me add debug to capture the full session_state and dependencies in the tool:
Assistant
The team's session_state has
current_session_id/current_run_idbut notuser_token. Let me check_read_or_create_session(sync) to see if it loadsteam.session_state:Assistant
Let me check the Team class
session_stateattribute and whetherinitialize_teamresets it:Assistant
session_state: Optional[Dict[str, Any]] = Noneis a dataclass field. Settingteam.session_state = {...}should work. Let me check ifinitialize_teamresets it. Let me look atinitialize_teamand_resolve_session_state.Actually, let me check the Team's
__post_init__orinitialize_teamfor session_state handling.Assistant
Let me debug by patching
_build_member_continue_run_kwargsto print the team's session_state:Assistant
The DEBUG print didn't appear. Let me run with full output to see what's happening:
Assistant
The team's run_context.session_state doesn't have
user_token- soteam.session_statewasn't loaded. Let me add a debug print ofteam.session_statebefore the call:Assistant
The TEST print didn't appear - my replacement may not have matched. Let me check the file:
Assistant
The session_state setting line is gone. Let me view the main function:
Assistant
Let me rewrite the e2e test cleanly with
team.session_stateset:Assistant
The end-to-end test passes. Now let me verify it FAILS without my fix (to confirm the fix is what resolves it):
Assistant
Confirmed - without the fix, both dependencies and session_state are None; with the fix, they're propagated. Let me also test the sync
continue_runpath:Assistant
Both sync and async paths work. Let me clean up temp files and review my final changes:
Assistant
The diff looks clean. Let me run the syntax check and the relevant test suites once more to confirm everything works:
Assistant
All 141 tests pass. Let me run the full team and agent unit test suites one final time (excluding the pre-existing db backend failures):
Assistant
All 751 tests pass. Let me do a final review of the modified routing functions to ensure everything is clean:
Assistant
All 8 call sites (2 per function × 4 functions) are correctly updated. Let me do a final verification by viewing the streaming sync function to confirm the structure is clean:
Assistant
The structure is clean. Let me verify the helper function once more:
Assistant
Let me check if there's a linter configured and run it on the modified file:
Assistant
Ruff checks pass. Let me also verify formatting:
Assistant
Let me see what ruff format wants to change:
Assistant
Let me check if the original file passed ruff format (to know if I should apply formatting):
Assistant
The original file was already formatted. Let me apply ruff format to keep consistency, then verify it only touches my changes:
Assistant
Formatting applied cleanly, only touching my changes. Let me run the tests once more to confirm everything passes after formatting:
Assistant
All tests pass. Let me do a final review of the complete diff:
Assistant
The diff is clean and complete. Let me verify one edge case - that the team's sync
continue_run_dispatchalso accepts the kwargs I'm passing (for sub-Team members):Assistant
The team's
continue_run_dispatchaccepts all the kwargs I'm passing (run_context,knowledge_filters,dependencies,metadata), so the fix works for sub-Team members too. Let me confirm no temp files remain and do a final test run:
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 →