Skip to content

fix(core): await deferred function tool results - #8341

Open
fhgffy wants to merge 1 commit into
microsoft:mainfrom
fhgffy:fix/function-tool-awaitable-results
Open

fhgffy wants to merge 1 commit into
microsoft:mainfrom
fhgffy:fix/function-tool-awaitable-results

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 11, 2026

Copy link
Copy Markdown

Why are these changes needed?

FunctionTool accepts callables returning an Awaitable, but a synchronous tracing decorator around an async function is dispatched through the executor and its coroutine is returned without being awaited. run_json therefore returns a coroutine object, the underlying operation never runs, and the tool result can be serialized as a coroutine repr.

Await deferred results from synchronous callables, preserving the existing cancellation contract: functions accepting cancellation_token handle it themselves; other deferred operations are linked to the token. Regression tests cover tracing decorators, partials, token injection, Future results, exception propagation, and cancellation cleanup.

Validation on Windows with Python 3.12.2 and locked dependencies:

  • The seven regression cases fail on the base implementation and pass with the patch; the public API reproduction changes from an unexecuted coroutine to the resolved result.
  • All 233 core tests pass. Core format, Ruff, mypy, Pyright, and wheel build pass. An independent review reran all 45 tool tests.
  • The AgentChat suite reports 375 passed, 5 skipped, and one failure in test_self_debugging_loop. The same LF/CRLF assertion failure reproduces using the original core source.
  • Full optional-extra setup is blocked by the Windows MSVC requirement of chroma-hnswlib; the complete optional-extension matrix, documentation build, and .NET checks were not run.

The documented API contract already permits awaitable results, so no documentation change is needed.

Related issue number

N/A

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/. No documentation change is needed for this correction to the existing contract.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed. GitHub checks are pending.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant