feat(agent): 云端 Agent - 加固运行时并新增导演工具

This commit is contained in:
ddcat666 committed 2026-09-27 09:45:43 +08:00
1 parent 1080b22196
commit 1a4598e496
16 files changed
+815 -195

No files matched your search

@@ -14,20 +14,33 @@ type cloudAgentToolRepair struct {
Attempt int `json:"attempt"`
}
func cloudAgentRetryReceipt(groupID string, attempt int, status string) map[string]any {
terminal := status == "exhausted"
severity := "warning"
if terminal {
severity = "error"
}
return map[string]any{
"groupId": groupID, "attempt": attempt, "maxAttempts": cloudAgentToolAttemptLimit,
"status": status, "severity": severity, "terminal": terminal,
}
}
// Count per tool, not per model step: intervening reads must not reset a failed
// write's allowance. Only explicitly typed, pre-execution errors are repairable.
func cloudAgentTrackToolRepair(runID string, state *cloudAgentRuntime, call cloudAgentCall, result any, err error, payload map[string]any) bool {
previous, exists := state.ToolRepairs[call.Function.Name]
if err == nil {
if exists {
payload["retry"] = map[string]any{"groupId": previous.GroupID, "attempt": previous.Attempt, "maxAttempts": cloudAgentToolAttemptLimit, "status": "recovered"}
payload["retry"] = cloudAgentRetryReceipt(previous.GroupID, previous.Attempt, "recovered")
delete(state.ToolRepairs, call.Function.Name)
}
return false
}
detail, _ := result.(map[string]any)
var argumentErr *cloudAgentArgumentError
if !errors.As(err, &argumentErr) || detail["taskSubmitted"] == true || detail["phase"] == "completion" {
retryable, _ := detail["retryable"].(bool)
if (!errors.As(err, &argumentErr) && !retryable) || detail["taskSubmitted"] == true || detail["phase"] == "completion" {
return false
}
if state.ToolRepairs == nil {
@@ -43,7 +56,7 @@ func cloudAgentTrackToolRepair(runID string, state *cloudAgentRuntime, call clou
if exhausted {
status = "exhausted"
}
retry := map[string]any{"groupId": previous.GroupID, "attempt": previous.Attempt, "maxAttempts": cloudAgentToolAttemptLimit, "status": status}
retry := cloudAgentRetryReceipt(previous.GroupID, previous.Attempt, status)
payload["retry"], detail["retry"] = retry, retry
return exhausted
}
@@ -57,6 +70,6 @@ func cloudAgentRecordToolResult(run *model.CloudAgentExecution, state *cloudAgen
cloudAgentDropInterjections(run.ID, "本轮已结束:"+truncateRunes(run.FailureMessage, 120), state)
state.event(run.ID, "run_failed", map[string]any{
"text": run.FailureMessage, "reason": "tool_retry_exhausted", "toolName": call.Function.Name,
"callId": call.ID, "attempts": cloudAgentToolAttemptLimit,
"callId": call.ID, "attempts": cloudAgentToolAttemptLimit, "severity": "error", "terminal": true,
})
}