JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
docs(heart-beat): 更新心跳文档
xiaoxiawangfbeb6866c6d4
diff --git a/docs/en/Heartbeat.md b/docs/en/Heartbeat.mdindex 724e449175..618f73689b 100644--- a/docs/en/Heartbeat.md+++ b/docs/en/Heartbeat.md@@ -1,109 +1,112 @@# Heartbeat-**Heartbeat** is a periodic probe from the gateway to AgentServer to verify connectivity and agent health. If **`workspace/HEARTBEAT.md`** (under the agent workspace) is configured, the agent can also run listed tasks on each beat. You can choose which channel receives results (default: web).+Heartbeat is jiuwenSwarm's periodic liveness probe and task runner. The gateway sends requests to AgentServer at a fixed interval to verify connectivity and agent availability. If **`workspace/HEARTBEAT.md`** is configured, the agent can also run predefined tasks on each beat. Results can be relayed to a chosen channel (default: web).---## 1. Overview-- **Liveness**: Sends on a fixed interval to confirm the service is up.-- **Optional tasks**: If `workspace/HEARTBEAT.md` exists under the project root, the agent runs “active task items” in order and returns the results; otherwise the response is `HEARTBEAT_OK`.-- **Relay**: Heartbeat responses can be forwarded to a configured channel (e.g. web) for UI display.+- **Liveness**: Sends requests to AgentServer on an interval to confirm the service is healthy.+- **Optional tasks**: If `workspace/HEARTBEAT.md` exists at the project root, the agent reads and executes the active task items in order and returns results. Without this file or empty tasks, only `HEARTBEAT_OK` is returned.+- **Result relay**: Heartbeat responses can be forwarded to a configured channel (e.g., web UI) for visibility of the latest heartbeat status and content.---## 2. Configuration-Three ways: config file, environment variables, or the web UI.+Three configuration methods are available: config file, environment variables, or web UI.-### 2.1 `config/config.yaml`+### 2.1 Config file `config/config.yaml`++Configure the `heartbeat` section in `config/config.yaml`:```yamlheartbeat:- # Interval in seconds, default 3600+ # Interval in seconds; default 3600every: 3600- # Relay target channel (e.g. "web" for the web UI)+ # Channel for relaying results (e.g., "web" = web UI)target: web- # Active window in local time; omit for 24/7+ # Active window in local time; heartbeat only within this range; omit for 24/7active_hours:start: 08:00end: 22:00```-| Field | Meaning | Notes |-| ----- | ------- | ----- |-| `every` | Interval (seconds) | Must be > 0. `60` = every minute, `3600` = hourly. |-| `target` | Relay channel | Often `web` to push to the web client; empty = no relay. |-| `active_hours` | Time window | `start` / `end` as `HH:MM` (24h). Heartbeat only fires when local time is in `[start, end]`. Omit for always on. Supports windows past midnight (e.g. 22:00–06:00). |-+|-------|---------|-------|+| `every` | Interval (seconds) | Must be > 0; e.g., 60 = every minute, 3600 = hourly |+| `target` | Relay channel | Usually `web`, which pushes heartbeat responses to the web UI; empty or omitted = no relay |+| `active_hours` | Active window | `start`/`end` in `HH:MM` (24-hour format). Heartbeat only fires within `[start, end]`. Supports cross-midnight windows (e.g., 22:00–06:00). |### 2.2 Environment variables (override YAML)-| Variable | Meaning | Example |-| -------- | ------- | ------- |+|----------|---------|---------|| `HEARTBEAT_INTERVAL` | Interval (seconds) | `3600` || `HEARTBEAT_RELAY_CHANNEL_ID` | Relay channel | `web` || `HEARTBEAT_TIMEOUT` | Single heartbeat timeout (seconds) | `30` |+Environment variables take precedence over the `heartbeat` section in `config/config.yaml`.-Env vars override the `heartbeat` section in `config/config.yaml`.--### 2.3 Web UI — Heartbeat panel+### 2.3 Web UI Heartbeat panel-Open **Heartbeat** in the sidebar to:+Open **Heartbeat** in the left sidebar:-- View the current heartbeat configuration (interval, relay target, and active window)+- View current heartbeat configuration (interval, relay target, active window)-- Edit and save (writes `config.yaml` and restarts the heartbeat service)+- Edit and save configuration (writes `config/config.yaml` and restarts the heartbeat service)-- See the last 20 heartbeat messages (status, body, time)+- View the last 20 heartbeat records, including status (normal / warning), content, and timestamps----## 3. `HEARTBEAT.md` and periodic tasks+## 3. HEARTBEAT.md and periodic tasks-### 3.1 Location and role+### 3.1 File location and role-- **Path**: In the web UI, the file appears on the right side of the panel and can be changed by clicking **Edit**.+- **Path**: In the web UI, this file appears on the right side of the Heartbeat panel. Click `Edit` to modify it.-- **Role**: If the file exists and lists tasks, each heartbeat run parses and executes them and returns the results; otherwise only `HEARTBEAT_OK` is returned.+- **Role**: If the file exists and contains tasks, each heartbeat reads this content, executes tasks in order, and returns results. Without this file or empty tasks, only `HEARTBEAT_OK` is returned.### 3.2 Agent behavior-- The server reads `HEARTBEAT.md`, parses the task list, builds a chat request, and runs the normal flow. If parsing fails or the task list is empty, it returns `HEARTBEAT_OK`; otherwise, it executes the tasks and returns the response.+The server reads `HEARTBEAT.md`, parses the task list, and sends a chat request to the agent following the normal conversation flow. If parsing fails or the task list is empty, `HEARTBEAT_OK` is returned directly. Otherwise, tasks are executed and responses returned.----## 4. Web UI and events+## 4. Web UI display and events-- **Status**: The heartbeat panel and toolbar show the latest heartbeat information (such as `HEARTBEAT_OK`) and time.-- **Events**: When `target` is `web`, each heartbeat response is pushed to the frontend through the `heartbeat.relay` event to update status and history. Content other than `HEARTBEAT_OK` is displayed in a popup so task results or errors can be viewed.+- **Status**: The Heartbeat panel and toolbar display the latest heartbeat info (e.g., `HEARTBEAT_OK`) and timestamp.+- **Events**: When `target` is `web`, each heartbeat response is pushed to the frontend via the `heartbeat.relay` event for status and history updates. If content is not `HEARTBEAT_OK`, a popup notification appears for viewing task results or errors.---## 5. FAQ-**Q: I edited `heartbeat` in `config.yaml` but nothing changed.**-A: Config is read at startup. If you use the web panel, it rewrites YAML and restarts the heartbeat service. If you edit YAML by hand, restart the app (e.g. `jiuwenswarm-web`).+**Q: I changed the heartbeat section in `config/config.yaml` but nothing happened.**+A: Config is read at startup. If you use the web UI Heartbeat panel, it rewrites YAML and automatically restarts the heartbeat service. If you edit YAML directly, restart the entire application (e.g., `jiuwenswarm-web`) for changes to take effect.-**Q: Heartbeats only during work hours?**-A: Set `heartbeat.active_hours.start` / `end`, e.g. `09:00`–`18:00`.+**Q: How do I send heartbeats only during work hours?**+A: Set `heartbeat.active_hours.start` / `end`, e.g., `start: 09:00`, `end: 18:00`. Heartbeats only fire within this window.-**Q: Heartbeat timeout?**-A: Set `HEARTBEAT_TIMEOUT` (seconds). On timeout the beat is marked failed and a WARNING is logged.+**Q: What if a heartbeat request times out?**+A: Set the `HEARTBEAT_TIMEOUT` environment variable (seconds). On timeout, the beat is marked failed and a WARNING is logged.-**Q: Where must `HEARTBEAT.md` live?**-A: At the DeepAgent workspace root: `~/.jiuwenswarm/agent/workspace/HEARTBEAT.md`. Otherwise it is treated as no custom tasks and only `HEARTBEAT_OK` is returned.+**Q: Where must `HEARTBEAT.md` live?**+A: At the DeepAgent workspace root: `~/.jiuwenswarm/agent/workspace/HEARTBEAT.md`. Otherwise, it is treated as "no custom tasks" and only `HEARTBEAT_OK` is returned.----## 6. Code index+## 6. Code and config index- Service: `jiuwenswarm/gateway/heartbeat/heartbeat.py`.-- Config: `jiuwenswarm/common/config.py` (`update_heartbeat_in_config`); at startup, `app.py` builds `HeartbeatConfig` from the `heartbeat` section of `~/.jiuwenswarm/config/config.yaml` and environment variables.-- Agent: `jiuwenswarm/server/runtime/agent_adapter/interface_deep.py` determines whether the current session is a heartbeat session, then reads `HEARTBEAT.md` and triggers the tasks.-- Web: `jiuwenswarm/channels/web/frontend/src/components/HeartbeatPanel/`, `heartbeat.get_conf` / `heartbeat.set_conf`, `heartbeat.relay`.+- Config reading and writing: `jiuwenswarm/common/config.py` (`update_heartbeat_in_config`); `app.py` builds `HeartbeatConfig` from the `heartbeat` section in `~/.jiuwenswarm/config/config.yaml` and environment variables at startup.+- Agent-side HEARTBEAT.md handling: `jiuwenswarm/server/runtime/agent_adapter/interface_deep.py` detects heartbeat sessions and reads `HEARTBEAT.md` to trigger tasks.+- Frontend: `jiuwenswarm/channels/web/frontend/src/components/HeartbeatPanel/`, `heartbeat.get_conf` / `heartbeat.set_conf`, `heartbeat.relay` events.++*Document version: v1.0*+*Audience: jiuwenSwarm users*+*Last updated: 2026-06-25*+*Simplified Chinese: [心跳](../zh/心跳.md)*\ No newline at end of filediff --git "a/docs/zh/\345\277\203\350\267\263.md" "b/docs/zh/\345\277\203\350\267\263.md"index 3513d00b2d..ca95df44f2 100644--- "a/docs/zh/\345\277\203\350\267\263.md"+++ "b/docs/zh/\345\277\203\350\267\263.md"@@ -108,3 +108,4 @@ A:必须放在 DeepAgent workspace 根目录下:`~/.jiuwenswarm/agent/worksp- Agent 侧 HEARTBEAT.md 处理:`jiuwenswarm/server/runtime/agent_adapter/interface_deep.py` 中确定当前是心跳会话,则读取 `HEARTBEAT.md` 并触发任务。- 前端:`jiuwenswarm/channels/web/frontend/src/components/HeartbeatPanel/`、`heartbeat.get_conf` / `heartbeat.set_conf`、`heartbeat.relay` 事件。+