一键导入
self-healing-agents
Self-Healing Agents are autonomous systems that detect their own failure modes and self-correct without human intervention.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Self-Healing Agents are autonomous systems that detect their own failure modes and self-correct without human intervention.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Parallel Agent Orchestration is the discipline of dispatching, coordinating, and aggregating results from multiple concurrent subagents to dramatically accelerate complex tasks.
Proactive Intelligence enables agents to autonomously seek out external information — web searches, API re-pulls, data freshness checks — during analysis without waiting for explicit user requests
Context Engineering is the discipline of maximizing agent output quality while minimizing token expenditure.
Prompt Architecture is the structural engineering of agent instructions.
Verification Loops are systematic evaluation pipelines that validate agent outputs at every stage of execution.
Continuous Learning enables agents to automatically extract successful patterns from completed sessions and codify them into reusable skills, rules, and prompt refinements.
| name | self-healing-agents |
| description | Self-Healing Agents are autonomous systems that detect their own failure modes and self-correct without human intervention. |
Part of Agent Skills™ by googleadsagent.ai™
Self-Healing Agents are autonomous systems that detect their own failure modes and self-correct without human intervention. In production environments, agent failures are not exceptional — they are expected. Network calls timeout, APIs return unexpected schemas, models hallucinate confidently, and tool outputs violate assumptions. The difference between a prototype and a production agent is the ability to recover gracefully from every category of failure.
This skill encodes the self-healing patterns developed for the Buddy™ agent at googleadsagent.ai™, where autonomous Google Ads analysis must complete reliably even when upstream APIs change, rate limits are hit, or model outputs contain structural errors. The system operates on a detect-diagnose-repair cycle that mirrors biological immune responses: identify the pathogen, classify the threat, and deploy the appropriate countermeasure.
Self-healing is not merely retry logic. It encompasses error classification, strategy mutation (retrying with a different approach rather than the same one), fallback model selection, output validation with automatic repair, and graceful degradation when full recovery is impossible. Agents built with these patterns achieve 99%+ task completion rates in production.
graph TD
A[Agent Action] --> B[Output Validation]
B -->|Valid| C[Continue Execution]
B -->|Invalid| D[Error Classifier]
D --> E{Error Type}
E -->|Transient| F[Retry with Backoff]
E -->|Structural| G[Mutate Strategy]
E -->|Model Error| H[Fallback Model]
E -->|Unrecoverable| I[Graceful Degradation]
F --> J{Retry Budget Remaining?}
J -->|Yes| A
J -->|No| G
G --> K[Modified Prompt/Approach]
K --> A
H --> L[Alternative Model Execution]
L --> B
I --> M[Partial Result + Error Report]
The self-healing cycle activates whenever output validation detects an anomaly. The error classifier categorizes the failure into one of four types: transient errors (network timeouts, rate limits) are retried with exponential backoff; structural errors (schema violations, missing fields) trigger strategy mutation where the agent modifies its approach; model errors (hallucinations, refusals) invoke fallback model selection; and unrecoverable errors trigger graceful degradation that returns the best partial result with a clear error report.
Error Classification Engine:
enum ErrorType {
Transient = "transient",
Structural = "structural",
ModelError = "model_error",
Unrecoverable = "unrecoverable",
}
interface ClassifiedError {
type: ErrorType;
message: string;
retryable: boolean;
suggestedStrategy: string;
}
function classifyError(error: unknown, context: ExecutionContext): ClassifiedError {
if (error instanceof NetworkError || error instanceof RateLimitError) {
return {
type: ErrorType.Transient,
message: String(error),
retryable: true,
suggestedStrategy: "exponential_backoff",
};
}
if (error instanceof SchemaValidationError) {
return {
type: ErrorType.Structural,
message: `Schema violation: ${error.path} — ${error.message}`,
retryable: true,
suggestedStrategy: "mutate_prompt",
};
}
if (error instanceof ModelRefusalError || isHallucination(error, context)) {
return {
type: ErrorType.ModelError,
message: String(error),
retryable: true,
suggestedStrategy: "fallback_model",
};
}
return {
type: ErrorType.Unrecoverable,
message: String(error),
retryable: false,
suggestedStrategy: "graceful_degradation",
};
}
Self-Healing Execution Loop:
class SelfHealingAgent:
def __init__(self, primary_model, fallback_models, max_retries=3):
self.primary_model = primary_model
self.fallback_models = fallback_models
self.max_retries = max_retries
async def execute(self, task, validator):
attempts = []
current_model = self.primary_model
current_prompt = task.prompt
for attempt in range(self.max_retries + len(self.fallback_models)):
try:
result = await current_model.generate(current_prompt)
validation = validator.validate(result)
if validation.is_valid:
return HealingResult(result=result, attempts=attempts)
error = classify_error(validation.error, task.context)
attempts.append({"attempt": attempt, "error": error, "model": current_model.name})
if error.strategy == "mutate_prompt":
current_prompt = self.mutate_prompt(current_prompt, error)
elif error.strategy == "fallback_model":
current_model = self.next_fallback(current_model)
except Exception as e:
error = classify_error(e, task.context)
attempts.append({"attempt": attempt, "error": error})
if not error.retryable:
break
await asyncio.sleep(2 ** attempt)
return HealingResult(
result=self.graceful_degradation(task, attempts),
attempts=attempts,
degraded=True
)
def mutate_prompt(self, prompt, error):
mutations = {
"schema_violation": f"{prompt}\n\nPrevious attempt had error: {error.message}. Ensure strict schema compliance.",
"missing_field": f"{prompt}\n\nYou MUST include all required fields. Missing: {error.message}",
}
return mutations.get(error.subtype, f"{prompt}\n\nPrevious error: {error.message}. Adjust approach.")
def next_fallback(self, current):
idx = ([self.primary_model] + self.fallback_models).index(current)
if idx < len(self.fallback_models):
return self.fallback_models[idx]
return current
Output Validation with Auto-Repair:
def validate_and_repair(output: str, schema: dict) -> tuple[dict, bool]:
try:
parsed = json.loads(output)
except json.JSONDecodeError:
extracted = extract_json_from_text(output)
if extracted:
parsed = extracted
else:
raise StructuralError("No valid JSON found in output")
repaired = False
for field, rules in schema.get("required_fields", {}).items():
if field not in parsed:
if "default" in rules:
parsed[field] = rules["default"]
repaired = True
else:
raise StructuralError(f"Missing required field: {field}")
return parsed, repaired
| Feature | Claude Code | Cursor | Codex | Gemini CLI |
|---|---|---|---|---|
| Retry with mutation | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Fallback model selection | ✅ Via API | ✅ Via extensions | ✅ Via API | ✅ Via API |
| Output validation | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Error classification | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Graceful degradation | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
self-healing, error-recovery, retry-strategy, fallback-models, output-validation, graceful-degradation, strategy-mutation, error-classification, resilience, agent-skills
© 2026 googleadsagent.ai™ | Agent Skills™ | MIT License