Support tool middleware in third-party providers - #1159
Conversation
Add ProviderConfig.ManagesToolExecution so providers receive function tools wrapped with middleware without importing internal packages. Apply wrapping immediately before the provider runs while preserving the options seen by outer middleware. Expose WithFuncCallID for provider-owned invocations and enable the capability in Copilot. Keep harness wrapping for additional tools. Test capability opt-in, dynamic tools, middleware behavior, option preservation, and repeated invocations.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review comments remain.
Review effort: Lite
Findings: None
What changed in this PR
Adds provider-managed tool execution middleware support for third-party providers, including Copilot integration and public function call IDs.
Changes:
- Adds
ManagesToolExecutionand non-mutating function-tool wrapping. - Exposes
WithFuncCallIDand updates Copilot/autocall execution. - Adds regression coverage for middleware, metadata, approvals, and repeated invocations.
| File | Description |
|---|---|
provider/copilotprovider/copilot.go |
Enables managed execution and applies call IDs. |
provider/copilotprovider/copilot_internal_test.go |
Updates Copilot middleware test coverage. |
agent/middleware.go |
Wraps provider-executed tools and exposes call IDs. |
agent/middleware_test.go |
Tests middleware composition and preservation behavior. |
agent/harness/toolautocall/autocall.go |
Uses the public call-ID helper. |
agent/agent.go |
Adds provider tool-execution capability configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Scope: public API, user-visible behavior Changed Go contract: New exported field Upstream evidence reviewed:
Result: aligned. The new
|
Summary
Third-party providers cannot import the internal wrapper used for function invocation middleware. Add
ProviderConfig.ManagesToolExecutionso the agent wrapsWithToolfunction tools immediately before the provider'sRun, after provider middleware, without changing caller-owned options.Expose
agent.WithFuncCallIDfor provider-owned callbacks and enable the capability in Copilot. Automatic tool execution keeps its existing internal wrapping for request tools andAdditionalTools.Add regression tests for capability opt-in, dynamic tools, middleware composition and short-circuiting, call IDs, schema and approval preservation, unchanged options, and repeated invocations.
Validation