Skip to content

feat(sdk/engine,sdk/event,sdk/model): engine host extensibility, event sampling, and token usage enrichment#51

Merged
lIang70 merged 1 commit into
mainfrom
feat/engine-host-extensibility-and-event-bus-enhancements
Apr 29, 2026
Merged

feat(sdk/engine,sdk/event,sdk/model): engine host extensibility, event sampling, and token usage enrichment#51
lIang70 merged 1 commit into
mainfrom
feat/engine-host-extensibility-and-event-bus-enhancements

Conversation

@lIang70

@lIang70 lIang70 commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Engine layer: Adds Capabilities struct + Describer interface so engines can advertise SupportsResume, EmitsUserPrompt, EmitsCheckpoint, and RequiredDepNames. Pod/agent layer reads these to validate PodSpecs and gate behaviour at apply time.
  • HostMiddleware: New decorator type + ComposeHost helper for stacking policy layers (audit → rate-limit → budget → secret-resolve) around a base Host. HostFuncs adapter makes partial decoration easy without struct embedding.
  • MergeInterrupts: New helper that fans N interrupt channels into one — the shape sandbox/pod hosts need for combining user cancel, SIGTERM, budget exceeded, graceful stop, etc.
  • UsageReporter.ReportUsage: Changed from void to error return. Hosts may now return errdefs.BudgetExceeded to signal accumulated usage has crossed a budget; engines MUST stop LLM-cost-incurring work on seeing it.
  • Event layer: Adds BackpressurePolicy.Sample for probabilistic envelope delivery with WithSampleRate option — useful for high-volume streams (token deltas, voice frames) where exact delivery is unnecessary. Also adds AckSubscription interface for at-least-once delivery semantics in cross-process buses.
  • Model layer: TokenUsage enriched with Model, LatencyMs, CostMicros fields so sandbox hosts can enforce dollar-denominated budgets without a separate sidecar.

Test plan

  • make ci passes on all in-tree modules
  • New capabilities_test.go, middleware_test.go, interrupt_test.go cover the new helpers
  • Updated host_test.go covers the new UsageReporter contract

🤖 Generated with Claude Code

…t sampling, and token usage enrichment

Engine layer:
- Add Capabilities struct + Describer interface so engines can advertise
  SupportsResume, EmitsUserPrompt, EmitsCheckpoint, and RequiredDepNames.
  Pod/agent layer reads these to validate PodSpecs and gate behaviour.
- Add HostMiddleware type + ComposeHost helper for stacking policy
  decorators (audit → rate-limit → budget → secret-resolve) around a base
  Host. HostFuncs adapter makes partial decoration easy.
- Add MergeInterrupts helper to fan-in N interrupt channels into one,
  the shape sandbox/pod hosts need for combining user cancel, SIGTERM,
  budget exceeded, graceful stop, etc.
- Change UsageReporter.ReportUsage to return error. Hosts may now return
  errdefs.BudgetExceeded to signal accumulated usage has crossed a
  configured budget; engines MUST stop LLM-cost-incurring work on seeing
  it.

Event layer:
- Add BackpressurePolicy.Sample for probabilistic envelope delivery with
  configurable per-subscription rate via WithSampleRate. Useful for
  high-volume streams (token deltas, voice frames) where exact delivery
  is unnecessary and Block/DropOldest/DropNewest have undesirable
  side-effects.
- Add AckSubscription interface for at-least-once delivery semantics
  (cross-process buses backed by NATS/Redis Streams/Kafka). v1 minimal
  contract: Ack(envelopeID) with duplicate tolerance.

Model layer:
- Enrich TokenUsage with Model, LatencyMs, CostMicros fields so sandbox
  hosts can enforce dollar-denominated budgets and per-model rate limits
  without a separate sidecar. TokenUsage.Add() updated to aggregate all
  numeric fields; Model label is preserved from the accumulator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lIang70
lIang70 merged commit d7d48a8 into main Apr 29, 2026
9 checks passed
@lIang70
lIang70 deleted the feat/engine-host-extensibility-and-event-bus-enhancements branch April 29, 2026 10:39
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