fix(agui): parse request bodies with Jackson 2 codec - #2638
Conversation
There was a problem hiding this comment.
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
AguiRequestBodyParserto parse raw JSON request bodies viaJsonUtils.getJsonCodec()intoRunAgentInput. - Update WebFlux and MVC entrypoints to read the raw JSON body as
Stringand delegate parsing toAguiRequestBodyParser. - 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 RunAgentInputdeserialization 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
背景
AG-UI 的
MessageContent依赖 Jackson 2 注解和自定义反序列化器。Spring Boot 4 默认使用 Jackson 3 解析请求体时,会导致 AG-UI 请求反序列化失败。修改内容
AguiWebFluxHandler改为先读取原始 JSON,再使用 AgentScope JSON codec(默认jackson2)解析。AguiRestController改用相同的请求体解析逻辑。MessageContent解析测试。兼容性影响
默认情况下使用 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.
mvn spotless:applymvn test)