You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HomeAutomation is a SwiftUI smart-home command resolution demo. It turns natural-language requests such as "Set the bedroom lamp to 40 percent" into validated home-automation drafts, execution plans, confirmations, or clarification questions.
The current implementation is orchestrator-first: a SwiftUI app calls a multi-agent command orchestrator, the orchestrator coordinates specialist agents, agents use canonical domain catalogs plus NLU-informed hybrid RAG context, and deterministic safety gates decide whether anything can execute.
Project Goals
Resolve natural-language home commands into structured HomeCommandDraft and HomeCommandResolution values.
Keep model output advisory until deterministic validation passes.
Support Foundation Models when available while preserving deterministic fallback behavior.
Retrieve only relevant catalog, device, command, and Bixby context through semantic, BM25, and hybrid RAG.
Preserve observability through streamed pipeline events, per-agent traces, retrieval-quality reports, metrics JSON, and UI dashboards.
Execute only low-risk mock-device commands when execution is enabled.
High-Level Architecture
Current architecture source of truth: the orchestrator is graph-only. Command routing starts with root-command-graph, then GraphPlanner, OperationGraphCatalog, and GraphScheduler own direct command, fallback, automation creation, and unsupported flows.
flowchart TD
A["User submits command"] --> B["ViewModel starts orchestrator stream"]
B --> C["Create CommandRequest and ResolutionContext"]
C --> D["Apply conversation-memory hints when text references prior context"]
D --> R["Root command graph: OperationDetectionAgent"]
R --> E{"Detected operation"}
E -->|Direct command + models unavailable| F["Fallback graph: RuleFallbackAgent"]
F --> G["BixbyFallbackAgent"]
G --> H["UnsupportedCommandAgent if no deterministic match"]
E -->|Direct command + models available| I["Direct command graph: run SemanticNLU, SlotExtraction, RiskClassification in parallel"]
I --> J["Run NLU-informed knowledge and candidate retrieval in parallel"]
J --> K["RetrievalJudgeAgent accepts or retries weak retrieval"]
K --> L["Rank and hydrate scoped candidates"]
L --> M{"Clarification needed?"}
M -->|Yes| N["Clarification result"]
M -->|No| O["Compose instruction package"]
O --> P["Generate or repair draft"]
P --> Q["SafetyValidationAgent"]
Q --> R["ParameterValidationAgent"]
R --> S["ConfirmationPolicyAgent"]
S --> T["ExecutionPlanningAgent"]
T --> U{"Allowed to execute?"}
U -->|Requires confirmation| V["Return confirmation result"]
U -->|Low risk and enabled| W["MockExecutionAgent mutates mock registry"]
U -->|Execution disabled or query| X["Return ready/query result"]
E -->|Automation creation| AA["Automation creation graph"]
AA --> AB["AutomationDraftAgent"]
AB --> AC["Action and condition resolution in parallel"]
AC --> AD["AutomationValidationAgent"]
AD --> AE["SmartThingsCompilationAgent"]
AE --> AF["AutomationResultAssemblyAgent"]
E -->|Unsupported operation| H
H --> Y["Assemble result and metrics"]
N --> Y
V --> Y
W --> Y
X --> Y
AF --> Y
Y --> Z["Stream outcome, metrics, dashboard updates"]
UI projection models for the timeline, agent status, device cards, and command history.
Orchestrator Layer
Component
Role
HomeCommandOrchestrator
Main command resolver. Creates context, streams events, runs the root routing graph, assembles HomeAutomationResolverResult, records metrics, and stores conversation turns.
GraphPlanner
Builds operation graphs for root routing, direct command, fallback, automation creation, and unsupported handling.
OperationGraphCatalog
Selects the graph provider for each detected operation and model-availability policy.
GraphScheduler
Executes DAG nodes as dependencies complete, checks circuit breakers, runs agents, applies typed patches, records traces, handles approved graph transitions, and fails closed for mandatory gates.
AgentRegistry
Stores AnyHomeAgent instances by AgentID and capability.
ResolutionContextStore
Actor-backed holder for the evolving ResolutionContext, including typed scoped artifacts and legacy string-key compatibility.
ContextArtifactKey / context facets
Typed artifact exchange and read-only context slices used to reduce raw string coupling between graph agents.
AgentEventBus
Async event stream for UI timeline updates.
OrchestratorPolicyEngine
Central policy for model availability, retry limits, terminal exits, execution eligibility, and fail-closed safety behavior.
CircuitBreakerRegistry
Per-agent circuit breaker registry.
ConversationMemory
Stores recent resolved turns and contributes low-priority memory hints for follow-up commands.
OrchestratorMetricsCollector
Stores and serializes the latest orchestrator metrics.
Agent Inventory
NLU Agents — Consolidated Active Stack
Agent
Input
Output
Description
OperationDetectionAgent
String
HomeOperationRoutingResult
Root-routing agent that produces operation, language, and domain in one Foundation Model call, with deterministic semantic analyzer fallback.
SemanticNLUAgent
String
HomeSemanticNLUResult
Active direct-command semantic classifier that fuses intent-family and device-type extraction in one Foundation Model call.
SlotExtractionAgent
String
HomeSlotExtractionResult
Extracts rooms, device nicknames, numeric values, units, and modes from the command text.
RiskClassificationAgent
String
HomeRiskClassificationResult
Produces initial risk estimate (.low/.medium/.high/.critical) as advisory signal for downstream safety gates.
The active direct-command NLU graph runs SemanticNLUAgent, SlotExtractionAgent, and RiskClassificationAgentin parallel. Language and domain are already produced by the root routing graph, so direct command resolution no longer spends separate model calls on them. Each active NLU agent supports optional RAG few-shot enrichment via ContextRetriever.
Knowledge Agents (4) - Context Hydration and Retrieval Quality
Agent
Input
Output
Description
CapabilityKnowledgeAgent
[String]
[KnowledgeSnippet]
Retrieves relevant capability context via RAG, then hydrates canonical definitions from HomeCapabilityRegistry.
BixbyKnowledgeAgent
BixbyKnowledgeInput
[KnowledgeSnippet]
Finds relevant Bixby voice commands via RAG + HomeBixbyCommandCatalog matching.
CommandExampleAgent
CommandExampleInput
[KnowledgeSnippet]
Retrieves similar generated command examples for few-shot context during draft generation.
RetrievalJudgeAgent
RetrievalJudgeInput
KnowledgeRetrievalAgentOutput
Reviews retrieval reports, fast-path accepts high-quality retrieval, and performs one bounded reformulated retry when retrieval quality is weak and models/RAG are available.
Scopes candidates by strong room/device-type hints before ranking, selects final IDs, or triggers clarification when ambiguous.
CandidateShardAgent
CandidateShardInput
[String]
Selects candidates within a single shard for large candidate lists (>12 devices).
CandidateHydrationAgent
CandidateHydrationInput
[HomeCandidateRecord]
Converts selected candidate IDs into fully hydrated HomeCandidateRecord values.
Draft Agents (3) — Command Draft Generation
Agent
Input
Output
Description
InstructionComposerAgent
HomeFinalResolutionInput
HomeModelInstructionPackage
Builds prompt, instructions, compact default tools, RAG-selected context, and context-budget reports for Foundation Models draft generation.
DraftGenerationAgent
HomeModelInstructionPackage
HomeCommandDraft
Produces the primary HomeCommandDraft via Foundation Models with guided schema constraints and retry across 4 strategy variants (base/adapter × full/simplified).
DraftRepairAgent
HomeModelInstructionPackage
AgentDraftResolutionOutput
Attempts draft repair when initial generation fails or produces low-confidence results.
Safety Agents (3) — Mandatory Fail-Closed Gates
Agent
Input
Output
Description
SafetyValidationAgent
SafetyValidationInput
HomeCommandResolution
Validates target device, capability, command support, and risk. Produces .readyToExecute, .needsClarification, .unsupported, or .requiresConfirmation.
ParameterValidationAgent
ParameterValidationInput
Bool
Validates parameter ranges, enum values, and numeric constraints against HomeCapabilityRegistry definitions.
ConfirmationPolicyAgent
ConfirmationPolicyInput
Bool
Enforces confirmation requirements for high-risk commands, memory-derived targets, and sensitive device types.
Safety invariant: All three safety agents are mandatory fail-closed gates. If any safety agent fails or times out, the command is rejected — never executed.
Executes low-risk command steps against MockHomeDeviceRegistry. Only agent permitted to mutate device state.
Fallback Agents (3) — Model-Free Resolution
Agent
Input
Output
Description
RuleFallbackAgent
RuleFallbackInput
HomeAutomationResolverResult
Deterministic rule-based resolver using AgentTextParser keyword matching + AgentBixbyFallbackMapper. Used when Foundation Models are unavailable.
BixbyFallbackAgent
BixbyFallbackInput
[AgentBixbyDraftMatch]
Maps user text against Bixby voice command catalog to produce draft candidates without model inference.
UnsupportedCommandAgent
String
HomeCommandResolution
Produces a safe .unsupported resolution when no agent can resolve the command.
Response Agents (2) — User-Facing Output
Agent
Input
Output
Description
ClarificationAgent
String
HomeCommandResolution
Converts ambiguity questions into .needsClarification resolutions.
ResultSummaryAgent
HomeCommandResolution
String
Formats final resolution into human-readable summary text for the UI.
Core and Data Layer
Component
Role
MockHomeDeviceRegistry
Actor-backed mock home graph with candidate retrieval and low-risk state mutation.
HomeCapabilityRegistry
Source-of-truth capability definitions and risk/command lookup helpers.
HomeAutomationKnowledgeBase
Loads generated capability catalog and natural-language dataset resources.
HomeBixbyCommandCatalog and HomeBixbyCommandMapper
Bixby command source data and utterance-to-draft mapping support.
HomeRiskPolicy and HomeParameterValidator
Deterministic safety and parameter validation rules.
IntentCapabilityMap
Maps NLU intent families to likely capability IDs for retrieval hints.
HomeModelInstructionPackage, FoundationModelContextBudgeter, and HomeAdapterModelProvider
Foundation Models prompt/tool/session support, context budgeting, and adapter diagnostics.
Safety Rules
No registry mutation happens before safety, parameter, confirmation, and execution-planning gates complete.
Safety, parameter, confirmation, execution-planning, and mock-execution agents fail closed if missing, failed, or blocked by a circuit breaker.
Memory-derived targets are hints only. Candidate retrieval, hydration, safety validation, and confirmation policy run again.
High-risk actions such as lock/unlock, open/close, camera, valve, oven, and security-sensitive operations require explicit confirmation.
RAG ranks and selects relevant context, but canonical registries remain the source of truth.
Foundation Models prompts are budgeted and compacted before draft generation; tool outputs are capped and safety still depends on deterministic validators.
RAG now stores both full display content and clean semanticContent. Embeddings use the clean semantic field, while BM25 and formatted debugging keep the full content plus metadata. Knowledge agents use StructuredRetrievalQuery, NLURetrievalHints, and metadata filters so intent families, device types, rooms, and capability hints can narrow retrieval before prompts are built.