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 trace the async continuation and requirement-routing paths, compare them with the synchronous implementation, and locate relevant tests before making a focused fix. First I’ll inspect the repository status and the cited methods.
- Assistant
The cited async router exists alongside a synchronous counterpart. I’ll compare both implementations and then inspect how
acontinue_runconstructs and passesRunContext, especially where dependencies and session state are restored. - Assistant
The dispatcher initializes continuation
session_stateas{}, while the caller’s example passes its state underdependencies. More importantly, all four member-routing variants currently call member continuation without forwarding the parentrun_context, dependencies, or state. I’ll inspect complete call chains and agent continuation semantics to determine the intended propagation contract rather than patching only one branch. - Assistant
All member-routing branches omit context, so the bug affects async streaming as reported and likely sync/non-streaming too. I’ll inspect
Agent.continue_rundispatch and team continuation session restoration to avoid sharing an incorrectly identified run ID or mutable context across concurrent members. - Assistant
Team async setup may mutate
run_context.session_statefrom persisted session state, but explicit continuation dependencies still need to reach the member. I’ll verify that mutation and how agent dispatch derives its context. This will show whether forwarding the same object is safe or whether a member-specific copy is required. - Assistant
Passing the parent context object directly would preserve values, but its
run_idis the team run ID and concurrent member continuations may mutate runtime fields (tools,messages). The safer pattern is to create a member-specificRunContextcarrying user/session data while letting each agent own runtime fields. I’ll look for existing context-copy helpers and delegation code that already solves this. - Assistant
Existing delegation explicitly forwards
dependenciesand a copiedsession_state, which establishes the project convention. Continuation should mirror it. I’ll inspect those exact calls and setup behavior, then patch all member continuation variants consistently (with copied session state and explicit options). - Assistant
Because agent continuation has no direct
session_stateargument, the appropriate fix is a fresh memberRunContextplus explicituser_id. It should preserve dependencies, metadata, knowledge filters, and a shallow copy of session state, while using the member run ID. I’ll inspect the existing HITL tests and test style, then implement a private helper reused by all four routes. - Assistant
There are relevant integration and unit suites, but per the environment constraint I will not modify or add tests. I’ll add the reusable context constructor in
_run.py, importcopy, and pass the resulting context/user ID to every sync and async member continuation call so behavior is consistent across streaming modes. - Assistant
The automated edit correctly detected only three matching blocks before writing anything; the sync non-streaming router has a slightly different structure. No file was changed. I’ll inspect all four method boundaries and apply a more precise transformation.
- Assistant
The special block differs only by an intervening comment. I’ll perform explicit edits: insert the helper before the routers, add member context construction after each lookup block, and augment all eight continuation calls in the bounded router region.
- Assistant
The patch now mirrors delegation semantics and isolates each member context, including concurrent async continuations. Before running tests, I’ll verify formatting/lint expectations and execute the focused continuation unit and HITL integration tests.
- Assistant
The focused test command is blocked before execution because
uvattempts to resolve mutually incompatible optional extras (a2arequireshttpx>=0.28.1, whilebraverequires<0.26). This is an environment/project lock-resolution issue unrelated to the patch. I’ll use the repository’s existing interpreter dependencies if available, run static compilation/lint, and create a temporary (non-repository) mock reproduction that directly exercises the async streaming router and asserts propagated values. - Assistant
The system environment has the required package import, pytest, and Ruff; compilation and Ruff pass. I’ll run the focused suites directly with
PYTHONPATHinstead of invoking dependency resolution. - Assistant
Combining unit and integration paths loads the integration root
conftest, which requires unavailablesqlalchemy. I’ll run only the unit tests first; then I’ll use a direct temporary reproduction for propagation, avoiding repository test changes and optional database dependencies. - Assistant
All 55 focused unit tests pass. I’ll now reproduce the exact failing route in isolation with a fake paused member: invoke
_aroute_requirements_to_members_stream, capture therun_contextreceived bymember.acontinue_run, and assert that dependencies/session state/user/session/member run ID are retained and that session state is copied rather than shared. - Assistant
The targeted reproduction now passes and confirms the fix for the reported async streaming path. I’ll review the integration tests’ dependencies and run them if only the missing lightweight database package is needed; I’ll also inspect the final diff for redundant assignments or edge cases before submission.
- Assistant
Those integration tests require an API key and will be skipped, but their shared conftest still needs SQLAlchemy to collect. Installing that missing test dependency is safe and allows verifying collection/skips; I’ll do so and rerun the focused integration files.
- Assistant
Integration files collect successfully and all seven tests skip as expected without
OPENAI_API_KEY. The focused unit suite and direct regression both pass. I’ll run the complete team unit test directory to catch signature/mock regressions across other routing paths, then perform final diff/status review. - Assistant
The full team unit suite reached 411 passes and 2 skips, then failed on an unrelated fixture path: it looked for sample skills under
/agno/libs/agno/cookbook, which does not exist in this checkout. The changed continuation tests had already passed. I’ll clean up redundantmember_run_idreassignments in fallback branches, rerun lint and the direct regression, and inspect the final diff. - Assistant
The final patch is clean and Ruff/compilation pass. The only full-suite failure is confirmed unrelated to this change and caused by a missing sample fixture directory. I’ll run the focused continuation tests once more after cleanup, verify only the intended source file changed, then submit with the requested checklist assessment.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.