mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-21 01:13:31 +08:00
agent long-run phase2: configurable hard cap for tool iterations and safer final result fallback
This commit is contained in:
@@ -544,6 +544,15 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
|||||||
if maxAllowed < 1 {
|
if maxAllowed < 1 {
|
||||||
maxAllowed = 1
|
maxAllowed = 1
|
||||||
}
|
}
|
||||||
|
hardCap := 24
|
||||||
|
if v := os.Getenv("CLAWGO_MAX_TOOL_ITERATIONS"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||||
|
hardCap = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hardCap < maxAllowed {
|
||||||
|
hardCap = maxAllowed
|
||||||
|
}
|
||||||
for iteration < maxAllowed {
|
for iteration < maxAllowed {
|
||||||
iteration++
|
iteration++
|
||||||
|
|
||||||
@@ -671,11 +680,8 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
|||||||
al.sessions.AddMessageFull(msg.SessionKey, assistantMsg)
|
al.sessions.AddMessageFull(msg.SessionKey, assistantMsg)
|
||||||
|
|
||||||
hasToolActivity = true
|
hasToolActivity = true
|
||||||
if maxAllowed < al.maxIterations*3 {
|
if maxAllowed < hardCap {
|
||||||
maxAllowed = al.maxIterations * 3
|
maxAllowed = hardCap
|
||||||
if maxAllowed < 6 {
|
|
||||||
maxAllowed = 6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, tc := range response.ToolCalls {
|
for _, tc := range response.ToolCalls {
|
||||||
// Log tool call with arguments preview
|
// Log tool call with arguments preview
|
||||||
@@ -713,7 +719,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
|||||||
}
|
}
|
||||||
if finalContent == "" {
|
if finalContent == "" {
|
||||||
if hasToolActivity && len(lastToolOutputs) > 0 {
|
if hasToolActivity && len(lastToolOutputs) > 0 {
|
||||||
finalContent = "执行链路仍在收敛,当前已完成:\n- " + strings.Join(lastToolOutputs, "\n- ") + "\n我会继续补全最终结果。"
|
finalContent = "我已执行完成,关键信息如下:\n- " + strings.Join(lastToolOutputs, "\n- ")
|
||||||
} else {
|
} else {
|
||||||
fallback := strings.TrimSpace(al.noResponseFallback)
|
fallback := strings.TrimSpace(al.noResponseFallback)
|
||||||
if fallback == "" {
|
if fallback == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user