Challenges in separating "thoughts" from "content" when using langgraph4j with Spring AI 2.0.0-M4 (Streaming) #373
-
|
Hi everyone, I’m currently working on a project using Spring AI 2.0.0-M4 with the GoogleGenAiChatModel (Gemini), and I’m trying to integrate langgraph4j to manage my agentic workflows. In my current standalone Spring AI implementation, I leverage the streaming capabilities to provide a rich UX. Specifically, I need to distinguish between the model's "thoughts" (reasoning) and the actual "content" (final response) to display them in different UI components. With Spring AI, this is straightforward because the Flux contains metadata that identifies the nature of the chunk: // Example of how I currently handle it in Spring AI
if (Boolean.TRUE.equals(chatResponse.getMetadata().get("isThought"))) {
// Render in Thought/Reasoning UI
} else {
// Render in Chat UI
}The Problem: My Questions: If not, is this a known limitation of the current Spring AI adapter in langgraph4j? Are there plans to expose these metadata fields in future releases to support "Reasoning" models like Gemini ? Being able to separate reasoning from output is becoming crucial for modern LLM interfaces, so any guidance or workaround would be greatly appreciated! Thanks in advance for the great work on this library. Code example: // Initialization
var stateSerializer = new SpringAIStateSerializer<>(AgentExecutorEx.State::new);
CompileConfig compileConfig = CompileConfig.builder()
.checkpointSaver(checkpointSaver)
.build();
AgentExecutorEx.Builder builder = AgentExecutorEx.builder()
.chatModel(this.chatModel)
.defaultSystem(processedSystemPrompt)
.stateSerializer(stateSerializer)
.streaming(streamEnabled);
// adding some tools and mcp clients
builder.toolsFromObject(proxiedChartingToolbox);
builder.toolsFromObject(proxiedTradingView);
ToolCallback[] mcpTools = mcpClientRegistry.getToolCallbacks(agentConfig.mcpServerIds());
builder.tools(Arrays.asList(mcpTools));
return builder.build().compile(compileConfig);
[...]
// Usage
var input = GraphInput.args(Map.of("messages", prompt.getUserMessage()));
var runnableConfig = RunnableConfig.builder()
.threadId("test")
.build();
var generator = agent.stream(input, runnableConfig);
var output = generator.stream()
.peek(s -> {
if (s instanceof StreamingOutput<?> out) { // here I cannot distinguish thoughts/content } |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Hi @symphony-enrico thanks you for valuable feedback and for evaluating LangGraph4j The solution is to extend I'll work on asap to expose all |
Beta Was this translation helpful? Give feedback.
-
|
Hi @symphony-enrico I've implemented feature and releasee it in the last Please test it and let me know so I can arrange a new official release |
Beta Was this translation helpful? Give feedback.
Hi @symphony-enrico thanks you for valuable feedback and for evaluating LangGraph4j
The solution is to extend
NodeOutputto support metadata by implementing the appropriateHasMetadatainterface.I'll work on asap to expose all
ChatResponsemetadata