LifeOSAI — Agent Runtime · sequential view
heartbeat → agent-invoker → resolveAdapterConfig → assemble RuntimeOptions → mint run token → mount MCP servers + skills → dispatch to Claude Code SDK or Pi Coding Agent → stream SDKMessages → persist + publish.
ENTRY
heartbeat.executeRun() claims wakeup · creates heartbeatRun orchestration/engine/heartbeat.ts
agent-invoker.invokeAgent() dispatches to adapter-specific path engine/agent-invoker.ts
INPUTS · feed RuntimeOptions
agent.adapterConfig adapterType · model
project.env project files · env
agent.skills additionalSkillPaths
agent.systemPrompt role · instructions
agent.env reusable defaults
wakeup payload issueId · chatKey · context
RUN-LOCAL ENV INJECTED
LIFEOSAI_RUN_TOKEN · LIFEOSAI_RUN_ID
LIFEOSAI_AGENT_ID · LIFEOSAI_COMPANY_ID
LIFEOSAI_API_URL · LIFEOSAI_TIMEZONE
ENV PRECEDENCE
agent env → project env → run env
project overrides agent
run wins everything
AGENT RUNTIME PIPELINE · packages/agent + apps/api/src/orchestration/engine
ADAPTER RESOLUTION
resolveAdapterConfig() reads agent.adapterConfig ResolvedAdapterConfig
adapterType branch "claude-code" → invokeClaudeCode() "pi-agent" → invokePiAgent()
ASSEMBLE RuntimeOptions · packages/agent/src/runtimes/types.ts
cwd workspace path cloud: NFS mount local: ~/.lifeosai
systemPrompt built by prompt-builder.ts role · skills · wake-context channel hint (if channel)
mcpServers channels (auto) + whatsapp · phone · files + side-panel · connector-status
env (redacted) env precedence chain + run-local LIFEOSAI_* secret refs redacted
other options model sessionId · resume permissionMode
AUTHORIZATION · run-scoped JWT
mintAgentRunToken() Authorization: Bearer $LIFEOSAI_RUN_TOKEN orchestration/auth/run-token.ts · short-lived JWT scoped to this run
RUNTIME ENGINES · packages/agent/src/runtimes
Claude Code SDK @anthropic-ai/claude-agent-sdk createStreamingSession(opts) claude-code-runtime.ts
Pi Coding Agent custom adapter (in-house) emits PiSSEEvent shape pi-agent-runtime.ts
event-normalizer normalizes Pi → SDKMessage so frontend parses one shape event-normalizer.ts
LLM PROVIDER (external)
Anthropic · Gemini · OpenAI runtime makes LLM API calls
SDKMessage STREAM · text · tool_use · permission_request · result
STREAM SINKS
event-bus publishRunEvent
SSE → Frontend CompanyEventsContext
runEvents DB durable record
Channel StreamSink if channel run
Activity Log logActivity()
cost · usage recordCost · budget
resolveAdapterConfig
assemble options
mint run token
dispatch to runtime
LLM API call
stream back
publishRunEvent → sinks