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 relevant code around
acontinue_runand_aroute_requirements_to_members_streamwhere the issue was reported. - Assistant
Let me examine the relevant code around
_aroute_requirements_to_members_streamand howacontinue_runhandles session state. - Assistant
rg is not available, let me use grep instead.
- Assistant
Let me search more specifically for acontinue_run and the _aroute_requirements function.
- Assistant
Let me fix the grep command.
- Assistant
I'll inspect
_aroute_requirements_to_members_streamand how acontinue_run builds run_context. - Assistant
Confirming member
acontinue_runomits run_context; checking team/agent continue_run for how session_state and dependencies are restored. - Assistant
Looking at agent continue_run and how members receive session_state/dependencies.
- Assistant
Let me look at the agent acontinue_run_dispatch and how it handles the parameters. Also need to check if the original team continue_run passes session_state.
- Assistant
Found empty session_state in async path — checking
_asetup_sessionand whether members receive run_context. - Assistant
Let me read the full
_asetup_sessionfunction and also how members get run_context during initial arun (when tools work), and how continue_run routes members in the sync path. - Assistant
Checking how member agents normally receive session_state and dependencies during delegation.
- Assistant
Let me look at how member agents are run during delegation - particularly adelegate_task_to_member.
- Assistant
Checking whether session_state is persisted on pause and restored correctly.
- Assistant
Let me understand how session_state gets saved when the run pauses. Also look at how team_handler saves session.
- Assistant
Let me look for how session state is saved during run - specifically when pause happens.
- Assistant
Checking how member agents handle session and whether agent sessions persist team session_state.
- Assistant
Checking whether continue_run accepts session_state and which params we should forward to members.
- Assistant
Checking how members resolve sessions when team_id is set.
- Assistant
Let me check if agent acontinue_run restores session_state in the async path.
- Assistant
Let me look at how agent
_acontinue_runhandles session_state loading more carefully, and whether member agent with team_id can properly load session_state from TeamSession. - Assistant
so for agent.acontinue_run, session_state IS loaded from DB during
_acontinue_run. The member would call aread_or_create_session which for team members loads TeamSession. And load_session_state shou... - Assistant
Looking for related tests and any existing handling of this pattern.
- Assistant
Let me look at those unit tests and also
RunContextto craft a proper fix. - Assistant
Let me look at RunContext definition and also check the rest of tests related to route_requirements.
- Assistant
Let me look at RunContext class and the existing routing tests that mock member.acontinue_run to understand exact expected parameters.
- Assistant
Checking agent continue_run parameters and whether kwargs can carry session_state.
- Assistant
Checking in-memory session handling without a database — that matches the user's example.
- Assistant
I'll inspect the four route functions' call sites and implement forwarding of run_context.
- Assistant
Checking whether session_state changes from members are assumed to merge back, and how pause handling saves session state.
- Assistant
Let me read the pause handlers to see if session state is saved.
- Assistant
Looking at
_cleanup_and_storeto see if session_state from run_context is put into session before save. - Assistant
Let me read cleanup_and_store
- Assistant
Checking how save_session works without a DB.
- Assistant
Checking how
apply_to_contexthandles existing run_context values. - Assistant
Implementing a helper and updating all four route functions to pass run_context (session_state, dependencies, etc.) to members.
- Assistant
Adding the helper and updating
_route_requirements_to_members. - Assistant
Verifying the rest of
_route_requirements_to_membersis intact after the edit. - Assistant
Updating the sync stream and both async versions.
- Assistant
Let me replace the continue_run calls in the stream version and then the async versions.
- Assistant
Removing the duplicate line and adding a session_state merge after the stream completes.
- Assistant
Adding the merge call after streaming completes.
- Assistant
There's corruption around the cleanup loop — inspecting and repairing it.
- Assistant
Fixing the corrupted section.
- Assistant
Removing the duplicate function definition.
- Assistant
Updating
_aroute_requirements_to_membersnow. - Assistant
Checking concurrent member state merging in delegation for races:
- Assistant
Fixing concurrent path so session_state merges after gather (avoids races).
- Assistant
Checking for duplicate headers and updating the async stream version.
- Assistant
Removing the duplicate header and updating the async stream function.
- Assistant
Verifying the end of the async stream function and that
_build_continuation_messageis intact. - Assistant
Restoring the wiped
_build_continuation_messagebody. - Assistant
Removing the duplicate empty function definition.
- Assistant
Checking imports and whether we need
BaseException, then validating syntax. - Assistant
Checking whether run_response carries session_state we can restore on continue when DB is absent.
- Assistant
Checking whether we should restore session_state from run_response in acontinue_run_dispatch.
- Assistant
Writing a unit test script to verify run_context is forwarded correctly.
- Assistant
Running existing unit tests related to continue_run.
- Assistant
All 55 tests passed. Verifying the structure once more and reviewing the git diff.
- Assistant
Double-checking the is_paused property handleheights our async stream test correctly in real code paths.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.