Skip to content

feat(#962): onError — infrastructure-error observability hook#22

Merged
Skobeltsyn merged 1 commit into
mainfrom
feat/962-on-error-callback
May 3, 2026
Merged

feat(#962): onError — infrastructure-error observability hook#22
Skobeltsyn merged 1 commit into
mainfrom
feat/962-on-error-callback

Conversation

@Skobeltsyn
Copy link
Copy Markdown
Contributor

New listener slot on Agent that fires when an exception is about to propagate out of an agentic invocation — LLM transport failures, response parse failures, budget exceptions, skill-routing errors.

Pure observability: the original exception always rethrows after the listener runs. If the listener itself throws, its failure is attached to the original via addSuppressed so it can never silently disappear.

Distinct from onToolError, which is per-tool semantic recovery and can substitute repaired arguments or a value for the failure.

API:
agent<IN, OUT>("name") {
onError { t -> log.error("agent failed", t) }
}

The listener field is settable post-construction (matches onToolUse / onSkillChosen / onKnowledgeUsed convention) so instrumentation can attach to a frozen agent.

New listener slot on Agent that fires when an exception is about to
propagate out of an agentic invocation — LLM transport failures,
response parse failures, budget exceptions, skill-routing errors.

Pure observability: the original exception always rethrows after the
listener runs. If the listener itself throws, its failure is attached
to the original via addSuppressed so it can never silently disappear.

Distinct from `onToolError`, which is per-tool semantic recovery and
can substitute repaired arguments or a value for the failure.

API:
    agent<IN, OUT>("name") {
        onError { t -> log.error("agent failed", t) }
    }

The listener field is settable post-construction (matches
onToolUse / onSkillChosen / onKnowledgeUsed convention) so
instrumentation can attach to a frozen agent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Skobeltsyn Skobeltsyn merged commit db6166a into main May 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant