Implementation:23blocks OS Ai maestro Wake Agent
| Knowledge Sources | |
|---|---|
| Domains | Agent_Orchestration |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
Concrete tool for waking a hibernated agent into a tmux session and verifying the program started, provided by AI Maestro's `services/agents-core-service.ts` and `lib/program-launch.ts`.
Description
The wakeAgent service function is the core wake path: it resolves the agent from the registry, builds the launch command via `buildLaunchCommand`, creates or reuses a tmux session (via `lib/agent-runtime.ts` and `lib/tmux-safe.mjs`), starts the program, then calls verifyProgramStarted to poll the pane until the program appears or the grace period expires.
verifyProgramStarted watches a tmux pane. It returns `started: true` on any doubt — a false "did not start" would tell an operator their working agent is broken, which is worse than staying quiet. It reports failure only when the shell has explicitly complained on screen.
Usage
- Call `wakeAgent` to bring a hibernated or first-time agent online.
- `verifyProgramStarted` is called internally by `wakeAgent`; it is also testable in isolation via a `VerifyRuntime` adapter.
Code Reference
Source Location
- Repository: ai-maestro
- File: services/agents-core-service.ts (L1663-1985), lib/program-launch.ts (L124-175)
- Supporting: lib/launch-command.ts, lib/agent-runtime.ts, lib/tmux-safe.mjs, lib/pane-readback.mjs
Signature
export async function wakeAgent(
agentId: string,
params: WakeAgentParams
): Promise<ServiceResult<{
success: boolean
agentId: string
name: string
sessionName: string
sessionIndex: number
workingDirectory?: string
woken: boolean
alreadyRunning?: boolean
programStarted?: boolean
}>>
export async function verifyProgramStarted(
runtime: VerifyRuntime,
sessionName: string,
startCommand: string,
opts: { graceMs?: number; pollMs?: number } = {}
): Promise<LaunchVerdict>
interface WakeAgentParams {
sessionIndex?: number
program?: string
permissionMode?: AgentPermissionMode
workingDirectory?: string
model?: string
launchOptions?: unknown
}
interface VerifyRuntime {
capturePane(name: string, lines?: number): Promise<string>
describePane?(name: string): Promise<Record<string, string>>
}
interface LaunchVerdict {
started: boolean
occupant?: string
shellSaid?: string
error?: string
}
Import
import { wakeAgent } from '@/services/agents-core-service'
import { verifyProgramStarted } from '@/lib/program-launch'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agentId | string | Yes | Agent UUID |
| params.program | string | No | Program to start (else use stored) |
| params.permissionMode | string | No | Permission mode for this wake |
| params.sessionIndex | number | No | Which session slot (default 0) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | ServiceResult | success, sessionName, sessionIndex, woken, programStarted |
| LaunchVerdict | object | started, occupant, error (nil on success) |
Usage Examples
Wake an agent
import { wakeAgent } from '@/services/agents-core-service'
const result = await wakeAgent('agent-uuid', {
program: 'claude',
permissionMode: 'supervised',
sessionIndex: 0,
})
if (result.data?.woken) {
console.log(`Agent woke in session ${result.data.sessionName}`)
} else if (result.data?.alreadyRunning) {
console.log('Agent was already running')
}
Related Pages
Implements Principle
- Principle:23blocks_OS_Ai_maestro_One_Click_Wake
- Principle:23blocks_OS_Ai_maestro_Agent_Launch_Command
- Principle:23blocks_OS_Ai_maestro_Agent_Post_Transfer_Activation