支持 OpenAPI 固定请求头参数#119
Merged
OhYee merged 1 commit intoJun 17, 2026
Merged
Conversation
用户要求:从 OpenAPI protocolSpec 中解析字符串类型的 header 固定值,让 remote OpenAPI 工具调用时自动携带这些 header。 实现思路: - 仅将 in: header 且 schema.const 为字符串的参数解析为 fixed_headers - 仅将 in: header 且 schema.enum 只有一个字符串值的参数解析为 fixed_headers - 调用工具时合并 fixed_headers,并过滤同名调用参数,避免误传到 query 或 body - 明确不支持 parameter $ref 和非字符串固定值,并补充对应测试 Signed-off-by: 黑曜 <haotian.qht@alibaba-inc.com>
42d64b5 to
f7ffb37
Compare
Contributor
There was a problem hiding this comment.
⚠️ Not ready to approve
There are test-mocking and logging issues that can mask failures and potentially leak sensitive values in debug logs.
Pull request overview
This PR extends ToolOpenAPIClient to recognize “fixed” request headers from an OpenAPI protocol_spec (header parameters with schema.const or single-value string schema.enum), automatically apply them at call time, and ensure they are not exposed as tool inputs or accidentally forwarded into query/body payloads.
Changes:
- Parse path-level + operation-level parameters together, extracting fixed header values into a new per-operation
fixed_headersfield. - Merge fixed headers into request headers with case-insensitive override and filter same-named entries out of call arguments before sending.
- Add unit tests covering fixed header parsing (const/enum), non-string cases,
$refboundary, and sync/async call behavior.
File summaries
| File | Description |
|---|---|
agentrun/tool/api/openapi.py |
Adds fixed-header extraction/merging/filtering logic and applies it in call_tool / call_tool_async. |
tests/unittests/tool/test_openapi.py |
Adds coverage for fixed header parsing rules and header/argument behavior during invocation. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 3
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+966
to
+970
| mock_client_instance.__aenter__ = AsyncMock( | ||
| return_value=mock_client_instance | ||
| ) | ||
| mock_client_instance.__aexit__ = AsyncMock() | ||
| mock_async_client_class.return_value = mock_client_instance |
Comment on lines
448
to
450
| logger.debug( | ||
| f"Calling FunctionCall tool: {method} {url} with args={arguments}" | ||
| ) |
Comment on lines
511
to
514
| logger.debug( | ||
| f"Calling FunctionCall tool async: {method} {url} with" | ||
| f" args={arguments}" | ||
| ) |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动说明
in: header+schema.const字符串值。in: header+ 单值字符串schema.enum作为固定请求头。$ref解析为 fixed header;非字符串 const/enum 不解析为 fixed header。验证
uv run pytest tests/unittests/tool/test_openapi.py -quv run pytest tests/unittests/tool -quv run pyink --check --config pyproject.toml agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.pyuv run isort --check-only agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.pygit diff --check -- agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.py