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 synchronous continuation and initial-run context construction, then reproduce the context loss with the narrowest existing tests or a temporary script. First I’ll inspect the repository and relevant methods.
- Assistant
The implementation is split between the public overloads and
_run.py; the suspected router is indeed present. I’ll inspect its context creation, its caller, and the analogous sync/non-stream implementations to identify exactly which fields should be restored. - Assistant
The streaming router passes only
session_idinto each member continuation, whereas the member needs the restored team continuation context. I’ll inspect all four routers and the dispatch/context setup to determine whether both dependencies and session state must be explicitly forwarded, and whether the same defect also exists in non-stream async continuation. - Assistant
acontinue_run_dispatchaccepts no separatesession_stateparameter; in this API,dependenciesare resolved into the continuationRunContext, while persisted session state is loaded by setup. I’ll now inspect that resolution and the exact member Agent API so the fix forwards canonical fields without sharing inappropriate team-only state. - Assistant
All sync and async member routers currently omit context, so the bug is broader than the cited streaming function. The team continuation’s
_asetup_sessionlikely hydratesrun_context.session_state; forwarding the sameRunContextobject to an Agent would carry a team run ID and may be mutated. I’ll inspect Agent dispatch and established delegation code for the intended child-context pattern. - Assistant
The Agent dispatcher uses a supplied
RunContextdirectly, so passing the team object could retain the wrongrun_id. Existing team delegation forwards dependencies/session state as explicit child-run inputs instead. I’ll inspect those calls and context setup to mirror the established convention. - Assistant
Agent
continue_rundoes not expose asession_stateargument, so dependencies can be passed explicitly, but restored team state requiresrun_context. The safest solution is to construct a member-specificRunContextpreserving the member run ID while copying the restored state and resolved dependencies/metadata/filter references. I’ll check theRunContextmodel and Agent continuation internals for parent/team identifiers and state mutation semantics before implementing a helper used by all routers. - Assistant
I need the full
RunContextfields and the continuation setup sections that reload state, because they determine whether a shallow copy is sufficient and whether member continuation would overwrite the supplied state from its own session. - Assistant
A supplied member context survives Agent state loading because the loader merges stored state into the supplied dictionary. To avoid contaminating the team’s run metadata and to match initial delegation’s “send a copy” policy, I’ll add a small helper that creates a child
RunContextwith the member run ID, same session/user, shallow-copied session state, and inherited dependencies/filters/metadata. Then I’ll pass it in every member continuation variant, including fallback-by-ID. - Assistant
I’ll implement the helper near the routing utilities and update all eight call sites (sync/async × stream/non-stream × run-output/fallback). Keeping behavior unchanged when no team context is supplied preserves direct internal callers and simplifies compatibility.
- Assistant
The scripted replacement matched the newly inserted
session_idlines on its second pass, creating duplicate keywords in the first four calls rather than reaching async calls. I’ll correct those duplicates and explicitly patch the async router sections, then compile immediately. - Assistant
I’ll remove each duplicated keyword pair and then insert one member context into the four untouched async calls using exact call fragments, avoiding broad replacements.
- Assistant
The transaction aborted before writing because one async fragment differs in its type-ignore annotation. I’ll split the correction into two steps: first reliably deduplicate and save; then inspect the remaining calls and patch them based on their actual text.
- Assistant
The async calls are now clear and uniform. I’ll insert the contexts into each, then run syntax checks and inspect the resulting diff for accidental unrelated edits.
- Assistant
The prefix also matches sync calls even though they already have context, so global counting is misleading. I’ll scope replacements to the async portion of the file, where exactly two output calls and two fallback calls remain.
- Assistant
The code now compiles and all four routing modes have both branches covered. Next I’ll locate the focused team continuation test modules and inspect their fixtures; I can use an existing mock-based test path to verify that dependencies/session state reach a member tool without requiring a live model.
- Assistant
I’ll run the focused unit module first. In parallel, I’ll inspect test classes around routing to understand any failures and then use a temporary, untracked script to assert the exact child context passed by the reported async streaming path.
- Assistant
Focused tests pass. I’ll now execute a temporary mock reproduction of the exact
_aroute_requirements_to_members_streamroute: a paused member continuation will capture its received context, and assertions will verify member run identity, token availability in both dependencies and session state, state isolation from the team context, and user/session preservation. - Assistant
The temporary reproduction used
member_agent_idas a constructor field, but this model stores routing metadata as runtime attributes (as the production propagation helper does). I’ll correct the fixture by assigning those fields after construction and rerun the same verification. - Assistant
RunRequirementalso requires a tool execution. I’ll add the minimal confirmation tool payload and rerun; this remains a temporary in-memory check and does not alter tests or repository files. - Assistant
The exact reported async streaming path now passes the reproduction. I’ll run the complete team HITL integration directory, which appears designed around mocked models and exercises sync/async continuation variants; if external configuration prevents it, I’ll report that explicitly and still run the broader unit team suite.
- Assistant
The integration suite is blocked at collection because optional
sqlalchemyis not installed. Rather than modifying dependencies for a potentially database-backed suite, I’ll run all team unit tests, then inspect static typing/lint conventions and the final diff. - Assistant
The broader unit run reached 299 passes before an unrelated database lazy-import test failed (
agno.db.postgresunavailable, consistent with missing SQLAlchemy). I’ll now run Ruff on the changed file and inspect dependency resolution to ensure inherited dependency dictionaries cannot be unexpectedly mutated across concurrent member continuations. - Assistant
Lint and whitespace checks pass. I’ll inspect dependency resolution and the complete final diff; if resolution mutates the inherited dictionary in place, I’ll defensively copy it as well, especially because async non-stream routing continues multiple members concurrently.
- Assistant
Dependency resolution does mutate the context dictionary in place. Since async routing may continue several members with
gather, sharing it would create a race and alter the restored team context. I’ll shallow-copy dependencies too; resolved service objects remain shared as intended, while each member owns the mapping. - Assistant
I’ll rerun the focused continuation unit tests after the defensive copy and repeat the reproduction with an added assertion that dependency mappings are isolated. Then I’ll review repository status and final diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.