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
I'll start by exploring the repository structure and understanding the issue better.
- Assistant
Let me explore the relevant file and understand the code structure.
- Assistant
Let me look at the specific file mentioned in the issue.
- Assistant
Let me look at the relevant section around line 5145 of
_run.py: - Assistant
Let me look at the area around line 5145 in
_run.py. - Assistant
Let me also check the sync counterpart
_route_requirements_to_members_streamand howrun_contextis used: - Assistant
Let me look at the sync version:
- Assistant
Let me look at the team's
acontinue_runmethod: - Assistant
Let me look at the
acontinue_runmethod: - Assistant
Let me look at
acontinue_run_dispatchin_run.py: - Assistant
Let me look at the dispatch function:
- Assistant
Let me now look at how
_acontinue_runand_acontinue_run_streamhandlerun_contextand session state restoration: - Assistant
Let me look at
_acontinue_run_stream: - Assistant
Let me look at
_asetup_sessionto understand how session state is restored: - Assistant
Let me look at that function:
- Assistant
Let me look at
_initialize_session_stateand_load_session_state: - Assistant
Let me search for
_load_session_statein the storage module: - Assistant
Let me look at
_load_session_state: - Assistant
Let me now understand how session state is saved. Let me look at where session state gets saved to the database:
- Assistant
Let me search more broadly for where session_state is saved.
- Assistant
Let me look at how the session data is saved, especially during the initial
arun: - Assistant
Let me look at
_initialize_session_state: - Assistant
Let me look at the main
arunfunction to understand howsession_stateflows through: - Assistant
Let me look at the
arun_dispatchfunction: - Assistant
Let me look at
arun_dispatch: - Assistant
Let me look at how the session is saved (the write/save function):
- Assistant
Let me find how session state is saved:
- Assistant
Let me look at the
_aread_or_create_sessionfunction to understand how session data is created: - Assistant
Let me look at how the session gets saved after a run. Let me find where the session is upserted after run completes:
- Assistant
No matches? Let me search more broadly.
- Assistant
Let me look at the session management in
_session.py: - Assistant
Now let me find where
save_sessionorasave_sessionis called in_run.py: - Assistant
Let me look at what happens at line 3212 and surrounding context:
- Assistant
Let me look at the
_arunfunction to see where it saves session state: - Assistant
Let me continue looking at the
_arunfunction, especially the part where it handles pausing and session saving: - Assistant
Let me look at
_acleanup_and_store: - Assistant
Let me look at
_acleanup_and_store: - Assistant
Now let me look at what happens when a run gets paused - specifically
ahandle_team_run_paused: - Assistant
Let me look at that function:
- Assistant
Now let me look at
_arun_streamto see how it handles pausing: - Assistant
Let me continue reading
_arun_streamto find where it handles pausing: - Assistant
Let me look at the member agent's
acontinue_runto see if it acceptsrun_context: - Assistant
Let me look at the agent's
acontinue_runmethod to see if it acceptsrun_context: - Assistant
Let me look at the agent's
acontinue_run_dispatch: - Assistant
Let me now look at how delegation to members works in the initial run to understand the full picture:
- Assistant
Let me search more broadly:
- Assistant
Let me look at how the delegate_task_to_member tool is implemented:
- Assistant
Let me look at
adelegate_task_to_memberto see how it calls the member: - Assistant
Let me now look at how the member agent saves session state when it's part of a team:
- Assistant
Let me search more broadly for how agent sessions are saved:
- Assistant
Let me look at the agent's
acleanup_and_store: - Assistant
Let me look at the agent's
acleanup_and_store: - Assistant
Let me look at the agent's
asave_sessionto see if it skips saving when part of a team: - Assistant
Let me look at the agent's
asave_session: - Assistant
Let me check how the agent's
read_or_create_sessionworks: - Assistant
Let me look at the agent's
read_or_create_session: - Assistant
Now I have a clear understanding of the issue. Let me verify my understanding by looking at all places where member's
acontinue_runorcontinue_runis called in the routing functions: - Assistant
Let me look at each of these call sites to see what parameters are being passed:
- Assistant
Let me also check the agent's sync
continue_run_dispatch: - Assistant
Now I have a clear understanding of the issue. Let me verify by creating a reproduction script first. But first, let me understand the fix needed by examining the full picture.
The root cause is that in the routing functions (
_aroute_requirements_to_members_stream,_aroute_requirements_to_members,_route_requirements_to_members_stream,_route_requirements_to_members), when callingmember.acontinue_runormember.continue_run, the team'srun_context(which containssession_state) is NOT passed to the member. Since member agents don't save their sessions to the DB when they're part of a team, the member's session_state is lost.Let me now implement the fix:
- Assistant
Let me see the full
_aroute_requirements_to_members_streamfunction: - Assistant
Let me also look at the agent's
_load_session_state: - Assistant
Let me look at this function:
- Assistant
Let me look at the RunContext class to understand its fields:
- Assistant
Let me find the RunContext class:
- Assistant
Let me look at the RunContext class:
- Assistant
Let me see the full RunContext class:
- Assistant
Let me check how
run_context.run_idis used in the agent's_acontinue_run: - Assistant
Let me look at the agent's
_acontinue_run: - Assistant
Let me continue reading the agent's
_acontinue_run: - Assistant
Now I have a complete understanding of the issue. Let me implement the fix. I need to modify the four routing functions to pass the team's
run_context(or a member-specific copy) to the member'scontinue_run/acontinue_runcalls.Let me first create a helper function and then modify the routing functions:
- Assistant
Now I understand the full picture. The issue is in all four routing functions where member agents'
continue_run/acontinue_runare called without passingrun_context, which contains thesession_stateanddependencies. Let me implement the fix.I'll need to modify all four routing functions to pass
run_contextto the member agent calls. Let me also first check how_route_requirements_to_members_stream(sync, streaming) and_aroute_requirements_to_members(async, non-streaming) look: - Assistant
Now let me see
_aroute_requirements_to_members: - Assistant
Now I have a clear picture. Let me implement the fix. I need to pass
run_contextto the member'scontinue_run/acontinue_runcalls in all four routing functions. Let me make the changes: - Assistant
Let me open the file first and then use the edit command:
- Assistant
Now let me make the first edit -
_route_requirements_to_members: - Assistant
Let me use sed to make the edits instead:
- Assistant
Let me verify the changes were applied correctly by looking at the modified sections:
- Assistant
Let me look specifically at the lines I modified:
- Assistant
Let me verify the changes by looking at the modified sections:
- Assistant
Let me verify each call has
run_contextbeing passed: - Assistant
Good, the first fix is applied. Let me check the others:
- Assistant
Good, the second fix is also applied. Let me check the async versions:
- Assistant
Good, the third fix is applied. Let me check the last one:
- Assistant
All four fixes are applied. Let me verify the file compiles correctly:
- Assistant
Good, the file compiles. Let me now check for existing tests related to this area:
- Assistant
Let me check if there are unit tests related to this:
- Assistant
Let me look at the unit tests for continue_run_requirements:
- Assistant
Let me run the existing unit tests to make sure my changes don't break anything:
- Assistant
All 49 unit tests pass. Let me also run the background stream tests:
- Assistant
All tests pass. Now let me think about the fix more carefully. I realize I should simplify - passing just
run_contextis sufficient since it already containsdependencies. Let me verify by checking the agent'sacontinue_run_dispatchflow more carefully: - Assistant
Let me look at the
apply_to_contextmethod in the run options: - Assistant
Let me look at the implementation:
- Assistant
Let me look at
resolve_run_optionsto see what it does with dependencies: - Assistant
I see. Since
resolve_run_optionsmakes a defensive copy, passingdependenciesseparately is redundant when we're already passingrun_context. Let me simplify my fix: - Assistant
Let me verify the final changes:
- Assistant
Let me verify the final state of all4 changes:
- Assistant
Let me also verify the other3 changes:
- Assistant
Let me also verify the async versions:
- Assistant
Let me also verify the last one:
- Assistant
All four fixes are applied correctly. Let me run the unit tests again to make sure everything passes:
- Assistant
All 55 tests pass. Let me also run any other unit tests related to teams:
- Assistant
Let me run all the unit tests for the team:
- Assistant
The failure in
test_team_config.py::TestTeamFromDict::test_from_dict_with_db_postgresis a pre-existing issue related to PostgresDb not being available in the test environment, not related to my changes. Let me verify by running just the tests that could be affected by my change: - Assistant
The failures are all in
test_team_config.pyand are pre-existing. Let me skip those and run the rest: - Assistant
The failure in
test_team_skills.pyis also pre-existing. Let me skip that and the config test and run all other tests: - Assistant
All 347 tests pass (2 skipped). Let me now look at the final diff to confirm the changes:
- Assistant
The diff looks clean and minimal. Let me also verify that the agent's
continue_run(sync version) acceptsrun_context: - Assistant
Good, the agent's
continue_run(sync version) also acceptsrun_context. The fix is complete and minimal.Let me now run the complete unit test suite one more time to confirm everything is good:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.