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
Let me start by understanding the issue. The problem is that in
team.acontinue_run, thedependenciesorsession_stateare lost. The issue points to_aroute_requirements_to_members_streaminlibs/agno/agno/team/_run.pyaround line 5145, where therun_contexthas not been restored.Let me explore the repository and the relevant file.
Assistant
Let me look at the relevant section around line 5145.
Assistant
I can see the issue. When calling
member.acontinue_run, therun_contextis not being passed. Let me look at the non-async version and how these functions are called.Assistant
Let me look at the non-async version
_route_requirements_to_membersto see how it handles run_context:Assistant
Let me look at how the team's
acontinue_runis implemented and how it calls these routing functions.Assistant
Now let me look at the async version of the team's continue_run to understand how run_context is set up there, and find where
_aroute_requirements_to_members_streamis called.Assistant
Now let me look at how
run_contextis created in the asyncacontinue_runfunction:Assistant
Let me look at the
acontinue_runpublic method to see how run_context is set up there:Assistant
Now let me look at the public
acontinue_runmethod on the Team class to see how run_context is constructed:Assistant
Let me look at
acontinue_run_dispatchto see how run_context is constructed:Assistant
Now let me look at the async dispatch
acontinue_run_dispatch:Assistant
I found the bug. In
acontinue_run_dispatch(the async version), therun_contextis initialized withsession_state={}instead of loading the actual session state from storage, unlike the synccontinue_run_dispatchwhich loads it. Let me also check how the member'sacontinue_runis called and what params it accepts:Assistant
Let me look at the agent's
acontinue_run_dispatchto understand how it loads session_state:Assistant
Let me look at how
delegate_task_to_memberpasses run_context/dependencies to the member (the original delegation pattern):Assistant
Let me check the agent's sync
continue_runsignature:Assistant
Let me look at the team's
_asetup_sessionand how session_state is loaded in the async path:Assistant
Let me look at
resolve_run_optionsandapply_to_contextto understand how options are applied to run_context:Assistant
Let me check how the member agent stores/loads session_state when part of a team:
Assistant
Let me look at the RunContext class definition:
Assistant
Let me look at
_process_delegate_task_to_memberto understand session_state handling for members:Assistant
Let me see the rest of the agent's
acontinue_run_dispatchto understand dependency resolution:Assistant
Let me look at the agent's
_acontinue_run_streamto see how it sets up session and resolves dependencies:Assistant
Let me check how dependencies resolution works to make sure passing already-resolved dependencies is safe:
Assistant
Let me check the agent's
load_session_stateto confirm passing session_state preserves it:Assistant
Let me check the agent's sync
continue_run_dispatchto ensure it handles a passedrun_contextsimilarly:Assistant
Let me check the agent's sync
_continue_run/_continue_run_streamfor session_state handling:Assistant
Let me look at the agent's sync
_continue_runto verify session_state handling:Assistant
Now I understand the issue fully. Let me check the imports at the top of the team
_run.py:Assistant
Now I understand the issue completely. Let me look at the exact code in
_aroute_requirements_to_members_streamto modify it:Assistant
Let me see the part above (where member_run_id and member_run_output are computed):
Assistant
Let me check what's right before
_route_requirements_to_members:Assistant
Now let me add the helper function. I'll insert it right before
_route_requirements_to_members:Assistant
Now let me insert this helper function before
_route_requirements_to_members:Assistant
Now let me insert the helper function. I'll use the
editcommand to insert it between line 4807 and 4810.Assistant
I need to add a blank line between the helper function and
_route_requirements_to_members:Assistant
Now let me modify
_route_requirements_to_members(sync, non-stream) to use the helper. Let me replace the relevant block:Assistant
Now let me look at
_route_requirements_to_members_stream(sync, stream):Assistant
Now let me modify
_route_requirements_to_members_stream(sync, stream):Assistant
I made a mistake - I accidentally removed the
route_result = _find_member_route_by_id(...)call and the None check. Let me fix this:Assistant
Let me add a blank line for readability:
Assistant
Let me add a missing blank line:
Assistant
Now let me look at the
_aroute_requirements_to_members(async, non-stream) function:Assistant
Now let me modify
_aroute_requirements_to_members(async, non-stream):Assistant
I see a bug introduced - the
for req in reqs:loop got mangled. Let me fix it:Assistant
Now let me modify
_aroute_requirements_to_members_stream(async, stream - the one mentioned in the issue):Assistant
There are leftover duplicate lines (5249-5254) from the original code. Let me remove them:
Assistant
All four routing functions are now modified. Let me verify the file compiles correctly:
Assistant
Now let me verify the helper function and all four modifications with a quick search:
Assistant
The fix looks complete. Now let me look at existing tests for team HITL/continue_run to understand the test patterns and write a reproduction script:
Assistant
Let me look at the member-level HITL test (more relevant to the fix):
Assistant
These tests require OpenAI API keys. Let me look for a mock/dummy model that I can use for a reproduction:
Assistant
Let me look for a model that can be used without an API key, like a function model or a mock. Let me check how unit tests for teams create controllable models.
Assistant
Let me search for any mock/test model utilities used in unit tests:
Assistant
Let me look at how this test file tests the routing functions:
Assistant
Let me look at
_find_member_route_by_idto understand how to construct a mock for the routing test:Assistant
Let me look at the
RunRequirementstructure:Assistant
Let me look at
is_resolvedand how the member'sacontinue_runre-executes confirmed tools:Assistant
Let me look at
test_run_requirement_fixes.pyto understand existing test patterns for continue_run routing:Assistant
Let me check
get_member_idandget_resolved_members:Assistant
Now let me write a reproduction script that directly tests the routing functions to verify the fix:
Assistant
Let me fix the async test function:
Assistant
Hmm, the sed command didn't actually change
async def test_async_stream_passes_run_contextto async because it already was. Wait, the error says'async for' outside async function. Let me look at the actual function definition. Maybe my heredoc wroteasync def test_async_stream_passes_run_context():correctly. Let me check.Actually wait, the grep says "async def present: False". That's strange. Let me look at the file around line 70-90.
Assistant
The function is missing
async. Let me fix it:Assistant
Let me use a real model class or
model=None. Let me check ifmodel=Noneworks for Agent construction:Assistant
is_pausedis a property. Let me check how it's computed:Assistant
is_pausedis based onstatus. Let me fix the test to usestatus:Assistant
Let me check
TeamRunOutputconstructor fields:Assistant
Let me fix the
TeamSessionconstruction (removeteam_name):Assistant
The fix works. Now let me confirm the bug existed before the fix by temporarily stashing my changes:
Assistant
Confirmed the bug existed before the fix. Let me extend the test to cover all four routing functions for completeness:
Assistant
All four routing functions now correctly restore dependencies and session_state. Let me run the existing unit tests for team continue_run to make sure I didn't break anything:
Assistant
All existing tests pass. Let me run a broader set of team unit tests to ensure nothing else broke:
Assistant
The 2 failures are about missing optional
sqlite/postgresDB dependencies, unrelated to my change. Let me confirm they fail on the original code too:Assistant
Confirmed pre-existing failures (missing optional DB dependencies). Now let me run the agent continue_run unit tests:
Assistant
All tests pass. Let me review the full diff to make sure everything is clean:
Assistant
The diff is clean and consistent. Let me verify there are no other places where member
continue_run/acontinue_runis called without the run_context that I might have missed:Assistant
All 8 calls are covered. Let me verify each now passes
run_context=member_run_context:Assistant
All 8 calls now pass
run_context=member_run_context. Let me clean up temp files and run a final broader test:Assistant
The 4 failures are all the same pre-existing
sqlite/postgresDB module issue. Let me confirm the agent ones are also pre-existing:Assistant
Confirmed all 4 failures are pre-existing. Let me do a final syntax check and review the complete set of changes:
Assistant
Let me do a final review of the helper function and one routing function to confirm everything is clean:
Assistant
Let me check the line length convention used in the repo and verify the helper's long line:
Assistant
The line is 115 chars, within the 120 limit. Let me run ruff on the modified file to be safe:
Assistant
Ruff passes. Let me also verify formatting:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.