Skip to content

Python: preserve local history with skill approvals#5686

Open
he-yufeng wants to merge 1 commit intomicrosoft:mainfrom
he-yufeng:fix/skill-script-approval
Open

Python: preserve local history with skill approvals#5686
he-yufeng wants to merge 1 commit intomicrosoft:mainfrom
he-yufeng:fix/skill-script-approval

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Motivation and Context

Fixes #5672.

When a local Agent session is used with SkillsProvider(require_script_approval=True), the approval resume turn needs the previous assistant function_call in the messages sent to the model. Before this change, adding a context provider such as SkillsProvider prevented the default in-memory history provider from being added, so the approved script result could be replayed without the original tool call.

Description

This changes the local history auto-injection guard to check for an existing HistoryProvider, rather than checking whether any context provider exists. The injected InMemoryHistoryProvider is inserted before other providers so stored conversation history is loaded before provider-added context for the current turn.

The regression test covers a code-defined skill script with require_script_approval=True, resumes with request.to_function_approval_response(True), and asserts that the final model call includes the original assistant function_call before the matching function_result.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

To verify:

  • uv run pytest packages\core\tests\core\test_agents.py::test_chat_agent_skill_script_approval_replays_stored_tool_call -q
  • uv run pytest packages\core\tests\core\test_agents.py -q
  • uv run pytest packages\core\tests\core\test_function_invocation_logic.py -q
  • uv run ruff check agent_framework\_agents.py tests\core\test_agents.py --no-fix
  • uv run ruff format agent_framework\_agents.py tests\core\test_agents.py --check
  • uv run python -m py_compile agent_framework\_agents.py tests\core\test_agents.py
  • git diff --check

I also ran uv run poe test -P core; it completed with one unrelated failure in tests/core/test_telemetry.py::test_detect_hosted_fallback_import_error while patching builtins.__import__ around azure.ai.agentserver. I did not change telemetry code. I tried uv run poe syntax -P core --check; the whole-package run reports an existing line-length issue in tests/core/test_skills.py:1193, outside this change.

@moonbox3 moonbox3 added the python label May 7, 2026
Copilot AI review requested due to automatic review settings May 7, 2026 06:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a local-session regression where enabling SkillsProvider(require_script_approval=True) prevented the default in-memory history from being used, causing approval resume turns to omit the prior function_call needed to correctly replay an approved tool/script execution.

Changes:

  • Adjust local history auto-injection to look specifically for an existing HistoryProvider (instead of “any context provider”).
  • Insert the auto-injected InMemoryHistoryProvider ahead of other context providers so stored conversation history loads before per-turn context augmentation.
  • Add a regression test asserting the approval resume model call includes the original function_call before the corresponding function_result.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/packages/core/agent_framework/_agents.py Fixes local history auto-injection logic to preserve history alongside other context providers and ensures correct provider ordering.
python/packages/core/tests/core/test_agents.py Adds a regression test covering skill script approvals and verifying correct replay ordering of tool call/result in the final model call.

@he-yufeng he-yufeng force-pushed the fix/skill-script-approval branch from ead9573 to d11a50a Compare May 7, 2026 16:27
@he-yufeng he-yufeng force-pushed the fix/skill-script-approval branch from d11a50a to 0d58f00 Compare May 7, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: require_script_approval=True fails with 400 "Expected toolResult blocks" for code-defined (@script) skills

3 participants