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
{{ message }}
This repository was archived by the owner on Aug 19, 2026. It is now read-only.
Implement the agent instance lifecycle state machine that manages the full execution lifecycle of agent instances: creation, start, pause (at next safe point between tool calls), resume (from persisted context), stop (immediate termination), timeout enforcement, and token budget tracking. The state machine ensures clean transitions, proper resource cleanup, and audit logging at every state change.
Technical Details
Server — Lifecycle Service (server/src/services/agentLifecycle.service.ts)
PENDING → RUNNING (on start)
RUNNING → PAUSED (on pause signal)
RUNNING → COMPLETED (on task_complete tool call)
RUNNING → FAILED (on unrecoverable error)
RUNNING → STOPPED (on stop signal or timeout or budget exhaustion)
PAUSED → RUNNING (on resume)
PAUSED → STOPPED (on stop signal)
All other transitions rejected with error
Every transition: update DB, log audit event, emit Socket.IO event for real-time UI
Server — API Routes (extend agent.routes.ts)
POST /agents/:id/start — start new instance: { taskDescription }
POST /agents/instances/:instanceId/pause — pause
POST /agents/instances/:instanceId/resume — resume
POST /agents/instances/:instanceId/stop — stop: { reason? }
GET /agents/:id/instances — list instances
GET /agents/instances/:instanceId — get instance status + metrics
GET /agents/instances/:instanceId/actions — paginated action log
Code: AGENT-2127
Priority: HIGH
Section: Orchestration — Agent Orchestration Gateway (Phase 1: Agent Core)
Dependencies: AGENT-2126
Description
Implement the agent instance lifecycle state machine that manages the full execution lifecycle of agent instances: creation, start, pause (at next safe point between tool calls), resume (from persisted context), stop (immediate termination), timeout enforcement, and token budget tracking. The state machine ensures clean transitions, proper resource cleanup, and audit logging at every state change.
Technical Details
Server — Lifecycle Service (
server/src/services/agentLifecycle.service.ts)startAgent(agentId, taskDescription): Promise<AgentInstance>pauseAgent(instanceId): Promise<void>resumeAgent(instanceId): Promise<void>stopAgent(instanceId, reason?): Promise<void>getInstanceStatus(instanceId): Promise<AgentInstanceStatus>listInstances(agentId, filters?): Promise<AgentInstance[]>Server — State Machine
Valid transitions:
Server — API Routes (extend
agent.routes.ts)POST /agents/:id/start— start new instance:{ taskDescription }POST /agents/instances/:instanceId/pause— pausePOST /agents/instances/:instanceId/resume— resumePOST /agents/instances/:instanceId/stop— stop:{ reason? }GET /agents/:id/instances— list instancesGET /agents/instances/:instanceId— get instance status + metricsGET /agents/instances/:instanceId/actions— paginated action logServer — Socket.IO Events
/agentsinstance:status,instance:action,instance:token_updateServer — Cleanup
Files Involved
server/src/services/agentLifecycle.service.ts— State machine and lifecycle managementserver/src/routes/agent.routes.ts— Add instance lifecycle endpointsserver/src/controllers/agent.controller.ts— Add instance handlersserver/src/socket/agent.handler.ts— Socket.IO namespace for real-time agent eventsserver/src/index.ts— Register /agents Socket.IO namespaceReference: Agent Orchestration Gateway — Phase 1.6