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
pythonrequires_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
pythonsession_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) Assistant
Let me start by understanding the issue. The user is reporting that when calling
team.acontinue_run, thedependenciesorsession_stateis lost. The issue points to a specific function_aroute_requirements_to_members_streaminlibs/agno/agno/team/_run.pyaround line 5145, where the run_context has not been restored.Let me explore the repository structure and understand the code.
Assistant
Let me start by exploring the repository structure.
Assistant
Let me look at the
_aroute_requirements_to_members_streamfunction mentioned in the issue.Assistant
Now let me look at the non-async version
_aroute_requirements_to_membersand the sync version_route_requirements_to_members_streamto compare howrun_contextis handled.Assistant
Let me look at the sync versions to compare how
run_contextis handled.Assistant
Let me look at the sync non-streaming version
_route_requirements_to_members:Assistant
Now I understand the issue. The
run_context(which containssession_stateanddependencies) is not being passed tomember.continue_run/member.acontinue_run. Let me look at the Agent'scontinue_runandacontinue_runsignatures to understand what parameters they accept.Assistant
Now I can see the issue clearly. The
member.continue_run/member.acontinue_runcalls in the_route_requirements_to_members*functions don't passrun_context,dependencies, oruser_id. Let me look at how the team'scontinue_runbuilds therun_contextand how it calls these routing functions.Assistant
Let me look at where
run_contextis created in the team'scontinue_runto understand what it contains:Assistant
Let me look at how
delegate_task_to_memberpassesrun_contextto the member agent, to follow the same pattern:Assistant
Let me look at the async delegate version:
Assistant
Let me look at the agent's
_run.continue_runto understand howrun_contextis used:Assistant
Let me look at how
user_idandrun_contextinteract in the agent's continue_run. Let me checkinitialize_session:Assistant
Let me check how
run_context.run_idis used in the agent's continue_run flow to understand if passing the team'srun_context(with team's run_id) would cause issues:Assistant
Let me look at the async continue_run dispatch flow more closely:
Assistant
Let me look at the
RunContextclass definition:Assistant
Let me look at how
_acontinue_run_streamusesrun_idvsrun_context.run_id:Assistant
Let me look at
_initialize_session_state:Assistant
Let me check
register_runandaregister_run:Assistant
Let me find where
aregister_runis called in the continue_run flow:Assistant
Let me look at existing tests for team continue_run with member HITL to understand the expected behavior:
Assistant
Let me look at the routing tests specifically:
Assistant
Let me check what's imported at the top of
libs/agno/agno/team/_run.py:Assistant
I see that
RunContextis imported. Now let me check ifcopyis imported.Actually, let me look at the imports more carefully and check for
copy.Assistant
Let me first create a reproduction script to confirm the issue. Let me look at how the team continue_run flow works end-to-end first:
Assistant
Let me look at the streaming version's call site:
Assistant
Now I have a clear understanding. Let me create a reproduction script to confirm the issue:
Assistant
I need to import
RunOutput. Let me fix the script:Assistant
I've confirmed the issue -
run_contextis not passed tomember.acontinue_run. Now let me look at_propagate_member_pauseto understand the relationship betweenmember_run_idandmember_run_output.run_id:Assistant
I've confirmed the issue. Now let me look at the code right before the routing functions to find a good place for a helper:
Assistant
Now let me add a helper function before
_route_requirements_to_members. Let me first open the file at the right location:Assistant
Now let me verify the helper was added and look at the updated line numbers:
Assistant
Now let me modify the first function
_route_requirements_to_members(sync, non-streaming). Let me view its current state:Assistant
Now let me modify the first function
_route_requirements_to_members. I'll use thereplacecommand to update the member continue_run calls:Assistant
Now let me modify the second function
_route_requirements_to_members_stream(sync, streaming):Assistant
Now let me modify the third function
_aroute_requirements_to_members(async, non-streaming):Assistant
Now let me modify the fourth function
_aroute_requirements_to_members_stream(async, streaming):Assistant
All four patches are applied. Now let me run the reproduction script to verify the fix:
Assistant
The fix works for the streaming async version. Now let me create a comprehensive test to verify all four routing functions pass the
run_context:Assistant
All tests pass. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All existing tests pass. Let me also run the broader team test suite and the background stream test:
Assistant
Let me run the full team test suite to ensure nothing is broken:
Assistant
The failure is unrelated to my change - it's a missing postgres dependency. Let me verify this is pre-existing by checking with git stash and running the specific test:
Assistant
Confirmed - the postgres test failure is pre-existing and unrelated to my change. Let me run the rest of the team tests, ignoring the postgres-related test:
Assistant
The only failures are pre-existing db config tests (missing postgres/sqlite dependencies), unrelated to my change. All 412 other tests pass. Let me also run the agent continue_run tests:
Assistant
All agent continue_run tests pass. Now let me do an end-to-end integration test to simulate the actual scenario from the issue - a team with a member agent that has a tool requiring confirmation, where the tool accesses
run_context.session_stateandrun_context.dependencies:Assistant
Let me check the correct parameter name for requiring confirmation on the Agent:
Assistant
Let me look at how to define a tool that requires confirmation:
Assistant
I see. The
requires_confirmationis a parameter of the@tooldecorator /Functionclass. Let me update the e2e test to use the@tooldecorator withrequires_confirmation=True.Actually, looking at the issue, the user uses
requires_confirmation_toolswhich is a list on the agent. Let me search for that.Assistant
The
requires_confirmation_toolsis a parameter onToolkit. Let me use the@tooldecorator withrequires_confirmation=Trueinstead:Assistant
The e2e test requires an actual LLM API. Let me look at how existing tests mock models to create a proper integration test:
Assistant
My unit tests with mocks thoroughly verify the fix. Let me review the final diff to ensure everything is correct:
Assistant
The diff looks clean and correct. Let me verify the module imports correctly:
Assistant
Now let me run the reproduction tests once more to confirm everything works:
Assistant
Let me also test the fallback branch (where
member_run_outputis None andrun_idis used):Assistant
Both branches work correctly. Let me clean up the temporary test files and run the full team test suite one final time:
Assistant
The only failures are the 2 pre-existing db config tests (missing postgres/sqlite dependencies), which are unrelated to my change. All 412 other tests pass. Let me also run a broader set of agent tests to be thorough:
Assistant
All tests pass. Let me now review the final state of the modified functions to make sure the code is clean and correct:
Assistant
Let me view the final version of the function specifically mentioned in the issue (
_aroute_requirements_to_members_stream):Assistant
The code looks clean and correct. Let me do a final comprehensive test run of the relevant test files:
Assistant
All 84 tests pass. Let me now provide a summary of the changes and verify the final diff one more time:
Assistant
The changes are complete. Let me provide a final summary of the work done.
Summary
Issue
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.