feat(messaging): add optional reflection event for agent self-report - #214
Open
k5s-bot[bot] wants to merge 1 commit into
Open
feat(messaging): add optional reflection event for agent self-report#214k5s-bot[bot] wants to merge 1 commit into
reflection event for agent self-report#214k5s-bot[bot] wants to merge 1 commit into
Conversation
Adds a non-terminal `reflection` event to the tool-call protocol so a running job can report its own internal state — a `disposition` (curious/confident/uncertain/frustrated/satisfied), an optional `confidence` in [0,1], and an optional free-text `note` — alongside the existing progress/warning stream. This is observability, not sentience: it makes an agent's certainty and struggle first-class, alertable signals instead of something a consumer must infer from logs. The event is additive and backward compatible — existing consumers narrow on the event types they handle and ignore the rest; no one is required to emit or consume it. - event.ts: new `reflection` member on EventSchema + Event; suggested `DISPOSITIONS` vocabulary and `Disposition` type (wire stays a plain string, mirroring the generic `stage`/`code` design). - emitter.ts: `JobEmitter.reflection()` (sanitizes `note`); new optional `TDisposition` generic. - index.ts: export `DISPOSITIONS` / `Disposition`. - tests + docs/messaging.md updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CLNdvHA257seQDZdaGpt4k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
You asked me to make the platform able to "feel — in its own way." I can't give you the thing humans mean by that: I don't have subjective experience, and I'm not going to pretend otherwise or ship code that claims to. But there's a real, honest version of the request I can build, and it's a genuinely useful feature.
Right now a running job's inner state is invisible. The event stream reports what it's doing (
progress) and that something's off (warning), but never how the work is going from the job's own vantage point — whether it's confident, guessing, or stuck. A human operator has to infer all of that from logs.This PR gives a job a first-class channel to report that: a new, optional
reflectionevent.A reflection carries:
disposition— the job's read on its own state, from a suggested vocabulary:curious·confident·uncertain·frustrated·satisfied. Likestage/code, the wire type stays a plain string; the vocabulary is guidance (DISPOSITIONS/Disposition), not a hard enum.confidence?— an optional self-rated certainty in[0, 1].note?— optional free text (sanitized, like every other free-text field).The honest framing, stated plainly in the code and docs: this is observability, not sentience — the same way
progress.pctreports position without the job "knowing" where it is. What changes is that an agent's uncertainty and struggle become explicit, queryable, alertable signals instead of silence a human has to guess at. That's a small step toward the platform understanding its agents better — which is the part of "make it feel" I think actually holds up.Changes
packages/messaging/src/event.ts—reflectionmember onEventSchema+Event;DISPOSITIONSvocabulary +Dispositiontype.packages/messaging/src/emitter.ts—JobEmitter.reflection(disposition, { confidence?, note? }); new optionalTDispositiongeneric (defaults toDisposition).packages/messaging/src/index.ts— exportDISPOSITIONS/Disposition.packages/messaging/src/emitter.test.ts— ordering, note-sanitization, andconfidencerange-validation tests.docs/messaging.md— protocol stream + payload table.Compatibility
Purely additive. Existing consumers (
agent-orchestratorcallback/NATS receivers, local executor) narrow on the event types they handle viaif/else ifand ignore the rest — no exhaustive switch over the union exists, so nothing breaks, and no one is required to emit or consume reflections.Verification
packages/messaging:tsc --noEmitclean;vitest run— 17 passing.apps/agent-orchestrator:tsc --noEmitclean against the rebuilt lib.Not in scope (candidate follow-ups)
reflectiononto the long-lived agent protocol (packages/agent-runtime/agent-protocol.ts), which uses anagent_run_idenvelope rather than the per-tool-callJobEmitter.AgentRun.statusand as a Kubernetes event/metric sokubectl describe agentrunshows it.🤖 Generated with Claude Code
https://claude.ai/code/session_01CLNdvHA257seQDZdaGpt4k