diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index ae02ea4..7575004 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -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)