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 understanding the issue.
Assistant
I'll explore the repository structure first.
Assistant
Let me look at the
_aroute_requirements_to_members_streamfunction around line 5110:Assistant
Now let me look at
_acontinue_run_streamto understand how the run_context is being handled:Assistant
Let me look at how
run_contextis created in the dispatch functionacontinue_run_dispatch:Assistant
Let me look at
_asetup_sessionto understand how the run_context's session_state is populated:Assistant
Let me look at the member agent's
acontinue_runimplementation:Assistant
Let me look at the sync version
_route_requirements_to_members_streamto compare:Assistant
Let me look at how
delegate_task_to_memberpasses run_context to members in the normal run flow:Assistant
Let me look at the non-stream version
_route_requirements_to_members:Assistant
Let me look at the async non-stream version
_aroute_requirements_to_members:Assistant
Let me look at the agent's
_asetup_sessionand_acontinue_run_streamto understand session_state handling:Assistant
Let me look at existing tests for team continue_run with HITL:
Assistant
Let me look at the dependencies test and the team dependencies test:
Assistant
Let me check the unit tests and how they mock models:
Assistant
Let me look at the test for routing requirements to members:
Assistant
Let me look at
_find_member_route_by_idand the imports in_run.py:Assistant
Now let me write a reproduction script to confirm the issue. Let me create a test that mocks the member agent and verifies the call args:
Assistant
Let me use a real model class but mock it differently, or just use
model=None. Actually, let me just use a simpler approach - mock the member entirely with MagicMock. Let me check the get_member_id function and how the team resolves members.Assistant
Let me rewrite the reproduction to use a MagicMock member agent with proper attributes. The team's
_find_member_route_by_idusesget_resolved_members(team, run_context)which returnsteam.members. Andget_member_id(member)- let me check what it needs.Assistant
The
member.acontinue_runwithstream=Trueshould return an async iterator. Let me fix the reproduction:Assistant
I've confirmed the issue. The
dependencies,session_state,metadata,knowledge_filters, andrun_contextare NOT passed to the member'sacontinue_run. Let me check the agent'scontinue_run_dispatch(sync) signature:Assistant
Let me check how member agents handle session saving when they have a
team_id:Assistant
Let me check the agent's
load_session_stateto understand merging behavior:Assistant
Let me look at the agent's
resolve_run_optionsandapply_to_context:Assistant
Let me see the rest of
_acontinue_run_streamafter the routing call:Assistant
Let me check the agent's save session logic for team members:
Assistant
Let me look at the
RunContextclass definition:Assistant
Let me search for how run_context is passed to member agents in various flows:
Assistant
Let me look at the agent's
arundispatch to see howsession_stateflows:Assistant
Now I understand the issue fully. The member agent (with
team_idset) doesn't read/save its session from DB, so duringcontinue_runthe session_state is empty, anddependencies/metadata/knowledge_filtersare never passed from the team'srun_contextto the member'scontinue_run/acontinue_run.Let me look at the agent's continue_run dispatch sections precisely to add
session_statesupport:Assistant
Let me look at the agent's
_continue_run(sync) to see how session_state is loaded:Assistant
Let me look at the agent's
_initialize_session_state:Assistant
Let me look at
_aresolve_run_dependencies:Assistant
Let me check all callers of the routing functions to see if
run_contextis always passed:Assistant
Let me check the git history for recent changes around these routing functions to understand conventions:
Assistant
Let me check the agent's public
continue_run/acontinue_runmethods to see how they pass params to the dispatch:Assistant
Let me check the team's public
continue_run/acontinue_runmethods:Assistant
Let me look at the team's
_load_session_stateand_initialize_session_state:Assistant
I have a clear understanding now. Let me implement the fix. I'll add
session_statesupport to the continue_run dispatches and pass the team's run_context values (dependencies, session_state, metadata, knowledge_filters) to members in the routing functions.Let me start with the agent's
continue_run_dispatch(sync):Assistant
Now let me make the edits. First, add
session_stateto the agent'scontinue_run_dispatchsignature:Assistant
Now update the docstring and the session_state loading line:
Assistant
Now let me update the docstring for
continue_run_dispatchand then handle the async version. Let me update the docstring:Assistant
I accidentally duplicated the
run_contextdocstring line. Let me fix it:Assistant
There's still a duplicate
session_idline. Let me fix the docstring:Assistant
Now let me handle the agent's
acontinue_run_dispatch(async). Let me find it:Assistant
Now update the docstring and the
_session_stateloading for the async version:Assistant
Now update the
_session_stateinitialization to use the passedsession_stateas base:Assistant
Now let me add
session_stateto the team'scontinue_run_dispatch(sync) for sub-team members. Let me find it:Assistant
Now update the session_state loading in the team's
continue_run_dispatch:Assistant
Now let me handle the team's
acontinue_run_dispatch(async):Assistant
Now let me add
session_stateto the team'sacontinue_run_dispatchsignature and use it:Assistant
Let me add a session_state precedence block for consistency with the other fields:
Assistant
Now I need to update the 4 routing functions to pass the team's run_context values to the member's
continue_run/acontinue_run. Let me first add a helper function. Let me view the area before_route_requirements_to_members:Assistant
Now let me add the helper function before
_route_requirements_to_members:Assistant
Let me fix the spacing between the helper and the next function:
Assistant
Now let me update the call sites in
_route_requirements_to_members(sync, non-stream):Assistant
Now let me update the call sites in
_route_requirements_to_members_stream(sync, stream):Assistant
The edit left leftover duplicate lines (5017-5022). Let me fix that:
Assistant
Let me add back the blank line that was removed:
Assistant
Now let me update the async non-stream version
_aroute_requirements_to_members. Let me find its call sites:Assistant
The edit mangled the lines again. Let me fix it properly:
Assistant
Now the last one -
_aroute_requirements_to_members_stream(async, stream). Let me find its call sites:Assistant
Let me add back the missing blank line:
Assistant
Now let me verify the changes compile correctly. First, let me check the imports in
_run.py:Assistant
Now let me update my reproduction script to verify the fix works. Let me check the captured kwargs now:
Assistant
The fix works -
dependencies,session_state,metadata, anduser_idare now passed to the member'sacontinue_run. Let me run the existing unit tests to make sure I didn't break anything:Assistant
All existing tests pass. Now let me run the broader unit test suites for team and agent:
Assistant
The 2 failures are unrelated (about
agno.dbsqlite attribute - an environment issue). Let me confirm they're pre-existing by stashing my changes:Assistant
The 2 failures are pre-existing environment issues, unrelated to my changes. Now let me write an end-to-end verification that the member agent's tool actually receives the
session_state/dependenciesduringcontinue_run. Let me check how unit tests mock models:Assistant
Let me look at how the agent unit tests mock the model for continue_run flows:
Assistant
Let me write a verification script that tests the agent's
acontinue_run_dispatchcorrectly uses the passedsession_statein the run_context:Assistant
Let me fix the mock to be an async generator:
Assistant
Excellent! The dispatch correctly uses the passed values. Now let me verify all 4 routing functions pass the kwargs correctly (sync and async, stream and non-stream):
Assistant
All 4 routing functions correctly propagate the run_context. Let me also verify the sync agent dispatch and run a broader set of unit tests:
Assistant
Let me check
initialize_sessionfor the agent to make sure passinguser_idis safe:Assistant
Let me check if the background continue_run stream also routes member requirements (to ensure completeness):
Assistant
Let me verify how
resolve_run_optionshandles metadata (to ensure no mutation of the team's metadata):Assistant
All passed values are copied (via
resolve_run_optionsor explicitly), so no mutation of the team's run_context. Let me run the broader unit test suite once more and the workflow HITL tests:Assistant
Let me exclude the file with the missing dependency and run the rest:
Assistant
Let me check if these workflow failures are pre-existing or caused by my change. Let me look at one failure first:
Assistant
The failure is due to missing
sqlalchemymodule - an environment issue. Let me confirm all these failures are pre-existing by stashing my changes:Assistant
The workflow failures are pre-existing (missing
sqlalchemy). Let me install sqlalchemy to run the full HITL test suite and verify my change doesn't break anything:Assistant
All workflow HITL tests pass now. Let me re-run the full unit suite to confirm everything passes:
Assistant
All 1249 unit tests pass. Let me check if I can run the integration HITL tests (they may need an API key):
Assistant
No API key available, but my unit-level verification confirms the fix. Let me do a final review of the complete diff:
Assistant
The diff looks clean and complete. Let me clean up temp files and run a final comprehensive test:
Assistant
Let me try to build a more complete end-to-end test mimicking the issue. Let me check for any test mock model utilities:
Assistant
My verifications are comprehensive. Let me do a final import/syntax check and verify the helper is correctly accessible:
Assistant
Let me check for any line-length issues in my changes:
Assistant
No lines over 120 chars. Good. Let me check the project's line length config.
Assistant
Let me verify the longest added line fits within 120 chars:
Assistant
All lines fit. Let me run ruff to check for any linting issues:
Assistant
Ruff flags
Agentas undefined in the annotation. Let me check howAgentis referenced elsewhere in_run.py:Assistant
I need to add
Agentto theTYPE_CHECKINGimports. Let me check the correct import path:Assistant
All ruff checks pass. Let me re-run the relevant unit tests to confirm everything still works:
Assistant
All 755 tests pass. Let me do a final review of the complete diff:
Assistant
The diff is clean and complete. Let me verify there are no leftover temp files and confirm the final git status:
Assistant
Everything is clean. Let me run the full unit test suite one final time to confirm everything passes:
Assistant
The collection errors are from missing optional vectordb dependencies (unrelated to my change). Let me run the relevant test directories:
Assistant
The tools tests have collection errors due to missing optional dependencies. Let me run just the relevant ones (team, agent, workflow, run) which I already verified pass.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.