--- name: sn-infographic description: | Generates professional infographics with various layout types and visual styles. Analyzes content, recommends layout and style, and generates publication-ready infographics. Use when user asks to create "infographic", "信息图", "visual summary", or "可视化". metadata: project: SenseNova-Skills tier: 1 category: scene priority: 9 user_visible: true triggers: - "infographic" - "information graphic" - "infographics generation" - "visual summary" - "data visualization" - "visual explanation" - "diagram" - "生成信息图" - "信息图生成" - "生成 infographic" - "信息图表" - "图表生成" - "数据可视化" - "图解" --- # sn-infographic Info graphic generation scene skill (tier 1), relying on the `sn-image-generate`, `sn-image-recognize`, and `sn-text-optimize` tools provided by `sn-image-base` (tier 0). Features: - Evaluation of prompt quality (auto mode) - Prompt expansion (force/auto mode) - Multiple rounds of image generation and VLM review - Output the best result based on quality ranking ## Input Specification | Parameter | Type | Default Value | Description | |-----------|------|---------------|-------------| | `user_prompt` | string | **Required** | Original user request. UTF-8 text; may include Markdown, URLs, or structured data. Length bounded only by the underlying LLM context budget. | | `max_rounds` | int | `1` | Maximum number of generation rounds. Valid range: `1`–`8`. When `max_rounds=1`, the Step 3 VLM review and the early-termination check are both skipped. | | `output_mode` | string | `friendly` | `friendly`: one-line content description + rank=1 single image | | | | | `verbose`: full quality ranking + timing stats + all images (ordered by rank) | | `prompts_expand_mode` | string | `auto` | `auto`: evaluate `user_prompt` quality first; enter Step 2 expansion only when it falls short | | | | | `force`: skip evaluation, always execute Step 2 expansion | | | | | `disable`: skip Step 2, use `user_prompt` directly as `expanded_prompt` | | `aspect_ratio` | string | *inferred* (`16:9`) | Set by **Main Agent** when the user states an explicit supported ratio (e.g. `16:9` / `9:16`, optionally via `宽高比` / `画面比例` / `aspect ratio`); otherwise left unset and the **Worker** infers it in Step 0 from `user_prompt` (orientation / scene cues) per `references/runtime-parameters.md`. | | `image_size` | string | *inferred* (`2k`) | Set by **Main Agent** when the user states an explicit size (`2k` / `4k`); otherwise the **Worker** infers it in Step 0 (currently a single option, `2k`). `4k` is forwarded to the model and may be rejected (e.g. sensenova) → surfaced as an error. | > **Who extracts what:** Main Agent parameter extraction resolves `max_rounds`, `output_mode`, `prompts_expand_mode`, and `aspect_ratio` / `image_size` (each only when the user gives an explicit value). `aspect_ratio` and `image_size` without an explicit value are inferred by the Worker in Step 0. ## API Configuration All API calls in this skill are executed through the `sn_agent_runner.py` of the `sn-image-base` skill, with authentication parameters using default values (CLI > environment variables > built-in defaults),无需显式传入。 | Call Type | Tool | Authentication Parameters | Description | |-----------|------|---------------------------|-------------| | **LLM** | sn-text-optimize (evaluation/expansion) | Default reads `SN_TEXT_API_KEY` -> `SN_CHAT_API_KEY` -> `SN_API_KEY` | Built-in default points to Sensenova internal network service | | **VLM** | sn-image-recognize (image review) | Default reads `SN_VISION_API_KEY` -> `SN_CHAT_API_KEY` -> `SN_API_KEY` | Built-in default points to Sensenova internal network service | | **Image Generation** | sn-image-generate | Default reads `SN_IMAGE_GEN_API_KEY` -> `SN_API_KEY`; `SN_IMAGE_GEN_API_KEY` is only needed for image-specific override | Default uses image generation configuration of `sn-image-base` | **When encountering `MissingApiKeyError` or needing to specify a model**: pass explicitly via CLI parameters, parameter reference `$SN_IMAGE_BASE/references/api_spec.md`. **`$SN_IMAGE_BASE` path explanation**: `$SN_IMAGE_BASE` is the installation directory of the `sn-image-base` skill (`SKILL.md` exists). The agent can locate this path by skill name `sn-image-base` in the list of installed skills. ## Architecture: Main Agent + Worker Agent This skill uses a two-tier agent architecture: | Role | Responsibility | |------|----------------| | **Main Agent** | Receive user request, normalize parameters, send preflight, start Worker, collect results, send text and images to user | | **Worker Agent** | Execute the generation pipeline (expand → multiple rounds of generation + review → sort), return structured JSON | **Responsibility Boundaries**: - Worker Agent **does not send any messages to the user directly**, only returns structured JSON - Main Agent is responsible for sending all user-visible messages - Worker Agent's last message **must be and only be** the JSON string defined in the Return Contract - Worker Agent's internal VLM calls **always execute directly**, without spawning subagents ## Workflow ### Main Agent Workflow 1. **Parameter extraction** from the user request, in three passes: 1. **Inline KV directives** — parse tokens of the form `key=value` where `key` ∈ {`max_rounds`, `output_mode`, `prompts_expand_mode`, `aspect_ratio`, `image_size`}; strip recognized tokens from the user message, and the remainder becomes `user_prompt`. Example: `"生成一张信息图 max_rounds=3 output_mode=verbose"` → `user_prompt="生成一张信息图"`, `max_rounds=3`, `output_mode=verbose`. 2. **Keyword recognition** (case-insensitive, applied to the stripped text) — fill any parameter not yet set by inline KV using the table below: | Parameter | Trigger keywords | Resolved value | |-----------|------------------|----------------| | `output_mode` | `verbose`, `详细`, `详尽`, `完整统计` | `verbose` | | | `friendly`, `简洁`, `精简` | `friendly` | | `max_rounds` | `N 轮`, `N rounds`, `重试 N 次` (parse `N`) | `N`, clamped to `[1, 8]` | | `prompts_expand_mode` | `强制扩写`, `force expand`, `force expansion` | `force` | | | `不扩写`, `跳过扩写`, `disable expansion`, `no expand` | `disable` | | `aspect_ratio` | an explicit supported ratio (`16:9` `9:16` `4:3` `3:4` `1:1` `2:3` `3:2` `4:5` `5:4` `21:9` `9:21`), with or without a `宽高比` / `画面比例` / `比例` / `aspect ratio` lead-in | that ratio (validated against the supported set in `runtime-parameters.md`; unsupported value → leave unset for Worker inference) | | `image_size` | an explicit supported size (`2k` `4k`), with or without an `image_size` / `分辨率` / `清晰度` / `image size` lead-in | that size (vague quality words like `高清` / `超清` do **not** count); unsupported value → leave unset for Worker inference | 3. **Defaults** — any parameter still unset falls back to `max_rounds=1`, `output_mode=friendly`, `prompts_expand_mode=auto`. `aspect_ratio` and `image_size` have **no** Main-Agent default: when no explicit value is detected they are left unset for the Worker to infer in Step 0. Precedence: **inline KV > keyword recognition > default**. Values from inline KV are validated against the Input Specification (out-of-range `max_rounds` clamped to `[1, 8]`; unrecognized enum values fall back to default and Main Agent should log the mismatch). 2. Send uniform preflight message: `"Using sn-infographic skill to generate infographic, please wait..."` 3. Start Worker Agent (Sub-Agent), passing in complete parameters and working directory 4. When Worker Agent returns `status=ok` and `need_main_agent_send=true`: - **max_rounds = 1**: Generate the Text Summary (see Output Format → friendly mode for length/language rules) from `expanded_prompt` in the returned JSON (always present for `status=ok`, see Return Contract), send it, then send the rank=1 single image - **max_rounds > 1, friendly mode**: Generate the Text Summary based on the rank=1 round's `result` and `violations`, send it, then send the rank=1 single image - **max_rounds > 1, verbose mode**: Render the verbose template (see Output Format → verbose mode for substitution rules) and send it, then send all images in rank order 5. If Worker Agent returns `status=error`, report the real `error` field content to the user ### Worker Agent Workflow Worker Agent receives `user_prompt`, `max_rounds`, `prompts_expand_mode`, an optional `aspect_ratio` and `image_size` (each set only when the user gave an explicit value), and the working directory of this skill (`SKILL_DIR`). (`output_mode` stays on the Main Agent side — Worker has no branch that depends on it.) #### Worker Environment Variables referenced as `$NAME` in the bash snippets below. Worker must bind each before the step that consumes it. | Variable | Source | Used by | |----------|--------|---------| | `USER_PROMPT` | Main Agent input — original user request | Step 1 evaluation; Step 2.0 content analysis | | `MAX_ROUNDS` | Main Agent input (default `1`) | Step 3 loop bound; early-termination gate | | `PROMPTS_EXPAND_MODE` | Main Agent input (default `auto`) | branches Step 1 | | `SKILL_DIR` | Agent runtime resolves the current skill's install path (e.g. `~/.openclaw/skills/sn-infographic`, `~/.hermes/skills/sn-infographic`) | reads `references/*` | | `SN_IMAGE_BASE` | Agent runtime resolves by skill name `sn-image-base` in the installed-skill registry | runs `scripts/sn_agent_runner.py` | | `TASK_ID` | Step 0 (`date +%Y%m%d_%H%M%S`) | uniqueness token | | `TEMP_DIR` | Step 0 (`/tmp/openclaw/sn-infographic/${TASK_ID}`) | scratch dir for all intermediate artifacts | | `IMAGE_SIZE` | Main Agent input when the user stated an explicit size, else Step 0 inference from `USER_PROMPT` (single option, `2k`) | `sn-image-generate --image-size` | | `ASPECT_RATIO` | Main Agent input when the user stated an explicit ratio, else Step 0 inference from `USER_PROMPT` (default `16:9`) | `sn-image-generate --aspect-ratio` | | `EXPANDED_PROMPT` | Step 1 (copy of `USER_PROMPT` when Step 2 is skipped) or Step 2.3 (expanded result) | `sn-image-generate --prompt` | | `LAYOUT`, `STYLE` | Step 2.1 selection result (with fallback to `hub-spoke` / `corporate-memphis`) | Step 2.3 system-prompt assembly | | `ROUND` | Step 3 loop counter (`for ROUND in $(seq 1 "$MAX_ROUNDS")`) | per-round file naming (`round_${ROUND}.png`) | **Naming**: `$SKILL_DIR` for own files; `$SN_` (e.g. `$SN_IMAGE_BASE`) for cross-skill references. **JSON parsing**: every `sn_agent_runner.py ... -o json` call prints a JSON *envelope* on stdout (`{"status", "result", "model", ...}`; diagnostics go to stderr). A failed call sets `status` to a non-`ok` value (e.g. `failed`) and omits `result`, so **always confirm `.status == ok` on the envelope before reading `.result`** — otherwise a missing `.result` surfaces as the literal `null`, which is itself valid JSON and slips past both `jq -r` and `extract_json.py` (no error raised). The LLM's own JSON (evaluation / analysis steps) lives inside the `result` string and may carry stray prose or ` ```json ` fences. Before any `jq`, pipe the runner output through `$SN_IMAGE_BASE/scripts/extract_json.py` (reads stdin, prints the recovered JSON, exits non-zero when none is found); for steps that parse the inner LLM/VLM JSON, pipe `.result` through it as well. A non-`ok` status or a non-zero `extract_json.py` exit means the response is unusable → return the Error Flow JSON. #### Step 0 — Initialization 1. Generate `task_id` (timestamp, format `YYYYMMDD_HHMMSS`) and create the uniform temporary directory `/tmp/openclaw/sn-infographic//` as `TEMP_DIR`. `TEMP_DIR` must exist before any subsequent step writes to it: ```bash TASK_ID=$(date +%Y%m%d_%H%M%S) TEMP_DIR="/tmp/openclaw/sn-infographic/${TASK_ID}" mkdir -p "$TEMP_DIR" ``` 2. Initialize an empty `rounds` list 3. Resolve `aspect_ratio` and `image_size` (bind to `ASPECT_RATIO` / `IMAGE_SIZE`): use the explicit Main Agent value when present, else infer from `user_prompt` per `$SKILL_DIR/references/runtime-parameters.md`. Defaults: `aspect_ratio` → `16:9`; `image_size` inference currently has a single option, `2k`. #### Step 1 — Decide whether to rewrite the image prompt (always runs) This step decides whether to **rewrite/expand the user's image-generation `prompt` text** before Step 3 generates the image, and produces the boolean `should_expand`. When Step 2 is skipped it also sets `EXPANDED_PROMPT` and records `prompts_expand_skipped = true`. **Scope (do not over-read the step name).** "Expand" here means *rewriting the text prompt for image generation*, nothing more. This is **not** task decomposition, plan generation, or a plan-review gate, and Step 1 starts no agents of its own — it is a single `sn-text-optimize` call made by the Worker itself. Do not map it onto any `subagent-driven-development` / `delegate_task`-style workflow, and write no plan files. (The Worker is the only sub-agent this skill uses, started once by the Main Agent; the Worker spawns none of its own — see Responsibility Boundaries.) `PROMPTS_EXPAND_MODE` is the **already-resolved input** handed over by the Main Agent — Step 1 *acts on* it, it does **not** re-parse the user request. Resolving the mode value (Main Agent parameter extraction) and running this decision are two different jobs: completing the former does **not** complete Step 1. **Do not skip this step**; in `auto` mode the evaluation call below is mandatory — never infer `should_expand` from the prompt's apparent quality. Only **Step 2 (prompt expansion)** is ever skipped, and only when this step decides so. The branch depends on `PROMPTS_EXPAND_MODE`: **`auto` mode** (default): 1. Run the evaluation call (mandatory). The inner evaluation JSON lives inside `.result`; its schema is `$SKILL_DIR/references/evaluation-standard.md` (`required_results`, `optional_results`). ```bash EVAL_ENVELOPE=$(python "$SN_IMAGE_BASE/scripts/sn_agent_runner.py" sn-text-optimize \ --system-prompt-path "$SKILL_DIR/references/evaluation-standard.md" \ --user-prompt "$USER_PROMPT" \ --output-format json | python "$SN_IMAGE_BASE/scripts/extract_json.py") # A failed runner envelope (status != ok) carries no .result. EVAL_STATUS=$(printf '%s' "$EVAL_ENVELOPE" | jq -r '.status') EVAL=$(printf '%s' "$EVAL_ENVELOPE" | jq -r '.result' \ | python "$SN_IMAGE_BASE/scripts/extract_json.py") ``` 2. Decide `should_expand`: - `required_pass`: all `answer` in `required_results` are `"yes"` - `optional_pass`: count of `answer="yes"` in `optional_results` / total ≥ 0.6 - `should_expand = not (required_pass and optional_pass)` 3. **Conservative fallback**: if `EVAL_STATUS` is not `ok` (the evaluation call itself failed) or `extract_json.py` exits non-zero, default `should_expand = true`. Unlike Steps 2.0 / 2.3, a failed evaluation does **not** abort the Worker — `auto` falls back to expanding. 4. If `should_expand = true`: execute Step 2. 5. If `should_expand = false`: skip Step 2, set `EXPANDED_PROMPT` to the original prompt, record `prompts_expand_skipped = true`: ```bash EXPANDED_PROMPT="$USER_PROMPT" echo "$EXPANDED_PROMPT" > "$TEMP_DIR/expanded-prompt.txt" ``` **`force` mode**: - Skip the evaluation, always execute Step 2 (expansion is mandatory). - `prompts_expand_skipped` is **not** recorded — the field appears in the Return JSON only when Step 2 is skipped (see Return Contract rules). **`disable` mode**: - Skip both the evaluation and Step 2; use `user_prompt` directly as `expanded_prompt`: ```bash EXPANDED_PROMPT="$USER_PROMPT" echo "$EXPANDED_PROMPT" > "$TEMP_DIR/expanded-prompt.txt" ``` - Record `prompts_expand_skipped = true`. #### Step 2 — Content Analysis + Layout & Style Selection + Prompt Expansion **2.0 Content Analysis** (using `sn-image-base`'s `sn-text-optimize` tool): ```bash ANALYSIS_ENVELOPE=$(python "$SN_IMAGE_BASE/scripts/sn_agent_runner.py" sn-text-optimize \ --system-prompt-path "$SKILL_DIR/references/analysis-framework.md" \ --user-prompt "$USER_PROMPT" \ --output-format json | python "$SN_IMAGE_BASE/scripts/extract_json.py") ``` Save the **inner** analysis JSON from `.result` (not the envelope, so Step 2.1 can `jq` `data_type` / `tone` / `audience` directly) to `$TEMP_DIR/analysis.json`. The guard below rejects a failed envelope first (status not `ok` or `extract_json.py` non-zero → Error Flow with `.error`): ```bash # A failed runner envelope (status != ok) has no .result → return Error Flow. if [ "$(printf '%s' "$ANALYSIS_ENVELOPE" | jq -r '.status')" != "ok" ]; then ANALYSIS_ERROR=$(printf '%s' "$ANALYSIS_ENVELOPE" | jq -r '.error') # return Error Flow JSON {"status":"error","error":"$ANALYSIS_ERROR"} to Main Agent and stop fi printf '%s' "$ANALYSIS_ENVELOPE" | jq -r '.result' \ | python "$SN_IMAGE_BASE/scripts/extract_json.py" > "$TEMP_DIR/analysis.json" ``` Schema: `$SKILL_DIR/references/analysis-framework.md` (defines `data_type`, `tone`, `audience`, and the other fields consumed by Step 2.1 / 2.2). **2.1 Layout & Style Selection** This is a **name-level, weighted-random pick** from the candidate tables in `$SKILL_DIR/references/layout-style-selection.md`; it operates purely on layout/style **names**. **Do NOT open any file under `references/layouts/` or `references/styles/` here**, and do not "compare options" to choose a best fit — the pick is random, not reasoned over file contents. The one selected layout file and one selected style file are read exactly once, later, in Step 2.3. 1. Read analysis result from temporary directory `$TEMP_DIR/analysis.json`; ```bash ANALYSIS=$(cat "$TEMP_DIR/analysis.json") ``` 2. From `data_type` / `tone` / `audience`, run the candidate lookup + weighted-random sampling defined in `$SKILL_DIR/references/layout-style-selection.md` to obtain one `LAYOUT` name and one `STYLE` name (names only — no file reads); 3. Validate the selection by checking the definition files exist (existence only via `[ -f ]`, still no reading); fall back to `hub-spoke` + `corporate-memphis` if missing: ```bash [ -f "$SKILL_DIR/references/layouts/${LAYOUT}.md" ] || LAYOUT=hub-spoke [ -f "$SKILL_DIR/references/styles/${STYLE}.md" ] || STYLE=corporate-memphis ``` 4. Save selection result to temporary directory: `$TEMP_DIR/layout-style.json`; Format of `layout-style.json`: ```json { "layout": "", "style": "