adk.Runner.Run 无法流式输出reasoning_content
Describe the bug
adk helloworld 示例使用deepseek-r1模型
流式输出的Message中ReasoningContent总为空 通过tracing是可以看到模型进行了推理:
{
"completion": "Hello there! 😊 I'm your friendly AI assistant, here to help you with anything you might need! Whether you're curious about facts, need help with writing, want to learn something new, or just feel like chatting—I've got you covered. Ask me questions, share your thoughts, or tell me what you're working on, and I'll do my best to assist you with enthusiasm and care! 💬✨\n\nSo... what can I do for you today? 💛",
"reasoning": "Okay, the user just asked me to introduce myself. That's a simple and friendly opener - seems like they might be new here or just want to establish a connection. \n\nHmm, looking at the context, I should keep this warm and inviting since they started with a polite \"Hello\". No signs of urgency or complexity in the query. Maybe they're testing the waters before asking something else? \n\nRight, I'll position myself as approachable but capable - highlight my versatility while leaving room for them to steer the conversation. Should mention core functions like answering questions and helping with tasks, but avoid overwhelming with details. \n\nNoted they didn't specify any needs yet, so ending with an open question (\"What can I do for you?\") feels right. The heart emoji in my draft reply maintains the warmth they initiated. \n\n...Wait, is \"chatty companion\" too casual? No, their tone was informal so it matches. Keeping it light!\n",
"rawRequest": {
"model": "deepseek/deepseek-r1-0528",
"stream": true,
"stream_options": {
"include_usage": true
}
}
}
To Reproduce eino-examples中helloworld稍作修改:
/*
* Copyright 2025 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"context"
"fmt"
"io"
"log"
"os"
"github.com/cloudwego/eino/adk"
"github.com/cloudwego/eino/schema"
"github.com/cloudwego/eino-ext/components/model/openai"
)
func main() {
ctx := context.Background()
// 初始化模型
model, err := openai.NewChatModel(ctx, &openai.ChatModelConfig{
APIKey: os.Getenv("OPENAI_API_KEY"),
Model: os.Getenv("OPENAI_MODEL"),
BaseURL: os.Getenv("OPENAI_BASE_URL"),
})
if err != nil {
log.Fatal(err)
}
// 创建 ChatModelAgent
agent, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
Name: "hello_agent",
Description: "A friendly greeting assistant",
Instruction: "You are a friendly assistant. Please respond to the user in a warm tone.",
Model: model,
})
if err != nil {
log.Fatal(err)
}
// 创建 Runner
runner := adk.NewRunner(ctx, adk.RunnerConfig{
Agent: agent,
EnableStreaming: true,
})
// 执行对话
input := []adk.Message{
schema.UserMessage("Hello, please introduce yourself."),
}
events := runner.Run(ctx, input)
for {
event, ok := events.Next()
if !ok {
break
}
if event.Err != nil {
log.Printf("错误: %v", event.Err)
break
}
if event.Output != nil && event.Output.MessageOutput != nil {
mv := event.Output.MessageOutput
if mv == nil {
break
}
if !mv.IsStreaming {
m := event.Output.MessageOutput.Message
if m == nil {
break
}
fmt.Printf("non-streaming message: %v", m)
} else {
// process streaming message
if event.Output.MessageOutput.MessageStream == nil {
break
}
s := event.Output.MessageOutput.MessageStream
for {
chunk, err := s.Recv()
if err != nil {
if err == io.EOF {
break
}
break
}
if chunk.ReasoningContent != "" {
fmt.Printf("reasoning token: %s\n", chunk.ReasoningContent)
continue
}
if chunk.Content == "" && len(chunk.ToolCalls) == 0 {
continue
}
fmt.Printf("content token: %s\n", chunk.Content)
}
}
}
}
}
环境变量: "OPENAI_API_KEY": "xxx", "OPENAI_BASE_URL": "https://openrouter.ai/api/v1/", "OPENAI_MODEL": "deepseek/deepseek-r1-0528",
输出: bogon:eino-examples me$ go run ./adk/helloworld/ content token: Hello content token: there content token: ! content token: 😊 I content token: 'm your content token: friendly AI content token: assistant, content token: ready content token: to help content token: you with content token: questions content token: , ideas content token: , or content token: everyday content token: tasks. content token: Whether you content token: need to content token: learn something content token: new, content token: brainstorm a content token: project, content token: write content token: creatively content token: , organize content token: information, content token: or just content token: chat— content token: I’ content token: m here content token: for you content token: !
content token: I’ content token: m powered content token: by advanced content token: language technology content token: , so content token: I can content token: understand content token: and respond content token: thoughtfully content token: in content token: real content token: -time. content token: Ask content token: me anything content token: —from content token: trivia content token: and content token: homework content token: help to content token: deep content token: conversations or content token: light content token: hearted fun content token: . content token: 💬✨ content token:
What content token: brings you content token: here today content token: ? I content token: ’d content token: love to content token: get content token: to know content token: you! content token: content token: 🌟 bogon:eino-examples me$
Expected behavior
ReasoningContent支持流式输出
Screenshots
If applicable, add screenshots to help explain your problem.
Version:
Please provide the version of {project_name} you are using.
Environment:
The output of go env.
Additional context
Add any other context about the problem here.
用 github.com/cloudwego/eino-ext/components/model/openrouter
@HhSen openrouter申请的模型,请使用 github.com/cloudwego/eino-ext/components/model/openrouter ,如果要使用openai的ChatModel 请升级到最新版本测试,但强烈建议使用model/openrouter 做初始化ChatModel ;因为openrouter 有一些特化逻辑与openai api 不相同