Skip to content

fix(http-tool): serialize formatted arguments in JSON mode - #8349

Open
Winoren (Winoren) wants to merge 1 commit into
microsoft:mainfrom
Winoren:fix/http-tool-json-formats
Open

Winoren (Winoren) wants to merge 1 commit into
microsoft:mainfrom
Winoren:fix/http-tool-json-formats

Conversation

@Winoren

Copy link
Copy Markdown

Why are these changes needed?

HttpTool accepts JSON Schema string formats such as date, date-time, and uuid. The generated input model validates those strings into Python date, datetime, and UUID instances. run() currently exports them with model_dump() in Python mode and passes the resulting objects to HTTPX's JSON encoder. Valid tool arguments consequently raise TypeError: Object of type ... is not JSON serializable before any HTTP request is sent.

Export arguments in Pydantic's JSON mode so validated formats become JSON-compatible values. Path parameters are still removed from the body, and ordinary boolean/integer values retain their JSON types.

Nine regression cases cover all three formats with POST, PUT, and PATCH through the real HttpTool.run_json() and HTTPX request encoding. Only the transport is replaced with MockTransport; no external service is called by these cases.

Related issue number

Found while inspecting the current HTTP tool implementation; no linked issue. This is separate from the existing configuration round-trip and path-escaping fixes.

Validation

Based on upstream 027ecf0a379bcc1d09956d46d12d44a3ad9cee14, using an isolated Python 3.11 environment installed with uv (editable core/ext/test-utils, HTTP tool dependencies, and local test server dependencies):

  • Before the fix: all 9 new cases fail with JSON serialization errors for date, datetime, or UUID.
  • python -m pytest python/packages/autogen-ext/tests/tools/http/test_http_tool.py -k 'not invalid_request' -q: 23 passed, 1 deselected after the fix.
  • Full HTTP test file: 23 passed, 1 failed. Existing test_invalid_request expects host fake to raise a connection error, but it receives a response in this environment. Restoring the upstream implementation and running that test alone reproduces the same failure. Removing proxy environment variables also did not resolve it; no change to that test is included here.
  • Ruff 0.4.8 lint and format checks on both changed files: passed.
  • Mypy 1.13.0, --config-file python/pyproject.toml --follow-imports=silent on both changed files: passed.
  • git diff --check: passed.

Full workspace checks and documentation builds were not run.

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/. No documentation change is needed for this serialization correction.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed. Local results and the baseline failure are documented above; upstream checks are pending.

Prepared with Codex assistance.

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