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 exploring the repository structure to understand the codebase.
Assistant
Let me look at the specific function mentioned in the issue -
_aroute_requirements_to_members_stream.Assistant
Now let me look at thecorresponding non-streaming function
_aroute_requirements_to_members(which we already saw around line 5023) and the sync streaming one_route_requirements_to_members_stream(around line 4903):Assistant
Now let me look at the sync streaming one
_route_requirements_to_members_stream:Assistant
Now let me look at the
acontinue_runmethod on the agent to understand what parameters it accepts and howdependenciesandsession_stateare passed through:Assistant
Now let me look at the agent's
acontinue_runto see how the dependencies and session_state are passed in:Assistant
Now let's look at how
dependenciesandsession_stateare handled in_continue_run_dispatch_stream_with_member_eventsoracontinue_run_dispatch:Assistant
Now let's look at
_acontinue_run_stream:Assistant
Now let me look at the sync version
_continue_run_dispatch_stream_with_member_events:Assistant
Now let's check how the member agent's
acontinue_runis called from_aroute_requirements_to_members_streamto see if dependencies and session_state are passed properly. Let me look at the agent'sacontinue_run:Assistant
Now let me look at
resolve_run_options:Assistant
Now let me look at the agent's
_run_options.py:Assistant
Now let me check how
delegate_task_to_memberdoes it (the "right" pattern):Assistant
Now let me look at the three functions again more carefully:
Assistant
Let me check the agent's
acontinue_runandcontinue_runparameters:Assistant
Let me look at how
run_contextis used by the agent in_continue_run_dispatch:Assistant
Let me also look at how session_state is restored from DB in the agent:
Assistant
Let me see what happens in
arun:Assistant
Let me look at the
RunContextclass:Assistant
Let me look at
_asetup_sessionto understand how session_state is loaded:Assistant
Now let me look at the existing tests to understand the structure:
Assistant
Let me search for tests that focus on the issue (HIL tests):
Assistant
Let me check the test setup more:
Assistant
Let me write a reproducer for the bug:
Assistant
Let me create a reproducer script to confirm the issue:
Assistant
Let me look at the existing tests to see how a HITL continuation test is structured andruns without API keys:
Assistant
Now let me create a reproducer script to confirm the bug:
Assistant
The bug is confirmed. Now let me apply the fix. The issue is in all 4 routing functions where
member.continue_run/member.acontinue_runis called withoutrun_contextbeing passed:Assistant
Now I'll apply the fix. The fix is to pass
run_context=run_contextand explicitdependenciesto the member agent'scontinue_run/acontinue_runcalls:Assistant
Let me look at the raw text more carefully to see why my replace didn't match. The text I provided had 4 spaces but the actual file may have different indentation. Let mecheck the raw bytes.
Assistant
The file has standard 8 spaces indentation, no tab issues. Let me try the replace again, perhaps the issue is line endings in heredoc.Let me try the replace again with the correct indentation:
Assistant
Let me try the replacement using exact text from the file. The reason my previous attempt failed is the heredoc had leading whitespace but the heredoc with indented content might have stripped or added tabs. Let me use a script instead.
Assistant
All four fixes applied. Let me verify by looking at the diff:
Assistant
The diff looks good. Now let me run my reproducer to verify the fix:
Assistant
The fix works. The
run_context(which contains bothdependenciesandsession_state) and explicitdependenciesare now passed to the member agent. Let me extend the reproducer to test all four routing functions:Assistant
Test 1 passes. Let me fix the mock to properly support iterator protocol:
Assistant
Let me fix the mock to properly handle both async iterator and awaitable patterns:
Assistant
All four tests pass. The fix is working as expected. Now let me also verify with the original issue scenario - where the dependencies/session_state are accessed in tool execution:
Assistant
Excellent! The fix works correctly. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All 49 tests pass. Let me also run other tests to make sure nothing is broken:
Assistant
The failing tests are unrelated to my changes - they're about missing sqlite and skills file path issues. Let me verify by checking these failures exist before my changes:
Assistant
Good - these tests fail even without my changes. Let me restore my changes:
Assistant
Good. The pre-existing failures are not related to my fix. Let me also run the agent-related tests:
Assistant
Only pre-existing failures unrelated to my fix. Let me also check
_continue_run_dispatch_stream_with_member_eventsto ensure it's still working:Assistant
The
_continue_run_dispatch_stream_with_member_eventsreceivesmember_event_streamfrom the caller that already passesrun_context. So that part is fine. Let me verify how the agent'scontinue_run_dispatchhandlesrun_context:Assistant
Let me also look at the agent's
_continue_run_streamfor sync and_acontinue_run_streamfor async:Assistant
Let me also check the agent's
_continue_run(non-streaming) to verify it usesrun_context:Assistant
Let me check the agent's
_acontinue_run_stream(async):Assistant
Let me verify how dependencies are resolved and whether they need to be resolved at the team level or agent level:
Assistant
Let me now run the full test suite to make sure nothing is broken:
Assistant
All 85 tests pass. Let me also run the agent continue_run tests:
Assistant
All 10 continue-related tests pass. Let me also test the overall agent test suite:
Assistant
Only the 2 pre-existing sqlite failures. All 339 other tests pass. Let me also check the team tests:
Assistant
Let me run the original reproducer one more time and verify everything works:
Assistant
All four routing functions now correctly propagate
run_context(which contains bothdependenciesandsession_state) and explicitdependenciesto the member agent.Let me also check the diff one more time to verify the final state of changes:
Assistant
The diff is clean and minimal. Let me clean up the temporary test files:
Assistant
Let me also verify the final state of the file:
Assistant
The fix is complete. Let me also run the specific continue_run related tests one more time to confirm everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.