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 heartbeatRunorchestration/engine/heartbeat.ts agent-invoker.invokeAgent()dispatches to adapter-specific pathengine/agent-invoker.ts INPUTS · feed RuntimeOptions agent.adapterConfigadapterType · model project.envproject files · env agent.skillsadditionalSkillPaths agent.systemPromptrole · instructions agent.envreusable defaults wakeup payloadissueId · 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.adapterConfigResolvedAdapterConfig adapterType branch"claude-code" → invokeClaudeCode()"pi-agent" → invokePiAgent() ASSEMBLE RuntimeOptions · packages/agent/src/runtimes/types.ts cwdworkspace pathcloud: NFS mountlocal: ~/.lifeosai systemPromptbuilt by prompt-builder.tsrole · skills · wake-contextchannel hint (if channel) mcpServerschannels (auto)+ whatsapp · phone · files+ side-panel · connector-status env (redacted)env precedence chain+ run-local LIFEOSAI_*secret refs redacted other optionsmodelsessionId · resumepermissionMode AUTHORIZATION · run-scoped JWT mintAgentRunToken()Authorization: Bearer $LIFEOSAI_RUN_TOKENorchestration/auth/run-token.ts · short-lived JWT scoped to this run RUNTIME ENGINES · packages/agent/src/runtimes Claude Code SDK@anthropic-ai/claude-agent-sdkcreateStreamingSession(opts)claude-code-runtime.ts Pi Coding Agentcustom adapter (in-house)emits PiSSEEvent shapepi-agent-runtime.ts event-normalizernormalizes Pi → SDKMessageso frontend parses one shapeevent-normalizer.ts LLM PROVIDER (external) Anthropic · Gemini · OpenAIruntime makes LLM API calls SDKMessage STREAM · text · tool_use · permission_request · result STREAM SINKS event-buspublishRunEvent SSE → FrontendCompanyEventsContext runEvents DBdurable record Channel StreamSinkif channel run Activity LoglogActivity() cost · usagerecordCost · budget resolveAdapterConfig assemble options mint run token dispatch to runtime LLM API call stream back publishRunEvent → sinks