Skip to content

[Go] streamed chunks do not include index, especially with multiple messages (tool calling) #3687

@pavelgj

Description

@pavelgj
resp, err := genkit.Generate(ctx, g,
	ai.WithModelName("googleai/gemini-2.5-flash"),
	ai.WithMessages(h...),
	ai.WithTools(convertTemperatureTool),
	ai.WithStreaming(cb),
)

when I say: "convert 20 c to f" I get chunks:

data: {"message": {"content":[{"toolRequest":{"input":{"from":"celsius","temperature":20,"to":"fahrenheit"},"name":"convertTemperature"}}]}}

data: {"message": {"content":[{"toolResponse":{"name":"convertTemperature","output":68}}],"role":"tool"}}

data: {"message": {"content":[{"text":"20 degrees Celsius is 68 degrees Fahrenheit."}]}}

but expect it to be the same as in JS, something like:

data: {"message":{"role":"model","index":0,"content":[{"toolRequest":{"name":"temperatureConverter","input":{"to":"F","from":"C","temperature":20},"ref":"0"}}]}}

data: {"message":{"role":"tool","index":1,"content":[{"toolResponse":{"name":"temperatureConverter","ref":"0","output":68}}]}}

data: {"message":{"role":"model","index":2,"content":[{"text":"2"}]}}

data: {"message":{"role":"model","index":2,"content":[{"text":"0 degrees Celsius is 68 degrees Fahrenheit."}]}}

Note the changing index.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggo

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions