Skip to content

fix(agui): parse request bodies with Jackson 2 codec - #2638

Open
jujn wants to merge 3 commits into
mainfrom
fix/agui-jackson2-request-deserialization
Open

fix(agui): parse request bodies with Jackson 2 codec#2638
jujn wants to merge 3 commits into
mainfrom
fix/agui-jackson2-request-deserialization

Conversation

@jujn

@jujn jujn commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

背景

AG-UI 的 MessageContent 依赖 Jackson 2 注解和自定义反序列化器。Spring Boot 4 默认使用 Jackson 3 解析请求体时,会导致 AG-UI 请求反序列化失败。

修改内容

  • AguiWebFluxHandler 改为先读取原始 JSON,再使用 AgentScope JSON codec(默认jackson2)解析。
  • AguiRestController 改用相同的请求体解析逻辑。
  • 增加文本和多模态 MessageContent 解析测试。
  • 不修改 Spring Boot 全局 Jackson 配置。

兼容性影响

默认情况下使用 AgentScope 的 Jackson 2 codec,可避免 Jackson 3 与 AG-UI 模型不兼容的问题。

如果用户通过 JsonUtils.setJsonCodec(...) 配置了自定义 codec,AG-UI 请求解析仍会遵循该全局配置。HTTP 请求格式、接口路径和 SSE 响应行为保持不变。

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Copilot AI lite review requested due to automatic review settings August 9, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR ensures AG-UI request bodies are deserialized using AgentScope’s JSON codec (defaulting to Jackson 2) rather than Spring Boot 4’s default Jackson 3 HTTP conversion, preventing deserialization failures for Jackson 2–annotated AG-UI models while leaving global Spring JSON configuration unchanged.

Changes:

  • Introduce AguiRequestBodyParser to parse raw JSON request bodies via JsonUtils.getJsonCodec() into RunAgentInput.
  • Update WebFlux and MVC entrypoints to read the raw JSON body as String and delegate parsing to AguiRequestBodyParser.
  • Add unit tests validating parsing for text and multimodal MessageContent.

Reviewed changes

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

File Description
agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/main/java/io/agentscope/spring/boot/agui/common/AguiRequestBodyParser.java New shared parser that converts raw JSON into RunAgentInput using AgentScope’s JSON codec.
agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/main/java/io/agentscope/spring/boot/agui/webflux/AguiWebFluxHandler.java Switch WebFlux handler to read raw JSON and parse via AguiRequestBodyParser.
agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/main/java/io/agentscope/spring/boot/agui/mvc/AguiRestController.java Switch MVC controller endpoints to accept raw JSON body strings and parse via AguiRequestBodyParser.
agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/test/java/io/agentscope/spring/boot/agui/common/AguiRequestBodyParserTest.java Add tests for text + multimodal parsing and null-body rejection.
Suppressed comments (2)

agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/main/java/io/agentscope/spring/boot/agui/mvc/AguiRestController.java:109

  • AguiRequestBodyParser.parse(body) can throw (invalid JSON, incompatible payload, etc.). In MVC this exception will propagate out of the controller method and typically become a 500, whereas previously @RequestBody RunAgentInput deserialization failures were mapped to a 400. Consider translating parse failures into an explicit 400 (e.g., ResponseStatusException).
            HttpServletRequest request) {
        RunAgentInput input = AguiRequestBodyParser.parse(body);
        return aguiMvcController.handleWithAgentId(input, agentIdHeader, agentId, request);

agentscope-extensions/agentscope-spring-boot-starters/agentscope-agui-spring-boot-starter/src/main/java/io/agentscope/spring/boot/agui/mvc/AguiRestController.java:92

  • Javadoc says @param body The run agent input, but the parameter is a raw JSON request body string. Updating this wording will avoid confusing API consumers.
     * @param body The run agent input

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.42105% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/spring/boot/agui/webflux/AguiWebFluxHandler.java 0.00% 4 Missing ⚠️
...scope/spring/boot/agui/mvc/AguiRestController.java 84.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/ext/spring-boot Spring Boot starters labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ext/spring-boot Spring Boot starters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants