show agent reasoning output
This commit is contained in:
parent
68616cb247
commit
9789eb56ff
|
|
@ -34,12 +34,20 @@ func (ag *Agent) initChatHandler() {
|
|||
ag.AppendChat(format.FormatEvent(ev.Role, ev.Name, ev.Content, ev.OutputFormat))
|
||||
|
||||
case "reasoning":
|
||||
// Absorbed silently
|
||||
if streamingRole != ev.Role {
|
||||
if streamingRole != "" {
|
||||
if streamingFence != "" {
|
||||
ag.AppendChat([]byte("\n" + streamingFence + "\n"))
|
||||
streamingFence = ""
|
||||
}
|
||||
ag.AppendChat([]byte("\n" + format.EndTag + "\n"))
|
||||
}
|
||||
ag.AppendChat([]byte(format.RoleDelim(ev.Role) + "\n"))
|
||||
streamingRole = ev.Role
|
||||
}
|
||||
ag.AppendChat(format.FormatEvent(ev.Role, ev.Name, ev.Content, ev.OutputFormat))
|
||||
|
||||
case "tool":
|
||||
if ev.Name == "reasoning_think" {
|
||||
return
|
||||
}
|
||||
if streamingRole == "tool" {
|
||||
if ev.Content == "" {
|
||||
if streamingFence != "" {
|
||||
|
|
@ -134,6 +142,9 @@ func (ag *Agent) ReplayMessages(messages []backend.Message) {
|
|||
case "user":
|
||||
ag.AppendChat(format.FormatEvent("user", "", m.Content, ""))
|
||||
case "assistant":
|
||||
if m.Reasoning != "" {
|
||||
ag.AppendChat([]byte(format.RoleDelim("reasoning") + "\n" + m.Reasoning + "\n" + format.EndTag + "\n"))
|
||||
}
|
||||
if m.ID != "" {
|
||||
ag.AppendChat([]byte(format.AssistantHeaderPrefix + m.ID + "]]]\n"))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ func (ag *Agent) autoCompact(ctx context.Context) (int, error) {
|
|||
}
|
||||
ag.emit(Event{Role: "info", Content: "auto-compacting context...\n"})
|
||||
ag.SetState("compacting")
|
||||
n, err := ag.runCompact(ctx, "auto")
|
||||
n, err := ag.runCompact(context.WithoutCancel(ctx), "auto")
|
||||
if err != nil {
|
||||
return n, fmt.Errorf("auto-compact: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string {
|
|||
if compactLimit := ag.autoCompactLimit(actCtx); compactLimit > 0 && tokens >= compactLimit {
|
||||
ag.emit(Event{Role: "info", Content: "auto-compacting context...\n"})
|
||||
ag.SetState("compacting")
|
||||
if _, err := ag.runCompact(actCtx, "auto"); err != nil {
|
||||
if _, err := ag.runCompact(context.WithoutCancel(actCtx), "auto"); err != nil {
|
||||
ag.log.Error("auto-compact failed: %v", err)
|
||||
}
|
||||
ag.SetState("thinking")
|
||||
|
|
@ -256,7 +256,11 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string {
|
|||
ag.history.messages = ag.history.messages[:preTurnLen]
|
||||
ag.emit(Event{Role: "info", Content: "context overflow — compacting and retrying...\n"})
|
||||
ag.SetState("compacting")
|
||||
if _, cerr := ag.runCompact(actCtx, "overflow"); cerr != nil {
|
||||
if _, cerr := ag.runCompact(context.WithoutCancel(actCtx), "overflow"); cerr != nil {
|
||||
break
|
||||
}
|
||||
if actCtx.Err() != nil {
|
||||
err = actCtx.Err()
|
||||
break
|
||||
}
|
||||
ag.history.appendUserMessage(input)
|
||||
|
|
|
|||
Loading…
Reference in New Issue