Boot and runtime wiring
This walkthrough uses sample app application/basic_demo, covering entry main.c and wiring in app_claw.c.
main.c entry
Section titled “main.c entry”main.c initializes required system pieces and peripherals so the ESP-Claw Agent can run.
-
Init NVS and load settings
On boot,
basic_demoinitializes the NVS partition (nvs_flash_init). Thenbasic_demo_settings_init+basic_demo_settings_loadpull Wi‑Fi, LLM, IM, search, time zone, etc. into RAM. -
Init Board Manager and optional Emote
Call
esp_board_manager_initto assemble board-level device handles.
IfCONFIG_BASIC_DEMO_ENABLE_EMOTEis enabled,app_expression_emote_startis also invoked afterward to start the emote-display component and set the screen to an offline hint state. -
Mount FATFS
Mount FATFS at the virtual path
/fatfs.
If mount fails,ESP_ERROR_CHECKtriggersabortand the device reboots—a filesystem is required for ESP-Claw to run normally. -
Init Wi‑Fi and state callback
Attempt Wi‑Fi init (
basic_demo_wifi_init/basic_demo_wifi_start): connect to configured SSID and start SoftAP for Web configuration and offline operations.- After
basic_demo_wifi_init,basic_demo_wifi_register_state_callbackis registered: if emote is enabled, it updates emote and text status on Wi‑Fi connect/disconnect, and can display intermediate state such as current AP SSID. - On failure, log and continue. Offline rules and Lua can still run without a Wi‑Fi link.
- After
-
Start HTTP server
Bring up the config HTTP server (
config_http_server_init/config_http_server_start) for Web-based settings. Captive DNS (captive_dns_start) is started as well, so SoftAP provisioning can auto-redirect to the portal page. -
Start ESP-Claw Agent stack
Call
app_claw_start(&s_settings)to bring up the Agent subsystems.
app_claw.c Agent wiring
Section titled “app_claw.c Agent wiring”app_claw.c initializes the Agent stack in order, then launches the Console REPL.
-
Init Session Manager and Event Router
Call
cap_session_mgr_set_session_root_dirto set the session manager root, thenclaw_event_router_initloads the automation file (demo:/fatfs/router_rules/router_rules.json), sets timeouts talking toclaw_core, anddefault_route_messages_to_agent(truewhen LLM settings are complete). Therun_agentaction uses asynchronous submission; Agent responses are published back to the Event Router asout_messageevents. -
Init scheduler
cap_scheduler_initsets the schedule file path (/fatfs/scheduler/schedules.json), check interval (tick_ms), max items, task stack size and priority, and binds publishing (claw_event_router_publish). The scheduler initializes here but does not start yet. -
Init Memory
claw_memory_initsets session history root (/fatfs/sessions/), long-term memory directory (/fatfs/memory), and per-message limits (basic_demodefaults to 1024 chars per message). If required structured-memory files are missing, they are created automatically. -
Init Skills
claw_skill_initsets the Skills root (/fatfs/skills/) and session state root foractivate_skilland related flows. -
Init capabilities
claw_cap_init, then each cap module registers into groups:- cap_files: file root
/fatfs. - cap_lua: Lua root
/fatfs/scripts/. - cap_im_qq / feishu / tg / wechat: when credentials exist, apply App ID / Secret / Token and inbox path (
/fatfs/inbox/) plus max attachment size. - cap_web_search: store Brave / Tavily keys when non-empty.
- cap_router_mgr: register Event Router console commands (
event_router). - cap_system: register the system information capability group (memory, CPU, Wi-Fi, IP, and restart action).
- cap_mcp_client / cap_mcp_server / cap_skill / cap_time / cap_llm_inspect / cap_session_mgr, etc.: each
*_register_group(Skill management sources live undercap_skill_mgr; the group id remainscap_skill). - In full structured-memory mode, the
claw_memorycapability group is also registered; in lightweight mode it is not. claw_cap_set_llm_visible_groupsseedscap_files,cap_skill,cap_system, andcap_luafor the LLM; full structured-memory mode additionally includesclaw_memory. Thenclaw_cap_start_allstarts every group.
- cap_files: file root
-
Bind outbound IM channels
claw_event_router_register_outbound_bindingmapsqq,feishu,telegram,wechatto their send caps (e.g.qq_send_message). -
Init claw_core (conditional)
When
llm_api_key,llm_model, andllm_profileare all non-empty:claw_core_initconfigures the LLM backend (key, profile, model, base_url, timeouts) and system prompt;- register seven context providers:
claw_memory_profile_provider, a long-term provider (claw_memory_long_term_providerin full mode,claw_memory_long_term_lightweight_providerin lightweight mode),claw_memory_session_history_provider,claw_skill_skills_list_provider,claw_skill_active_skill_docs_provider,claw_cap_tools_provider,cap_lua_async_jobs_provider; claw_core_startlaunches the inference task.
Otherwise
claw_core_init/claw_core_startare skipped with a WARN—ask, default Agent routing, image inspect, and other core-dependent features stay unavailable until the LLM is configured and the device reboots. -
Start Event Router, time sync, scheduler, and Console REPL
claw_event_router_startbegins processing inbound events, thencap_time_sync_service_startstarts SNTP (first successful sync triggerscap_scheduler_handle_time_syncto rebase the scheduler), thencap_scheduler_startstarts the scheduler task, thenbasic_demo_cli_startopens the Console REPL—wiring complete.
Filesystem layout
Section titled “Filesystem layout”Directoryfatfs
Directorysessions
- … session history
Directorymemory
- MEMORY.md human-readable memory view (read-only)
- memory_records.jsonl structured memory records
- memory_index.json summary-tag and keyword index
- memory_digest.log memory-operation digest log
- user.md user profile
- soul.md persona
- identity.md identity
Directoryskills
- skills_list.json Skills manifest
- … Skill files
Directoryscripts
- … Lua scripts
Directoryrouter_rules
- router_rules.json automation rules
Directoryscheduler
- schedules.json scheduler config
- schedules.json.state scheduler runtime state
Directoryinbox
- … IM attachments