fix(graph): add JsonCreator for InterruptionMetadata to support Jackson deserialization#4464
Open
NGshiyu wants to merge 2 commits intoalibaba:mainfrom
Open
fix(graph): add JsonCreator for InterruptionMetadata to support Jackson deserialization#4464NGshiyu wants to merge 2 commits intoalibaba:mainfrom
NGshiyu wants to merge 2 commits intoalibaba:mainfrom
Conversation
Contributor
Author
StateGraph stateGraph = new StateGraph(keyStrategyFactory)
//节点添加
.addNode("semantic_understanding", node_async(new SemanticUnderstandingNode(toolCallbackProvider, mcpClientCommonProperties))) // 语义理解节点
.addNode("weather_search", new WeatherSearchNode(toolCallbackProvider, mcpClientCommonProperties)) // 天气查询节点
;
//定义一个流转的边界路线图
stateGraph.addEdge(StateGraph.START, "semantic_understanding")
.addEdge("semantic_understanding", "weather_search")
.addEdge("weather_search", StateGraph.END);
public record WeatherSearchNode(org.springframework.ai.tool.ToolCallbackProvider toolCallbackProvider,
org.springframework.ai.mcp.client.common.autoconfigure.properties.McpClientCommonProperties mcpClientCommonProperties)
//implements NodeAction,
implements AsyncNodeAction,
InterruptableAction {
private static final Logger logger = LoggerFactory.getLogger(WeatherSearchNode.class);
private static final String instruction = """
# Role
智能天气助手
# Profile
你擅长调用工具获取实时天气数据,并将信息转化为清晰易读的预报计划。
# Rules
1. **日期逻辑**:若用户提供日期,查询该日天气;若未提供,默认查询最近 7 天预报。
2. **信息确认**:提取输入中的城市信息,避免干扰,若缺失城市信息,请先追问。
3. **输出要求**:数据展示结构化(温度、状况),并根据天气适当给出穿衣或出行建议。
""";
@Override
public CompletableFuture<Map<String, Object>> apply(OverAllState state) {
// 创建人工介入Hook - 所有工具调用都需要用户确认
HumanInTheLoopHook humanInTheLoopHook = HumanInTheLoopHook.builder()
// === 餐品信息查询 ===
.approvalOn("maps_weather", ToolConfig.builder()
.description("根据城市名称或者标准adcode查询指定城市的天气")
.build())
.build();
//............................................................................
try {
Optional<NodeOutput> nodeOutput = agent.invokeAndGetOutput(state.value(TravelGuideGraphConfig.SEMANTIC_ANSWER).get().toString(),
config);
return CompletableFuture.completedFuture(Map.of(TravelGuideGraphConfig.WEATHER_ANSWER, nodeOutput));
//return Map.of(TravelGuideGraphConfig.WEATHER_ANSWER, nodeOutput);
} catch (GraphRunnerException e) {
throw new RuntimeException(e);
}
} |
chickenlj
approved these changes
Mar 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Jackson constructor annotations to InterruptionMetadata (and its ToolFeedback) so graph state containing InterruptableAction nodes can be deserialized without IllegalArgumentException.
Changes:
- Added
@JsonCreator/@JsonPropertyconstructor forInterruptionMetadata. - Added
@JsonCreator/@JsonPropertyconstructor forToolFeedback. - Added null-safe initialization for collection fields during deserialization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/action/InterruptionMetadata.java
Outdated
Show resolved
Hide resolved
...alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/action/InterruptionMetadata.java
Outdated
Show resolved
Hide resolved
…i/graph/action/InterruptionMetadata.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Describe what this PR does / why we need it
When building a graph where a node implements
InterruptableAction, if that node is the last one before theendnode, the system currently throws anIllegalArgumentExceptionduring Jackson deserialization.This occurs because
InterruptionMetadataand its inner classToolFeedbacklack proper Jackson annotations. This PR adds@JsonCreatorand@JsonPropertyto the relevant constructors to ensure the graph state can be correctly reconstructed from JSON.Does this pull request fix one issue?
NONE
Describe how you did it
@JsonCreatorand@JsonPropertyannotations to the constructor ofInterruptionMetadata.@JsonCreatorand@JsonPropertyannotations to theToolFeedbackinner class constructor.metadata,toolFeedbacks, etc.) handle null values gracefully during deserialization to preventNullPointerException.Describe how to verify it
InterruptableActionnode as the penultimate node (beforeend).IllegalArgumentExceptionno longer occurs and the state is correctly restored.