#1328·eino

schema: ConcatAgenticMessages turns a custom AssistantGenText.Extension into reflect.Value

Author: vitolee-1018Created Sep 28, 2026Updated Sep 28, 2026

Description

When schema.ConcatAgenticMessages merges streamed AssistantGenText chunks, a custom Extension (the field for models other than OpenAI and Claude, supplied by the component implementer) comes back as a reflect.Value instead of its original type. As a result:

  • type assertions on the merged Extension fail;
  • json.Marshal writes "extension":{}, so the extension data is silently dropped when the message is logged or persisted as JSON.

Affected branches: main (ba04fde) and alpha/10 (58daeda).

Root cause

internal.ConcatSliceValue returns a reflect.Value, and concatAssistantGenTexts assigns it directly to the any field (schema/agentic_message.go:1494 on alpha/10, :1466 on main):

go
ret.Extension, err = internal.ConcatSliceValue(extensions)

The other three callers in the same file unwrap the result with .Interface(): concatAgenticResponseMeta (:1079), concatServerToolCalls (:1902) and concatServerToolResults (:1957) (line numbers on alpha/10). Only this call site doesn't.

Both paths are affected: a single chunk carrying the extension (the Len() == 1 shortcut in ConcatSliceValue), and multiple chunks merged by a registered concat function.

Steps to reproduce

go
package main

import (
    "encoding/json"
    "fmt"

    "github.com/cloudwego/eino/schema"
)

type MyExt struct {
    Citations []string `json:"citations"`
}

func main() {
    chunks := []*schema.AgenticMessage{
        {Role: schema.AgenticRoleTypeAssistant, ContentBlocks: []*schema.ContentBlock{
            schema.NewContentBlockChunk(&schema.AssistantGenText{Text: "Hello "}, &schema.StreamingMeta{Index: 0}),
        }},
        {Role: schema.AgenticRoleTypeAssistant, ContentBlocks: []*schema.ContentBlock{
            schema.NewContentBlockChunk(&schema.AssistantGenText{
                Text:      "world",
                Extension: &MyExt{Citations: []string{"doc-1"}},
            }, &schema.StreamingMeta{Index: 0}),
        }},
    }

    msg, err := schema.ConcatAgenticMessages(chunks)
    if err != nil {
        panic(err)
    }

    text := msg.ContentBlocks[0].AssistantGenText
    _, ok := text.Extension.(*MyExt)
    fmt.Printf("Extension type: %T, type assertion ok: %v\n", text.Extension, ok)

    b, _ := json.Marshal(text)
    fmt.Println(string(b))
}

Actual output:

Extension type: reflect.Value, type assertion ok: false
{"text":"Hello world","extension":{}}

Expected output:

Extension type: *main.MyExt, type assertion ok: true
{"text":"Hello world","extension":{"citations":["doc-1"]}}

Proposed fix

Unwrap the result the same way concatAgenticResponseMeta does:

go
var ext reflect.Value
ext, err = internal.ConcatSliceValue(extensions)
if err != nil {
    return nil, err
}
ret.Extension = ext.Interface()