feat(examples): add headless smart-home agent - #70
Conversation
A virtual smart home (lights/thermostat/blinds/locks/scenes) built as an ordinary ignite-element component and driven by Claude through igniteTools + the ignite-element/tools/anthropic adapter — running fully headless in Node with no DOM and no jsdom. This is the end-to-end proof of the DOM-free agent runtime (Phase A) and a stress test of the agent API surface. - Varied command schemas: object (toggleLight/setThermostat/setBlinds), scalar enum (lockDoor/unlockDoor/runScene → Option D scalar wrap), no-arg (status). - Pluggable model seam: a scripted key-free model (npm run mock / the test) and the real @anthropic-ai/sdk (npm run anthropic). - A pure-Node (environment: node, zero jsdom) test asserts the schema breadth, the scalar round-trip, event observation, and errors-as-values. - A terminal renderer for a watchable demo. - GAPS.md records what dogfooding surfaced (view-vs-snapshot grounding, canExecute gating, an observe() channel, async/settle, scalar legibility). - CI examples-typecheck now covers examples/agents/*.
Dogfooding the smart-home agent (Phase B) showed the agent only ever saw the raw
snapshot, never the derived view the design says it should ground on. Fix:
- ToolObservation is now { snapshot, view, events } (gains a View type param).
- igniteTools binds getView (added to the IgniteToolsRuntime surface alongside
getSchema/execute) and captures it at command-acknowledgement, so every run()
observation — and every provider tool_result a dialect serializes — carries
the view (the read-model: lightsOn/allDoorsLocked/...), distinct from the
raw snapshot.
- NeutralToolResult threads View; the Anthropic dialect needs no change (it
serializes the whole observation).
Breaking to the pre-stable beta igniteTools surface (observation shape +
IgniteToolsRuntime pick). Resolves GAPS.md #1.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
Walkthrough
ChangesView-aware tool observations
Smart-home agent example
Sequence Diagram(s)sequenceDiagram
participant runHomeAgent
participant igniteTools
participant createHome runtime
participant Model
runHomeAgent->>Model: messages + tools
Model-->>runHomeAgent: tool_use blocks
runHomeAgent->>igniteTools: run(toolCall)
igniteTools->>createHome runtime: execute(command, input)
createHome runtime-->>igniteTools: snapshot
igniteTools->>createHome runtime: getView()
createHome runtime-->>igniteTools: view
igniteTools-->>runHomeAgent: { snapshot, view, events }
runHomeAgent->>Model: tool_result with view
Model-->>runHomeAgent: final text
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## beta #70 +/- ##
=======================================
Coverage ? 89.96%
=======================================
Files ? 32
Lines ? 1515
Branches ? 433
=======================================
Hits ? 1363
Misses ? 142
Partials ? 10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/agents/smart-home/package.json`:
- Around line 6-10: The smart-home package’s local typecheck setup is broken
because package.json defines a typecheck script that calls tsc without ensuring
typescript is installed. Fix this by either adding typescript to the package’s
dependencies/devDependencies or removing the typecheck script from
examples/agents/smart-home/package.json; keep the test/mock/anthropic scripts
unchanged and make sure npm run typecheck works in a standalone install.
In `@examples/agents/smart-home/src/home.ts`:
- Around line 91-125: The SET_THERMOSTAT, SET_BLINDS, and SET_LOCK handlers in
the smart-home state machine are clearing activeScene even when the command is a
no-op. Update the assign logic in home.ts so activeScene is only reset when the
incoming event actually changes the stored value in context. Use the existing
TOGGLE_LIGHT-style state update pattern as a reference, and apply the same
idempotency guard across these handlers so runScene presets remain active after
repeated commands that do not change state.
- Around line 149-159: The view() function is returning live references from
snapshot.context, which exposes the machine’s internal state to downstream
mutation. Update the view in home.ts so it returns defensive copies for the
lights, thermostat, blinds, and locks fields while keeping derived values like
lightsOn and allDoorsLocked computed from snapshot.context. Use the existing
view()/getView() path as the place to clone those objects before exposing them
through tool observations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 13786e57-14a9-495a-ac3e-f99a4997604a
📒 Files selected for processing (20)
.changeset/ignitetools-view-in-observation.md.github/workflows/ci.ymldocs/ignite-tools.mdexamples/agents/smart-home/GAPS.mdexamples/agents/smart-home/README.mdexamples/agents/smart-home/package.jsonexamples/agents/smart-home/src/agentLoop.test.tsexamples/agents/smart-home/src/agentLoop.tsexamples/agents/smart-home/src/anthropic.tsexamples/agents/smart-home/src/home.tsexamples/agents/smart-home/src/mock.tsexamples/agents/smart-home/src/model.tsexamples/agents/smart-home/src/render.tsexamples/agents/smart-home/tsconfig.jsonexamples/agents/smart-home/vite.config.tspackages/ignite-element/src/tests/tools.anthropic.test.tspackages/ignite-element/src/tests/tools.test.tspackages/ignite-element/src/tests/types/tools.types.test.tspackages/ignite-element/src/tools/igniteTools.tspackages/ignite-element/src/tools/types.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Verification
CodeRabbit disposition
Summary by CodeRabbit