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
- Assistant
I'll start by exploring the repository structure and the code mentioned in the issue around
_aroute_requirements_to_members_stream. - Assistant
Let me look at the specific code mentioned in the issue around line 5145 in _run.py
- Assistant
Let me search more specifically for acontinue_run and _aroute_requirements_to_members_stream
- Assistant
Let me examine the
_aroute_requirements_to_members_streamfunction and related route functions carefully. - Assistant
Let me look at the stream and async versions more carefully.
- Assistant
Let me read the async route functions in detail.
- Assistant
And now the stream async version mentioned specifically in the issue.
- Assistant
Let me check how acontinue_run handles dependencies/session_state and how agent continue_run passes them.
- Assistant
Now let me look at
_acontinue_run_streamto see how it restores run_context and whether it passes it properly. - Assistant
Let me continue reading where it calls
_aroute_requirements_to_members_stream. - Assistant
Let me check setup session and how agent continue_run handles session_state/dependencies.
- Assistant
Let me check the team.acontinue_run and agent.acontinue_run signatures for session_state support.
- Assistant
Let me look at how agent acontinue_run handles run_context, and how members receive dependencies initially during delegation.
- Assistant
Let me continue reading agent acontinue_run_dispatch to see how it builds run_context
- Assistant
Let me look at how delegation to members passes run_context/session_state normally.
- Assistant
Let me look at how members are run with session_state during delegation.
- Assistant
Let me check agent's continue_run signature for session_state support.
- Assistant
Let me check how tools get run_context and session_state/dependencies injected, and look for related tests.
- Assistant
Let me look at integration tests related to team HITL and session_state.
- Assistant
Let me check the HITL tests for teams.
- Assistant
Let me check how session caching works without a DB and how
load_session_stateworks. - Assistant
Let me check how
_acontinue_runon the agent uses run_context.session_state after setup. - Assistant
So agent.acontinue_run reloads session_state from its session, merging with existing. When the member is part of a team without its own DB, it uses team session caching somehow?
- Assistant
Let me check the RunContext class definition.
- Assistant
agent.run takes session_state. Let's check if continue_run_dispatch can take it via kwargs somehow.
- Assistant
Let me check the git log and any existing similar patterns for building member run contexts.
- Assistant
There's a related fix for HITL pause session state loss - let me examine it.
- Assistant
Let me look at
_default_tools.pyfor howcontinue is done there. - Assistant
Let me also check how function tools inject dependencies and if dependencies is separate from session_state.
- Assistant
So tools get run_context which has both session_state and dependencies. Tools using
run_context.session_stateneed that field populated. - Assistant
Let me check how session_state is merged after member runs in the delegate path and if member_response has session_state.
- Assistant
Let me look at_process_delegate_task_to_member
- Assistant
Let me check agent cleanup and run_response.session_state after continue.
- Assistant
Let me check imports at the top of team/_run.py and the full member route functions for running the edit.
- Assistant
Let me also check for existing unit tests about route_requirements:
- Assistant
Let me look at test_continue_run_requirements.py forpatterns.
- Assistant
Let me see how route requirements is tested in that file.
- Assistant
Let me look at section around line 632 for the aroute_requirements test to understand how they mock member.acontinue_run:
- Assistant
Let me carefully re-read agent session creation for team members.
- Assistant
Let me check if initialize_team clears member cachedsessions.
- Assistant
Look at team.initialize_team - does it clear member caches?
- Assistant
_initialize_member...
- Assistant
Looking at _read_or_create_session and team cleanup_and_store...
- Assistant
Interesting - cached_session is still returned even when cache_session by is False (lines 238-243 детям check _cached_session without requiring cache_session). The cache_session flagonly controls whether we set_it at the end.
- Assistant
Let me try langchainRU differently.
- Assistant
But wait - looking at_session.py lines that set_cached_session unconditionally when loading.
- Assistant
I'll implement a helper to pass run_context fields to members and update all four routing functions.
- Assistant
I'll add a helper and update all four route functions carefully.
- Assistant
Now update
_route_requirements_to_membersto use this helper. - Assistant
Let me replace the continue_run calls in
_route_requirements_to_members. - Assistant
Good. Now update the stream version.
- Assistant
Now update the stream version.
- Assistant
Now updatesthe async versions.
- Assistant
Update async non-stream version.
- Assistant
Now the async stream version - the one mentioned in the issue.
- Assistant
Update the async stream version.
- Assistant
Let me write a temporary script to verify the helper and that routing passes run_context correctly.
- Assistant
The issue is that MagicMock isinstance check against RunOutput fails. The fake stream yields MagicMock which isn kit a RunOutput. Let me fix the test to yield an actual RunOutput.
- Assistant
All wordt routing paths pass context. Now let me also run the existing unit tests for continue_run requirements and regressions.
- Assistant
I should avoid concurrent merges when multiple members run in parallel with asyncio.gather.
- Assistant
I'll change the return type of_continue_member to include session state and merge after gather.
- Assistant
Let me verify the gather/return part was updated correctly and there's no duplicate old code.
- Assistant
Good. Re-run the verification tests.
- Assistant
All good. Let me also verify the syntax compiles cleanly and check gitά diff summary.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.