Agents
Self-debug
Agents that read their own traces, diagnose failures, retry with corrections.
Pattern
- Run fails or produces low-confidence output.
- Feed the trace (steps, tool calls, errors) back to the agent.
- Agent proposes a fix (different tool, different arg, smaller step).
- Retry with the fix applied.
Sketch
import { createDurableRunner } from '@agentskit/runtime'
const res = await durable.run({ runId, input })
if (res.status === 'error') {
const trace = await durable.getTrace(runId)
const fix = await debuggerRuntime.run({
input: `Trace failed. Diagnose and suggest fix.\n\n${JSON.stringify(trace)}`,
})
await durable.run({ runId: `${runId}-retry`, input: fix.output })
}