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
_acontinue_run_streamand_acontinue_runfunctions to understand the run_context flow:Assistant
Now let me look at
_acontinue_run_stream:Assistant
Now let me look at the
acontinue_run_dispatchfunction and howrun_contextis set up:Assistant
Let me check the
resolve_run_optionsfunction:Assistant
Let me look at how the agent's
acontinue_runworks:Assistant
Let me look at how
arunand the original_arunfunction passsession_statetorun_context:Assistant
Let me look at the
acontinue_runmethod signature onteam.py:Assistant
Let me look at the issue's reference line 5145:
Assistant
Now I see the issue. The
member.acontinue_runcall doesn't passrun_context(ordependencies/session_state). Let me also look at the non-streaming version:Assistant
Let me look at the agent's
acontinue_runmethod signature:Assistant
Let me look at how the team arun handles
session_stateand how it stores it in the run_response:Assistant
Let me look at the agent's
acontinue_run_dispatch:Assistant
Let me look at the sync versions of these functions:
Assistant
Let me first understand the structure better and look at how
_find_member_route_by_idworks:Assistant
Now let me look at the
RunContextto understand its structure:Assistant
Let me look at the cookbook examples for acontinue_run:
Assistant
Let me look at the
_arunflow to understand howrun_contextis passed to members during the initial run:Assistant
Let me first check if there are tests for the existing functionality to understand the structure:
Assistant
Now let me look at how the existing tests handle session_state and dependencies:
Assistant
Let me create a reproduction script for the issue:
Assistant
Let me check the
continue_runmethod signature:Assistant
Now let me look at the exact code blocks I need to modify:
Assistant
Now I have a clear picture. Let me now look at the exact code at each location more carefully:
Assistant
Now I have a clear understanding. Let me look at the
run_contextparameter type:Assistant
Now let me create a comprehensive test script that demonstrates the issue and then fix it:
Assistant
The bug is confirmed. Now let me fix all 4 affected functions. Let me start with the streaming version mentioned in the issue:
Assistant
Now let me fix the
_aroute_requirements_to_members_streamfunction:Assistant
Let me make the fix now.
Assistant
Let me make the fix now.
Assistant
Now let me fix the
_aroute_requirements_to_members(async, non-streaming) function:Assistant
I need to fix a missing blank line:
Assistant
Now let me fix the sync versions. First, let me look at
_route_requirements_to_members(sync, non-streaming):Assistant
Now let me fix the sync streaming version:
Assistant
I see there are duplicate lines from my edit. Let me fix this:
Assistant
There's still a duplicate line. Let me check:
Assistant
Now let me verify all 4 locations have been fixed by searching for
run_context=run_contextin the file:Assistant
All 8 locations are now fixed. Let me verify the changes look correct:
Assistant
I need to fix the blank line that I accidentally removed:
Assistant
Now let me verify the async non-streaming version:
Assistant
All 4 functions are now fixed. Let me run the reproduction script to confirm:
Assistant
Let me also test all 4 functions to make sure they all pass
run_context:Assistant
All 4 functions are now passing
run_contextto the member. Now let me also think about edge cases. Let me look at thecontinue_run_dispatchandacontinue_run_dispatchto see if there are other places where therun_contextmight need to be handled:Assistant
Now I need to also add
session_stateparameter toacontinue_runandcontinue_runmethods so the user can pass it. Let me look at the dispatch function:Assistant
Let me also add
session_stateparameter to theacontinue_runandcontinue_runmethods on both Team and Agent. This is needed because the user's tool usesrun_context.session_state:Assistant
Let me look at how
_asetup_sessionhandlessession_stateforacontinue_run:Assistant
Let me check the async setup:
Assistant
Let me check
_load_session_state:Assistant
Let me check if the TeamRunOutput stores session_state:
Assistant
The
TeamRunOutputdoes storesession_state. So the session_state from the previous run is available in the run_response.Let me look at the
acontinue_run_dispatchto see if it restores session_state fromrun_response:Assistant
Let me look at how
acontinue_runhandlesrun_idwhenrun_responseis not provided:Assistant
Let me now look at the existing tests to make sure my changes don't break anything:
Assistant
All tests are skipped because they require
OPENAI_API_KEY. Let me set it and try again:Assistant
Let me check what unit tests exist that don't require an API key:
Assistant
All these tests require OpenAI API. Let me check if there's a way to test withoutAPI.
Let me look at unit tests:
Assistant
All 49 tests pass. Let me also run the broader unit tests:
Assistant
The only failure is unrelated to my changes - it's about a skills path that doesn't exist. Let me verify this is unrelated:
Assistant
All 409 tests pass (excluding the unrelated skills test). Let me also run the agent unit tests:
Assistant
All 341 agent tests pass. Now let me verify my fix with a more comprehensive test that simulates the full flow:
Assistant
All tests pass. Let me now also verify the fix doesn't break the edge cases - specifically when
run_contextis None:Assistant
All edge cases pass. Now let me verify the changes by looking at the diff:
Assistant
The diff looks clean. Let me also run the specific test files that might be affected by the changes:
Assistant
All 402 tests pass. Let me clean up the temporary test files:
Assistant
Now let me verify the final state of the file is correct:
Assistant
All 8 locations are correctly modified. Let me also verify the final diff:
Assistant
The fix is minimal and clean - just 8 lines added (one for each call site). Let me also run the original reproduction script one more time to make sure the fix works:
Assistant
The bug is fixed. Let me clean up:
Assistant
Let me also run the broader test suite to make sure nothing is broken:
Assistant
These errors are due to missing optional dependencies, not my changes. Let me just run the specific tests for team and agent:
Assistant
All 750 unit tests pass. Let me also run the related integration tests that don't require OpenAI:
Assistant
These errors are due to missing optional dependencies, not my changes. Let me just run the human_in_the_loop tests:
Assistant
These tests are skipped because they require OpenAI API key. Let me verify my changes one more time by looking at the diff:
Assistant
The fix is clean and minimal - exactly 8 lines added (one for each call site in the 4 affected functions). Let me run the checklist:
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
YES. I created a reproduction script that demonstrated the bug - the
_aroute_requirements_to_members_streamfunction (and its 3 sibling functions) was NOT passing to /. The script showed:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.