Doc — Professional Document Generator
Generate professional, beautifully formatted documents by calling the Skywork Office Doc API.
Prerequisites
API Key Configuration (Required First)
This skill requires a
SKYWORKAPIKEY to be configured before use.
If you don't have an API key yet, please visit:
https://skywork.ai
For detailed setup instructions, see:
references/apikey-fetch.md
Privacy & Remote Calls (Read Before Use)
- - Remote upload & processing: This skill uploads user-provided files and sends the full, verbatim user request to the Skywork service. Avoid sensitive or confidential content unless you trust the remote service and its data handling policies.
- Web search: Any web search mentioned in this skill is performed by the server-side Skywork Doc API, not locally by these scripts.
Workflow
Step 0: Intent Recognition (CRITICAL - Do This First)
Before calling any script, analyze the user's request and determine:
- 1. Does the user provide reference files, or imply that certain files are needed to proceed with the writing task?
- Look for file paths, attachments, or mentions like "based on this PDF", "use the uploaded document". If you gathered info beforehand (e.g., web search, other tools) that would help the writing task, save it to disk as files and pass them as reference files in Step 1.
- If YES: find/extract file paths → proceed to Step 1
- If NO: skip to Step 2
- 2. What language should the output be in?
- Analyze the user's request language or explicit requirement. If unspecified, infer from the user's language or the language used in uploaded files.
- Set
--language parameter:
English,
中文简体, etc.
- Default: INLINECODE3
- 3. What format does the user want?
- Look for keywords: "Word document" →
docx, "PDF" →
pdf, "HTML" →
html, "Markdown" →
md
- Default if not specified:
docx
-
Supported formats:
docx,
pdf,
html, INLINECODE12
- 4. How to write the content prompt?
- The
--content parameter is like a
rewrite query
- Synthesize user's requirements (possibly from multiple conversation turns)
- Be specific: describe structure, sections, tone, key points. Avoid being overly verbose or straying far from the user's original requirements; stay close to their intent to ensure accuracy.
Step 1: Parse Reference Files (If User Provides Files)
IMPORTANT:
- -
parse_file.py processes one file at a time. For multiple files, call it multiple times. - Quote any file path that contains spaces so arguments are passed correctly.
- Parse all reference material the user needs for the writing task as files. If a file was already parsed earlier in the session, skip re-parsing and reuse its
file_id.
Single file:
CODEBLOCK0
Multiple files (call the script once for each file; you can run these in parallel to speed things up):
CODEBLOCK1
Each script call outputs:
CODEBLOCK2
Extract all PARSED_FILE outputs and collect them into a JSON array:
CODEBLOCK3
This array will be passed to create_doc.py via the --files parameter below.
Step 2: Create Document
Without reference files:
CODEBLOCK4
With reference files (use the collected file_ids from Step 1):
CODEBLOCK5
The title field should not contain spaces.
Output:
CODEBLOCK6
Step 3: Deliver Result
After create_doc.py finishes, parse the final JSON output. It contains two ways for the user to access the document — always provide both:
- -
file_url — the remote download link (cloud URL). Include it as a clickable hyperlink so the user can open it in a browser or share it. file_path — the absolute local path where the file was automatically downloaded on their machine. Mention this path explicitly so the user can find the file right away without manual downloading.
Example reply (adapt wording to user's language):
The document is ready!
If file_path is empty (download failed), still provide file_url and inform the user they can download manually.
Script Parameters
parse_file.py
- -
file - Path to the reference file (required) - INLINECODE27 - Output full result as JSON (optional)
Key Output: PARSED_FILE: <json> — extract this for Step 2
create_doc.py
- -
--title - Document title (required) - INLINECODE30 - Content prompt describing what to write (required)
- This is like a rewrite query — synthesize user's requirements
- Be specific about structure, sections, tone, key points
- -
--files - JSON array of file objects from parse_file.py (optional)
- Format:
[{"file_id":"xxx","filename":"yyy","url":""}]
- -
--language - Output language (optional, default: English)
- Examples:
English,
中文简体,
中文繁體,
日本語,
한국어,
Français,
Deutsch,
Español, ...
- -
--format - Output format (optional, default: docx)
-
Supported:
docx,
pdf,
html,
md
Important Notes
- 1. Intent Recognition First - Always analyze the user's request before calling scripts.
- Web Search Built-In - The Doc API automatically performs web searches on demand to gather relevant content for document creation. Whether you pre-search for materials externally or not is entirely optional—either approach works fine.
- File ID is the Bridge -
parse_file.py outputs file_id → pass to create_doc.py via --files. - Server Fetches Content - No need to paste
parsed_content manually; the server retrieves it using file_id. - Content is Rewrite Query - Synthesize the user's requirements into a clear, detailed prompt. Even when the user's instructions are long or complex, capture every requirement—don't omit anything.
- Generation Takes Time - Document generation typically takes 5-10 minutes, sometimes longer for complex documents.
- Scripts Wait Automatically -
create_doc.py uses SSE (Server-Sent Events) to maintain a long connection and receives real-time progress updates. The script will automatically wait up to 3~10 minutes for completion. No manual polling needed - just wait for the script to finish and it will output the result. - Progress Display - The script shows a real-time progress bar during generation. The AI agent should relay this to the user to set expectations.
- Final Document Delivery - CRITICAL: Upon successful execution of
create_doc.py, the output JSON contains both file_url (remote download link) and file_path (local path where the file was automatically saved). You MUST proactively return both to the user: the clickable file_url so they can share or open it online, and the file_path so they can locate it immediately on their machine. If file_path is empty, notify the user and provide file_url for manual download.
Error Handling
| Error | Solution |
|---|
INLINECODE63 / INVALID_TOKEN / INLINECODE65 | Authentication failed (keep the error code / raw message in the reply). Verify SKYWORK_API_KEY is set in OpenClaw or rotate a valid key (see references/apikey-fetch.md). Do not suggest upgrading membership. |
| INLINECODE67 |
Check network connection |
|
JSON parse error | Use double quotes in --files JSON |
|
Insufficient benefit | Script or log may show e.g.
Insufficient benefit. Please upgrade your account at {url} — see below |
How to reply when benefit is insufficient
When you detect the above, reply in the user's current language — do not echo the English message. Use this pattern:
- - Convey: "Sorry, document generation failed. This skill requires upgrading your Skywork membership to use." then a single call-to-action link.
- Format: One short sentence in the user's language + a link like
[Upgrade now →](url) or the equivalent in their language. - URL: Extract the upgrade URL from the log/script output (e.g. the
at https://... part).
Technical Notes
- - Generation takes 5-10 minutes, set sufficient timeout. Because
create_doc.py may run for a long time. As SSE events arrive, display each stage to the user. This keeps them informed during the generation.
Doc — 专业文档生成器
通过调用天工Office文档API,生成专业、格式精美的文档。
前置条件
API密钥配置(必须优先完成)
此技能在使用前需要配置
SKYWORKAPIKEY。
如果您还没有API密钥,请访问:
https://skywork.ai
详细设置说明请参考:
references/apikey-fetch.md
隐私与远程调用(使用前请阅读)
- - 远程上传与处理:此技能会上传用户提供的文件,并将用户的完整请求逐字发送至天工服务。请避免包含敏感或机密内容,除非您信任该远程服务及其数据处理策略。
- 网络搜索:此技能中提到的任何网络搜索均由服务端的天工文档API执行,而非本地脚本。
工作流程
第0步:意图识别(关键——请优先执行)
在调用任何脚本之前,分析用户的请求并确定:
- 1. 用户是否提供了参考文件,或暗示需要某些文件才能继续写作任务?
- 查找文件路径、附件或类似基于此PDF、使用上传的文档等表述。如果您事先收集了有助于写作任务的信息(例如通过网络搜索或其他工具),请将其保存为磁盘文件,并在第1步中作为参考文件传入。
- 如果是:查找/提取文件路径 → 进入第1步
- 如果否:跳至第2步
- 2. 输出应使用哪种语言?
- 分析用户请求的语言或明确要求。若未指定,则根据用户使用的语言或上传文件中的语言推断。
- 设置 --language 参数:English、中文简体 等。
- 默认值:English
- 3. 用户需要什么格式?
- 查找关键词:Word文档 → docx,PDF → pdf,HTML → html,Markdown → md
- 未指定时默认:docx
-
支持的格式:docx、pdf、html、md
- 4. 如何编写内容提示?
- --content 参数类似于
重写查询
- 综合用户的需求(可能来自多轮对话)
- 具体描述:结构、章节、语气、关键点。避免过于冗长或偏离用户的原始需求;贴近用户的意图以确保准确性。
第1步:解析参考文件(如果用户提供了文件)
重要提示:
- - parsefile.py 一次只处理一个文件。对于多个文件,需多次调用。
- 对包含空格的文件路径使用引号,以确保参数正确传递。
- 将用户写作任务所需的所有参考资料作为文件进行解析。如果某个文件在本次会话中已被解析过,则跳过重新解析,直接复用其 fileid。
单个文件:
bash
python3 /scripts/parse_file.py /path/to/reference.pdf
多个文件(每个文件调用一次脚本;可并行运行以加快速度):
bash
解析文件1
python3
/scripts/parse_file.py /path/to/file1.pdf
解析文件2
python3 /scripts/parse_file.py /path/to/file2.xlsx
解析文件3
python3 /scripts/parse_file.py /path/to/file3 with blank in it.docx
每次脚本调用输出:
[parse] File: reference.pdf (2,458,123 bytes)
...
[success] File parsed!
File ID: 2032146192467681280
...
PARSEDFILE: {fileid:2032146192467681280,filename:reference.pdf,url:}
提取所有 PARSED_FILE 输出,并将其收集到一个JSON数组中:
json
[
{file_id:2032146192467681280,filename:file1.pdf,url:},
{file_id:2032146192467681281,filename:file2.xlsx,url:},
{file_id:2032146192467681282,filename:file3.docx,url:}
]
此数组将通过下面的 --files 参数传递给 create_doc.py。
第2步:创建文档
无参考文件时:
bash
python3 /scripts/create_doc.py \
--title Document_Title \
--content 基于用户需求的详细内容提示... \
--language English \
--format docx
有参考文件时(使用第1步收集的file_id):
bash
python3 /scripts/create_doc.py \
--title Analysis_Report \
--content 基于上传的参考文件,创建一份全面的分析报告... \
--files [{fileid:id1,filename:file1.pdf,url:},{fileid:id2,filename:file2.xlsx,url:}] \
--language English \
--format docx
title 字段不应包含空格。
输出:
[doc] Creating document: Analysis Report
...
[success] Document created!
File ID: abc-123
Path: /output/doc/some_file.html
URL: https://...
Time: 15.2s
第3步:交付结果
create_doc.py 完成后,解析最终的JSON输出。其中包含两种让用户访问文档的方式——请始终同时提供两者:
- - fileurl — 远程下载链接(云端URL)。将其作为可点击的超链接提供,方便用户在浏览器中打开或分享。
- filepath — 文件自动下载到用户机器上的本地绝对路径。明确提及此路径,以便用户无需手动下载即可立即找到文件。
回复示例(根据用户语言调整措辞):
文档已生成!
如果 filepath 为空(下载失败),仍提供 fileurl 并告知用户可以手动下载。
脚本参数
parse_file.py
- - file - 参考文件的路径(必填)
- --json - 以JSON格式输出完整结果(可选)
关键输出:PARSED_FILE: — 提取此内容用于第2步
create_doc.py
- - --title - 文档标题(必填)
- --content - 内容提示,描述要撰写的内容(必填)
- 这类似于重写查询——综合用户的需求
- 具体说明结构、章节、语气、关键点
- - --files - 来自parse_file.py的文件对象JSON数组(可选)
- 格式:[{file_id:xxx,filename:yyy,url:}]
- - --language - 输出语言(可选,默认值:English)
- 示例:English、中文简体、中文繁體、日本語、한국어、Français、Deutsch、Español、...
- - --format - 输出格式(可选,默认值:docx)
- 支持的格式:docx、pdf、html、md
重要说明
- 1. 先进行意图识别 - 在调用脚本之前,始终先分析用户的请求。
- 内置网络搜索 - 文档API会自动按需执行网络搜索,以收集文档创建所需的相关内容。您是否预先在外部搜索材料完全可选——两种方式均可。
- 文件ID是桥梁 - parsefile.py 输出 fileid → 通过 --files 传递给 createdoc.py。
- 服务端获取内容 - 无需手动粘贴 parsedcontent;服务端使用 fileid 检索内容。
- 内容是重写查询 - 将用户的需求综合成一个清晰、详细的提示。即使用户的指令很长或很复杂,也要捕捉每一个需求——不要遗漏任何内容。
- 生成需要时间 - 文档生成通常需要5-10分钟,复杂文档可能更久。
- 脚本自动等待 - createdoc.py 使用SSE(服务器发送事件)保持长连接,并接收实时进度更新。脚本会自动等待3~10分钟完成。无需手动轮询——只需等待脚本完成,它就会输出结果。
- 进度显示 - 脚本在生成过程中会显示实时进度条。AI代理应将此信息传达给用户,以管理预期。
- 最终文档交付 - 关键:createdoc.py 成功执行后,输出的JSON包含 fileurl(远程下载链接)和 file_path(文件自动保存的本地路径)。您必须