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:

ParameterTypeRequiredDescription
config{ orgId: string; gatewayUrl: string; pollIntervalMs: number; heartbeatThresholdMs: number; maxRestartAttempts: number; discordChannelId?: string | undefined; }Yes
mcpCallMcpCallFnYes

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:

ParameterTypeRequiredDescription
flowStateFlowStateMcpClientYes
orgIdstringYes
thresholdMsnumberNo

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:

ParameterTypeRequiredDescription
flowStateFlowStateMcpClientYes
openClawOpenClawClientYes
orgIdstringYes

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:

ParameterTypeRequiredDescription
teamMemberIdstringYes
agentDefAgentDefinitionYes

Returns:

Promise<LifecycleResult> -

stopAgent

Stop an agent session

stopAgent(teamMemberId: string, sessionId: string): Promise<LifecycleResult>

Parameters:

ParameterTypeRequiredDescription
teamMemberIdstringYes
sessionIdstringYes

Returns:

Promise<LifecycleResult> -

restartAgent

Restart an agent session

restartAgent(teamMemberId: string, oldSessionId: string, agentDef: AgentDefinition): Promise<LifecycleResult>

Parameters:

ParameterTypeRequiredDescription
teamMemberIdstringYes
oldSessionIdstringYes
agentDefAgentDefinitionYes

Returns:

Promise<LifecycleResult> -

TaskWatcher

Polls FlowState for assigned tasks and dispatches to idle agents

Constructor

constructor(flowState: FlowStateMcpClient, openClaw: OpenClawClient, orgId: string)

Parameters:

ParameterTypeRequiredDescription
flowStateFlowStateMcpClientYes
openClawOpenClawClientYes
orgIdstringYes

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:

ParameterTypeRequiredDescription
mcpCallMcpCallFnYes

Methods

getAgents

Get all agents (TeamMembers where isAgent=true)

getAgents(orgId: string): Promise<AgentInfo[]>

Parameters:

ParameterTypeRequiredDescription
orgIdstringYes- 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:

ParameterTypeRequiredDescription
orgIdstringYes- 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:

ParameterTypeRequiredDescription
teamMemberIdstringYes- TeamMember ID to update
statusAgentStatusYes- New agent status
sessionIdstring | undefinedNo- Optional session ID

Returns:

Promise<void> -

claimTask

Mark a task as claimed

claimTask(taskId: string): Promise<void>

Parameters:

ParameterTypeRequiredDescription
taskIdstringYes- Task ID to claim

Returns:

Promise<void> -

releaseTask

Release a task (clear claimedAt, set failedAt)

releaseTask(taskId: string): Promise<void>

Parameters:

ParameterTypeRequiredDescription
taskIdstringYes- Task ID to release

Returns:

Promise<void> -

updateHeartbeat

Update agent heartbeat timestamp

updateHeartbeat(teamMemberId: string): Promise<void>

Parameters:

ParameterTypeRequiredDescription
teamMemberIdstringYes- TeamMember ID to update

Returns:

Promise<void> -

getClaimedTasksForAgent

Get tasks claimed by a specific agent

getClaimedTasksForAgent(orgId: string, teamMemberId: string): Promise<TaskAssignment[]>

Parameters:

ParameterTypeRequiredDescription
orgIdstringYes- Organization ID
teamMemberIdstringYes- 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:

ParameterTypeRequiredDescription
gatewayUrlstringYes

Methods

createSession

Create a new agent session

createSession(request: CreateSessionRequest): Promise<SessionResponse>

Parameters:

ParameterTypeRequiredDescription
requestCreateSessionRequestYes

Returns:

Promise<SessionResponse> -

sendMessage

Send a message to an active session

sendMessage(sessionId: string, message: TaskDispatchMessage): Promise<void>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes
messageTaskDispatchMessageYes

Returns:

Promise<void> -

stopSession

Stop an active session

stopSession(sessionId: string): Promise<void>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes

Returns:

Promise<void> -

isSessionAlive

Check if a session is alive

isSessionAlive(sessionId: string): Promise<boolean>

Parameters:

ParameterTypeRequiredDescription
sessionIdstringYes

Returns:

Promise<boolean> -

Previous
Types