Coordinator
Classes
Classes
Coordinator
Main coordinator class that orchestrates agent work
Constructor
constructor(config: { orgId: string; gatewayUrl: string; pollIntervalMs: number; heartbeatThresholdMs: number; maxRestartAttempts: number; discordChannelId?: string | undefined; }, mcpCall: McpCallFn)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
config | { orgId: string; gatewayUrl: string; pollIntervalMs: number; heartbeatThresholdMs: number; maxRestartAttempts: number; discordChannelId?: string | undefined; } | Yes | |
mcpCall | McpCallFn | Yes |
Methods
runOnce
Run a single iteration of task dispatch and health check
runOnce(): Promise<RunResult>
Returns:
Promise<RunResult> -
start
Start the coordinator loop
start(): Promise<void>
Returns:
Promise<void> -
stop
Stop the coordinator loop
stop(): void
getLifecycleManager
Get the lifecycle manager for manual operations
getLifecycleManager(): LifecycleManager
Returns:
LifecycleManager -
HeartbeatMonitor
Monitors agent heartbeats and marks offline when stale
Constructor
constructor(flowState: FlowStateMcpClient, orgId: string, thresholdMs?: number)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
flowState | FlowStateMcpClient | Yes | |
orgId | string | Yes | |
thresholdMs | number | No |
Methods
checkHealth
Check health of all agents
checkHealth(): Promise<HealthCheckResult>
Returns:
Promise<HealthCheckResult> - Lists of healthy, offline, and errored agents
LifecycleManager
Manages starting, stopping, and restarting agent sessions
Constructor
constructor(flowState: FlowStateMcpClient, openClaw: OpenClawClient, orgId: string)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
flowState | FlowStateMcpClient | Yes | |
openClaw | OpenClawClient | Yes | |
orgId | string | Yes |
Methods
getOrgId
Get the organization ID (for future use in logging/context)
getOrgId(): string
Returns:
string -
startAgent
Start an agent session
startAgent(teamMemberId: string, agentDef: AgentDefinition): Promise<LifecycleResult>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
teamMemberId | string | Yes | |
agentDef | AgentDefinition | Yes |
Returns:
Promise<LifecycleResult> -
stopAgent
Stop an agent session
stopAgent(teamMemberId: string, sessionId: string): Promise<LifecycleResult>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
teamMemberId | string | Yes | |
sessionId | string | Yes |
Returns:
Promise<LifecycleResult> -
restartAgent
Restart an agent session
restartAgent(teamMemberId: string, oldSessionId: string, agentDef: AgentDefinition): Promise<LifecycleResult>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
teamMemberId | string | Yes | |
oldSessionId | string | Yes | |
agentDef | AgentDefinition | Yes |
Returns:
Promise<LifecycleResult> -
TaskWatcher
Polls FlowState for assigned tasks and dispatches to idle agents
Constructor
constructor(flowState: FlowStateMcpClient, openClaw: OpenClawClient, orgId: string)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
flowState | FlowStateMcpClient | Yes | |
openClaw | OpenClawClient | Yes | |
orgId | string | Yes |
Methods
checkAndDispatch
Check for assigned tasks and dispatch to idle agents
checkAndDispatch(): Promise<DispatchResult[]>
Returns:
Promise<DispatchResult[]> - Array of dispatch results
FlowStateMcpClient
Client for FlowState operations via MCP
Constructor
constructor(mcpCall: McpCallFn)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
mcpCall | McpCallFn | Yes |
Methods
getAgents
Get all agents (TeamMembers where isAgent=true)
getAgents(orgId: string): Promise<AgentInfo[]>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
orgId | string | Yes | - Organization ID to query |
Returns:
Promise<AgentInfo[]> - Array of agent information
getAssignedTasks
Get tasks assigned to agents (status = "To Do", has assignedAgent)
getAssignedTasks(orgId: string): Promise<TaskAssignment[]>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
orgId | string | Yes | - Organization ID to query |
Returns:
Promise<TaskAssignment[]> - Array of task assignments
updateAgentStatus
Update agent status in TeamMember.extended
updateAgentStatus(teamMemberId: string, status: AgentStatus, sessionId?: string | undefined): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
teamMemberId | string | Yes | - TeamMember ID to update |
status | AgentStatus | Yes | - New agent status |
sessionId | string | undefined | No | - Optional session ID |
Returns:
Promise<void> -
claimTask
Mark a task as claimed
claimTask(taskId: string): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
taskId | string | Yes | - Task ID to claim |
Returns:
Promise<void> -
releaseTask
Release a task (clear claimedAt, set failedAt)
releaseTask(taskId: string): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
taskId | string | Yes | - Task ID to release |
Returns:
Promise<void> -
updateHeartbeat
Update agent heartbeat timestamp
updateHeartbeat(teamMemberId: string): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
teamMemberId | string | Yes | - TeamMember ID to update |
Returns:
Promise<void> -
getClaimedTasksForAgent
Get tasks claimed by a specific agent
getClaimedTasksForAgent(orgId: string, teamMemberId: string): Promise<TaskAssignment[]>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
orgId | string | Yes | - Organization ID |
teamMemberId | string | Yes | - TeamMember ID of the agent |
Returns:
Promise<TaskAssignment[]> - Array of claimed task assignments
OpenClawClient
Client for communicating with OpenClaw gateway via HTTP
Constructor
constructor(gatewayUrl: string)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
gatewayUrl | string | Yes |
Methods
createSession
Create a new agent session
createSession(request: CreateSessionRequest): Promise<SessionResponse>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
request | CreateSessionRequest | Yes |
Returns:
Promise<SessionResponse> -
sendMessage
Send a message to an active session
sendMessage(sessionId: string, message: TaskDispatchMessage): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes | |
message | TaskDispatchMessage | Yes |
Returns:
Promise<void> -
stopSession
Stop an active session
stopSession(sessionId: string): Promise<void>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes |
Returns:
Promise<void> -
isSessionAlive
Check if a session is alive
isSessionAlive(sessionId: string): Promise<boolean>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes |
Returns:
Promise<boolean> -