Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [Bug] team.acontinuerun loss dependencies or sessionstate Description…

  1. 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.9
    

    Possible 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

    Additional Context

    No response

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /agno, current file: none) bash-$

  2. GLM Assistant

    I'll start by exploring the repository structure and understanding the issue.

  3. GLM Assistant

    Let me look at the acontinue_run method in the team.

  4. GLM Assistant

    Now let me look at the streaming version _acontinue_run_stream:

  5. GLM Assistant

    Now let me look at the _asetup_session function to understand how the run_context and session_state are handled:

  6. GLM Assistant

    Now let me look at the non-streaming version _aroute_requirements_to_members to compare:

  7. GLM Assistant

    Now let me understand the issue. When acontinue_run is called, the run_context has the dependencies/session_state set. But when routing to members, the member's acontinue_run is called without passing the dependencies/session_state/run_context.

    Let me look at how the member agent's acontinue_run works to understand what parameters it accepts and how it uses the run_context.

    But first, let me look at the _find_member_route_by_id function to understand what run_context does there.

  8. GLM Assistant

    Now let me look at the member agent's acontinue_run to understand its parameters:

  9. GLM Assistant

    Let me look at the agent's acontinue_run_dispatch to understand how it handles session_state and dependencies:

  10. GLM Assistant

    Now let me look at how the team's arun passes dependencies/session_state to members during the initial run (delegate_task), to follow the same pattern:

  11. GLM Assistant

    Let me look at the agent's _asetup_session to understand how session_state is loaded:

  12. GLM Assistant

    Let me look at the agent's _acontinue_run to understand how the session_state is loaded during continue_run.

  13. GLM Assistant

    Let me check whether the member agent's acontinue_run accepts session_state:

  14. GLM Assistant

    Let me check how member agents save sessions when part of a team (team_id handling):

  15. GLM Assistant

    This is key. Let me look at aread_or_create_session for the agent:

  16. GLM Assistant

    Let me look at apply_to_context and resolve_run_options for the agent:

  17. GLM Assistant

    Let me look at the sync version _route_requirements_to_members:

  18. GLM Assistant

    Let me look at the agent's sync continue_run signature:

  19. GLM Assistant

    Let me look at the RunContext class:

  20. GLM Assistant

    Now I have a clear understanding of the issue. Let me write a reproduction script first to confirm the issue. Let me look at existing tests for team continue_run with HITL to understand the test patterns:

  21. GLM Assistant

    Let me look at the test that tests member-level HITL with continue_run, to understand how member tools are tested.

  22. GLM Assistant

    Let me check how unit tests use mock models for team HITL:

  23. GLM Assistant

    Let me check the unit tests for team that might use mock models for HITL flows:

  24. GLM Assistant

    Now let me write a reproduction script that directly tests the routing functions with mocks, to confirm the member's acontinue_run doesn't receive dependencies/session_state:

  25. GLM Assistant

    The _find_member_route_by_id is in agno.team._tools. Let me look at how it's imported in _run.py. The routing functions import _find_member_route_by_id locally:

    from agno.team._tools import _find_member_route_by_id
    

    So I should patch agno.team._tools._find_member_route_by_id. Let me fix the script. The get_resolved_members is in agno.utils.callables. But I'm patching _find_member_route_by_id directly, so I don't need to patch get_resolved_members.

  26. GLM Assistant

    My sed messed up the script. Let me rewrite the file cleanly:

  27. GLM Assistant

    I've confirmed the issue. The member.acontinue_run is called without dependencies or run_context. Now let me implement the fix. Let me check the imports at the top of _run.py:

  28. GLM Assistant

    Good, RunContext is imported. Now let me check if Agent is imported for type hints.

  29. GLM Assistant

    Let me look at the metadata resolution in resolve_run_options for the agent:

  30. GLM Assistant

    Now I understand the full picture. Let me implement the fix. First, I'll create a helper function that propagates the team's run_context to the member's continue_run/acontinue_run. Let me view the exact location right before _route_requirements_to_members:

  31. GLM Assistant

    Now let me add the helper function right after _has_team_level_requirements:

  32. GLM Assistant

    Now let me insert this helper function into the file after _has_team_level_requirements:

  33. GLM Assistant

    Now let me update the 4 routing functions. Let me start with _route_requirements_to_members (sync, non-streaming):

  34. GLM Assistant

    Now let me update the 4 routing functions. Let me find the exact line numbers for each call site:

  35. GLM Assistant

    Let me view the exact content around each call site to do precise edits. First, _route_requirements_to_members (sync, non-streaming):

  36. GLM Assistant

    Now let me edit the first call site (sync, non-streaming). I'll replace lines 4918-4929:

  37. GLM Assistant

    Now let me edit the second call site (sync, streaming). Let me view it:

  38. GLM Assistant

    I see there are leftover orphaned lines (5041-5044). Let me remove them:

  39. GLM Assistant

    Now the sync streaming is fixed. Let me view the async non-streaming call site:

  40. GLM Assistant

    There are issues - the edit removed a line and left an orphaned ). Let me view and fix:

  41. GLM Assistant

    I need to fix two issues: the missing member_run_output.tools = ... line and an orphaned ). Let me fix:

  42. GLM Assistant

    Now let me remove the orphaned ) at line 5151:

  43. GLM Assistant

    There's now a duplicate **member_continue_kwargs, at lines 5149-5150. Let me fix it:

  44. GLM Assistant

    The async non-streaming is now correct. Now let me handle the last call site (async streaming). Let me view it:

  45. GLM Assistant

    There are orphaned lines 5267-5268 again. Let me remove them:

  46. GLM Assistant

    Now there's a duplicate **member_continue_kwargs, at lines 5265-5266. Let me fix it:

  47. GLM Assistant

    All 4 call sites are now updated. Let me verify the file compiles correctly:

  48. GLM Assistant

    Now let me run my reproduction script to verify the fix works:

  49. GLM Assistant

    The fix works. Now let me run the relevant existing unit tests to make sure I didn't break anything:

  50. GLM Assistant

    All passing. Now let me write a more comprehensive end-to-end test using a mock model to simulate the actual flow. Let me first check how tests mock the model for team delegation flows:

  51. GLM Assistant

    Let me look at how agent HITL tests mock the model to produce tool calls requiring confirmation:

  52. GLM Assistant

    Let me look for mock model patterns in unit tests that produce tool calls:

  53. GLM Assistant

    Let me look for a test that does a full agent run with a mock model producing a tool call:

  54. GLM Assistant

    Let me look at how ModelResponse represents tool calls (FunctionCall):

  55. GLM Assistant

    Let me search for tests that mock model to return tool_calls in a full run:

  56. GLM Assistant

    Let me write a comprehensive test that verifies all 4 routing functions propagate the kwargs correctly:

  57. GLM Assistant

    All 4 routing functions work correctly. Now let me write an end-to-end test with a real agent member and a mock model to verify the actual tool receives the user_token. Let me look at how the agent runs tools from a model response:

  58. GLM Assistant

    Let me look at how a ModelResponse with tool_calls is processed in the agent:

  59. GLM Assistant

    Let me run the broader team and agent unit test suites to ensure nothing is broken:

  60. GLM Assistant

    That failure is unrelated (postgres db not installed). Let me run the rest, deselecting the postgres test:

  61. GLM Assistant

    Both failures are pre-existing (missing db backends). Let me confirm these are unrelated by checking git status and running the specific continue_run tests plus agent tests:

  62. GLM Assistant

    Confirmed - these 2 failures are pre-existing (missing db backends), unrelated to my change. Now let me run the agent unit tests and the team HITL-related tests:

  63. GLM Assistant

    Now let me run the agent unit tests to ensure the agent side still works:

  64. GLM Assistant

    Only the 2 pre-existing db backend failures. Now let me write a full end-to-end test using a mock model to verify the actual tool receives the user_token. Let me look at how the agent processes a ModelResponse with tool_calls:

  65. GLM Assistant

    Let me look at the non-streaming handle_model_response to understand how invoke produces an assistant message with tool_calls:

  66. GLM Assistant

    Let me look at the agent's ahandle_tool_call_updates_stream to understand how confirmed tools are executed:

  67. GLM Assistant

    Let me look at arun_tool to understand how the run_context is passed to the tool function:

  68. GLM Assistant

    Let me search for existing mock models that yield tool calls in a full run, to build an end-to-end test:

  69. GLM Assistant

    Let me look at the base model's streaming arun method to understand what ainvoke_stream should yield for tool calls:

  70. GLM Assistant

    The full end-to-end mock model is complex; my routing tests comprehensively cover the fix. Let me verify edge cases of the helper and run the broader regression tests:

  71. GLM Assistant

    Let me look at the team basic test to understand the minimum mock model interface for a full run:

  72. GLM Assistant

    Let me look at call_model_stream_with_fallback and acall_model_with_fallback to understand the model interface:

  73. GLM Assistant

    So acall_model_stream_with_fallback calls model.aresponse_stream(**kwargs). Let me look at the base Model's aresponse_stream to understand the interface. The mock model needs to implement aresponse_stream.

    Let me look at the base Model's aresponse_stream.

  74. GLM Assistant

    Let me verify the agent's _acontinue_run_stream flow - does it execute confirmed tools before the model call?

  75. GLM Assistant

    Let me look at aprocess_response_stream to understand how to build a mock model for a final text response:

  76. GLM Assistant

    Let me check how a member agent's team_id is set when added to a team:

  77. GLM Assistant

    Now let me build a full end-to-end test through the team's acontinue_run with a mock model. Let me create it:

  78. GLM Assistant

    sqlalchemy isn't installed. Let me try without a DB. Let me check what happens in _aread_or_create_session without a DB:

  79. GLM Assistant

    Without a DB it creates an in-memory session. Let me check _normalize_requirements_payload to ensure _member_run_response is preserved:

  80. GLM Assistant

    Let me check what acheck_and_apply_approval_resolution does with a None db:

  81. GLM Assistant

    acheck_and_apply_approval_resolution returns early if db is None. Let me update the e2e test to not use a DB:

  82. GLM Assistant

    Let me check the RunRequirement.confirm and requires_confirmation:

  83. GLM Assistant

    Let me check is_resolved:

  84. GLM Assistant

    Let me update the e2e test to set confirmed=True directly on the tool (simulating post-confirm state):

  85. GLM Assistant

    The error is because I need to pass requirements to acontinue_run (as the user does in the issue). Let me update the test:

  86. GLM Assistant

    Progress! Dependencies are now propagated. The session_state is None because I didn't store it (in the issue, the user passes session_state to the initial arun, which stores it). Let me set team.session_state to simulate the stored session_state from the initial run:

  87. GLM Assistant

    Let me debug why the session_state isn't being loaded. Let me check _initialize_session_state and _load_session_state for the team:

  88. GLM Assistant

    Let me check the team's _initialize_session_state:

  89. GLM Assistant

    Let me add debug to capture the full session_state and dependencies in the tool:

  90. GLM Assistant

    The team's session_state has current_session_id/current_run_id but not user_token. Let me check _read_or_create_session (sync) to see if it loads team.session_state:

  91. GLM Assistant

    Let me check the Team class session_state attribute and whether initialize_team resets it:

  92. GLM Assistant

    session_state: Optional[Dict[str, Any]] = None is a dataclass field. Setting team.session_state = {...} should work. Let me check if initialize_team resets it. Let me look at initialize_team and _resolve_session_state.

    Actually, let me check the Team's __post_init__ or initialize_team for session_state handling.

  93. GLM Assistant

    Let me debug by patching _build_member_continue_run_kwargs to print the team's session_state:

  94. GLM Assistant

    The DEBUG print didn't appear. Let me run with full output to see what's happening:

  95. GLM Assistant

    The team's run_context.session_state doesn't have user_token - so team.session_state wasn't loaded. Let me add a debug print of team.session_state before the call:

  96. GLM Assistant

    The TEST print didn't appear - my replacement may not have matched. Let me check the file:

  97. GLM Assistant

    The session_state setting line is gone. Let me view the main function:

  98. GLM Assistant

    Let me rewrite the e2e test cleanly with team.session_state set:

  99. GLM Assistant

    The end-to-end test passes. Now let me verify it FAILS without my fix (to confirm the fix is what resolves it):

  100. GLM Assistant

    Confirmed - without the fix, both dependencies and session_state are None; with the fix, they're propagated. Let me also test the sync continue_run path:

  101. GLM Assistant

    Both sync and async paths work. Let me clean up temp files and review my final changes:

  102. GLM Assistant

    The diff looks clean. Let me run the syntax check and the relevant test suites once more to confirm everything works:

  103. GLM Assistant

    All 141 tests pass. Let me run the full team and agent unit test suites one final time (excluding the pre-existing db backend failures):

  104. GLM Assistant

    All 751 tests pass. Let me do a final review of the modified routing functions to ensure everything is clean:

  105. GLM Assistant

    All 8 call sites (2 per function × 4 functions) are correctly updated. Let me do a final verification by viewing the streaming sync function to confirm the structure is clean:

  106. GLM Assistant

    The structure is clean. Let me verify the helper function once more:

  107. GLM Assistant

    Let me check if there's a linter configured and run it on the modified file:

  108. GLM Assistant

    Ruff checks pass. Let me also verify formatting:

  109. GLM Assistant

    Let me see what ruff format wants to change:

  110. GLM Assistant

    Let me check if the original file passed ruff format (to know if I should apply formatting):

  111. GLM Assistant

    The original file was already formatted. Let me apply ruff format to keep consistency, then verify it only touches my changes:

  112. GLM Assistant

    Formatting applied cleanly, only touching my changes. Let me run the tests once more to confirm everything passes after formatting:

  113. GLM Assistant

    All tests pass. Let me do a final review of the complete diff:

  114. GLM Assistant

    The diff is clean and complete. Let me verify one edge case - that the team's sync continue_run_dispatch also accepts the kwargs I'm passing (for sub-Team members):

  115. GLM Assistant

    The team's continue_run_dispatch accepts all the kwargs I'm passing (run_context, knowledge_filters, dependencies, metadata), so the fix works for sub-Team members too. Let me confirm no temp files remain and do a final test run:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.