feat: metrics record --emit-event for kaizen.metrics.recorded
Publish activity-core EventEnvelope payloads to NATS subject activity.kaizen.metrics.recorded after a successful append. Optional nats-py via kaizen-agentic[events]; project slug from KAIZEN_PROJECT_SLUG or directory basename. Skips emit on idempotency duplicates. Closes KAIZEN-WP-0008 T03.
This commit is contained in:
@@ -35,9 +35,11 @@ action:
|
||||
|
||||
**Threshold:** 0.8 success rate, minimum 5 executions (avoids noise on early pilots).
|
||||
|
||||
**CLI mapping:** Event emitter is future work; manual check today:
|
||||
**CLI mapping:** `kaizen-agentic metrics record <agent> --emit-event` after each
|
||||
append (see [kaizen-metrics-recorded-event.md](../kaizen-metrics-recorded-event.md)).
|
||||
Manual check today:
|
||||
|
||||
```bash
|
||||
kaizen-agentic metrics show <agent> # inspect summary.success_rate
|
||||
kaizen-agentic metrics optimize <agent>
|
||||
```
|
||||
```
|
||||
|
||||
69
docs/integrations/kaizen-metrics-recorded-event.md
Normal file
69
docs/integrations/kaizen-metrics-recorded-event.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# Event Payload: `kaizen.metrics.recorded`
|
||||
|
||||
**Status:** implemented — `kaizen-agentic metrics record --emit-event`
|
||||
|
||||
Emitted after a successful metrics append when `--emit-event` is set. Default
|
||||
off for backward compatibility.
|
||||
|
||||
## Subject
|
||||
|
||||
```
|
||||
activity.kaizen.metrics.recorded
|
||||
```
|
||||
|
||||
Published to NATS (activity-core `EventEnvelope` format). Consumed by
|
||||
activity-core event router and definitions such as `low-success-rate-review`.
|
||||
|
||||
## Envelope
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"type": "kaizen.metrics.recorded",
|
||||
"version": "1.0",
|
||||
"timestamp": "2026-06-18T12:00:00Z",
|
||||
"publisher": "kaizen-agentic",
|
||||
"attributes": {
|
||||
"agent": "coach",
|
||||
"project": "kaizen-agentic",
|
||||
"summary": {
|
||||
"success_rate": 0.75,
|
||||
"execution_count": 12,
|
||||
"avg_quality": 0.81
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Attribute fields
|
||||
|
||||
| Field | Type | Notes |
|
||||
|-------|------|-------|
|
||||
| `agent` | string | Agent name from `metrics record <agent>` |
|
||||
| `project` | string | Repo slug — `KAIZEN_PROJECT_SLUG` env or directory basename |
|
||||
| `summary.success_rate` | float | Rolling rate from `summary.json` after append |
|
||||
| `summary.execution_count` | int | Total executions |
|
||||
| `summary.avg_quality` | float | Maps from `avg_quality_score` in ADR-004 summary |
|
||||
|
||||
## CLI
|
||||
|
||||
```bash
|
||||
kaizen-agentic metrics record coach --success --time 120 --quality 0.9 --emit-event
|
||||
```
|
||||
|
||||
Requires `nats-py` (`pip install 'kaizen-agentic[events]'`). Configure broker via
|
||||
`NATS_URL` (default `nats://localhost:4222`).
|
||||
|
||||
Events are **not** emitted when append is skipped (duplicate idempotency key).
|
||||
|
||||
## Consumers
|
||||
|
||||
- **activity-core** — `trigger.type: event` with `event_type: kaizen.metrics.recorded`
|
||||
- **coulomb-loop** — `low-success-rate-review` (LOOP-WP-0002); replaces hourly
|
||||
health sweep when event path is stable
|
||||
|
||||
## Related
|
||||
|
||||
- [low-success-rate-review](activity-definitions/low-success-rate-review.md)
|
||||
- [INTEGRATION_PATTERNS.md Pattern 2](../INTEGRATION_PATTERNS.md)
|
||||
- coulomb-loop `loops/quality-escalation/event-payload.md` (customer contract)
|
||||
Reference in New Issue
Block a user