streaming: tool output streams into [tool:] block, no new roles

This commit is contained in:
ollie 2026-07-19 21:36:55 +02:00
parent 805933453f
commit 9c1dd58474
1 changed files with 8 additions and 1 deletions

View File

@ -298,8 +298,13 @@ func run(ctx context.Context, cfg agentConfig, state state) error {
var result string
var resultBlocks []backend.ContentBlock
var isErr bool
streamed := false
if cfg.Exec != nil {
streamCtx := tools.WithOutputStream(ctx, func(data string) {
if !streamed {
emit(cfg, Event{Role: "tool", Name: tc.Name})
streamed = true
}
emit(cfg, Event{Role: "tool", Name: tc.Name, Content: data})
})
out, blocks, err := cfg.Exec(streamCtx, tc.Name, tc.Arguments)
@ -349,7 +354,9 @@ func run(ctx context.Context, cfg agentConfig, state state) error {
if readSafe && !isErr {
resultCache.Store(tc.Name+"\x00"+string(tc.Arguments), result)
}
emit(cfg, Event{Role: "tool", Name: tc.Name, Content: result})
if !streamed {
emit(cfg, Event{Role: "tool", Name: tc.Name, Content: result})
}
tier := TierHot
if !isErr && cfg.ClassifyTier != nil {
tier = cfg.ClassifyTier(tc.Name, tc.Arguments)