Overview
The daemon coordinates all agent activity without manual intervention:The daemon runs as a background service on the smithy server. Start it with
sf daemon start.Polling Loops
The daemon executes five main polling loops every 5 seconds (configurable):1. Worker Availability Polling
Purpose: Assign unassigned tasks to available ephemeral workersFind Available Workers
Query for ephemeral workers with:
- No active session
- Not rate-limited
- Below pool capacity
Query Ready Tasks
Get highest priority tasks that are:
- Status: OPEN
- No assignee
- Not blocked by dependencies
Workers are spawned inside their worktree directory for full isolation.
2. Inbox Polling
Purpose: Route messages and trigger agent sessions when needed- Ephemeral Workers
- Persistent Workers
- Directors
- Stewards
Message Routing Logic:
- Poll for unread messages in worker inbox
- For each message:
- Dispatch message? Mark as read (spawn handled by worker polling)
- Has active session? Leave unread (session will handle it)
- Idle with non-dispatch messages? Leave unread to accumulate
- If accumulated messages exist, spawn triage session
- Groups messages by channel
- Spawns temporary session to process batch
- Uses message-triage prompt template
- Agent responds to messages then exits
3. Steward Trigger Polling
Purpose: Activate steward workflows based on triggersSteward Workflow Execution
Steward Workflow Execution
- Trigger fires (event or cron)
- Create workflow from playbook template
- Workflow picked up by Workflow Task Polling
- Steward session spawned to execute
4. Workflow Task Polling
Purpose: Assign workflow tasks to available stewardsFind Incomplete Workflows
Query for workflows with:
- Status: RUNNING or PENDING
- No assigned steward
- Current step not completed
Find Available Stewards
Get stewards matching workflow requirements:
- No active session
- Correct steward focus
- Not rate-limited
5. Orphan Recovery Polling
Purpose: Recover workers with assigned tasks but no active session after restartDetect Orphaned Assignments
Find ephemeral workers with:
- No active session (sessionStatus: ‘idle’)
- Assigned tasks (OPEN or IN_PROGRESS)
- Session terminated by restart
Attempt Resume
Try to resume previous session:
- Check for
sessionIdin task metadata - If found, attempt provider session resume
- Reuse existing worktree
- Inject resume context explaining restart
Orphan recovery runs at daemon startup and at the start of each poll cycle.
End-to-End Flow
Here’s a complete example of a task flowing through the system:Configuration
Customize daemon behavior via configuration:Configuration Options
Configuration Options
| Option | Default | Description |
|---|---|---|
pollIntervalMs | 5000 | Time between poll cycles |
workerAvailabilityPollEnabled | true | Enable task assignment |
inboxPollEnabled | true | Enable message routing |
stewardTriggerPollEnabled | true | Enable steward triggers |
workflowTaskPollEnabled | true | Enable workflow dispatch |
orphanRecoveryEnabled | true | Enable restart recovery |
maxResumeAttemptsBeforeRecovery | 3 | Resume limit before steward |
maxSessionDurationMs | 0 | Worker timeout (0=disabled) |
maxStewardSessionDurationMs | 1800000 | Steward timeout (30 min) |
Starting and Stopping
CLI
Programmatically
Monitoring
Poll Results
The daemon emits poll results after each cycle:Health Checks
Advanced Features
Rate Limit Handling
The daemon tracks rate-limited workers:Session Timeout
Automatically terminate sessions that run too long:Plan Auto-Completion
Automatically close plans when all tasks are done:Stuck Merge Recovery
Recover tasks stuck in merge states:Next Steps
Agent Roles
Learn about the agents being orchestrated
Task Management
Understand task lifecycle and statuses
Dependencies
See how blocking affects dispatch
Workflows
Build multi-step steward workflows