Agno 集成 Claude Agent Skills:让 Agent 一键生成 PPT、Excel、Word 与 PDF
Agno 集成 Claude Agent Skills让 Agent 一键生成 PPT、Excel、Word 与 PDF【免费下载链接】agnoBuild, run, and manage agent platforms.项目地址: https://gitcode.com/GitHub_Trending/ag/agno导读本文基于 Agno 开源仓库中cookbook/90_models/anthropic/skills/README.md及其配套示例系统讲解如何让基于 Anthropic Claude 模型的 Agno Agent 具备文档生产能力通过 Claude Agent Skills 的pptx、xlsx、docx、pdf四项技能Agent 能够在沙箱中执行代码直接生成专业级的 PowerPoint、Excel、Word 与 PDF 文件。读完本文你将掌握技能的原理progressive disclosure 渐进式披露、环境准备、直连 API 与 Agno 两种启用方式、多技能组合编排、沙箱文件的下载流程Anthropic Files API以及常见故障的排查思路。适用场景Agno 框架下构建办公自动化、数据分析报告、商业方案生成、教学课件等文档生成类 Agent。一、Claude Agent Skills 是什么Claude Agent Skills 是 Anthropic 为 Claude 模型提供的一组文档创作专项能力它让 Claude 在执行特定任务时表现更好PowerPointpptx创建包含幻灯片、版式与格式化效果的专业演示文稿Excelxlsx生成带公式、图表与数据分析能力的电子表格Worddocx创建和编辑富格式文档PDFpdf分析并提取 PDF 文档中的信息。这些技能采用progressive disclosure渐进式披露架构Claude 先「发现」哪些技能与当前任务相关仅在需要时才加载完整的技能指令从而把 token 开销控制到最低——这也是它与传统「一次性把所有工具说明塞进 system prompt」方案的关键区别。在 Agno 中这一能力被原生接入 Agent 框架只要给Claude模型传入skills参数框架会自动完成 beta 参数配置、代码执行工具注入、beta API 客户端切换以及容器container配置开发者无需关心底层细节。二、环境准备与安装2.1 前置条件条件说明Python 3.8Agno 与示例脚本的运行环境Anthropic API Key需具备 Claude 模型访问权限并开通 skills betaanthropic直接调用 Anthropic API文件下载也依赖它agnoAgent 框架python-pptx/openpyxl/python-docx/PyPDF2/pdfplumber可选仅在沙箱生成文件后需要在本地做文件处理时安装说明后一组文档处理库是「可选」的官方文档特别注明它们只用于「文件在沙箱中生成之后的本地处理」。Agent 本身生成文件靠的是 Anthropic 沙箱里的代码执行环境不依赖这些本地库。2.2 安装与密钥配置# 1. 安装核心包 uv pip install anthropic agno # 2. 可选安装本地文档处理库 uv pip install python-pptx openpyxl python-docx PyPDF2 pdfplumber配置 API Key两种方式任选# 方式一环境变量 export ANTHROPIC_API_KEYyour_api_key_here # 方式二项目根目录 .env 文件 # ANTHROPIC_API_KEYyour_api_key_here⚠️ 安全提醒永远不要把 API Key 提交进版本控制如.env文件应加入.gitignore。三、快速上手直连 Anthropic API 使用 Skills不借助框架时可以像下面这样直接调用 Anthropic 的 messages API 启用技能。关键点有三个betas开启 skills beta、container.skills声明技能清单、model选择支持技能和代码执行的 Claude 模型。import anthropic client anthropic.Anthropic() response client.messages.create( modelclaude-sonnet-4-5-20250929, max_tokens4096, betas[skills-2025-10-02], # 启用 skills beta container{ skills: [ {type: anthropic, skill_id: pptx, version: latest}, {type: anthropic, skill_id: xlsx, version: latest}, {type: anthropic, skill_id: docx, version: latest}, {type: anthropic, skill_id: pdf, version: latest}, ] # 一次性启用全部技能 }, messages[ {role: user, content: Create a 3-slide PowerPoint about AI trends} ] )这段代码演示了完整的「技能发现 → 代码执行 → 生成文件」链路。在实际使用中生成的文件不会直接出现在响应文本里而是通过工具结果返回一个file ID需要另行下载见第六节。四、Agno 原生集成给 Agent 挂上文档技能4.1 最小示例启用单个技能Agno 的Claude模型类新增了skills参数直接传入技能字典列表即可from agno.agent import Agent from agno.models.anthropic import Claude # 启用 PowerPoint 技能 agent Agent( modelClaude( idclaude-sonnet-4-5-20250929, skills[{type: anthropic, skill_id: pptx, version: latest}] # 启用 PPT 技能 ), instructions[ You are a presentation specialist., Create professional PowerPoint presentations. ], markdownTrue ) agent.print_response(Create a sales presentation with 5 slides)可用技能清单pptx、xlsx、docx、pdf。4.2 同时启用多个技能model Claude( idclaude-sonnet-4-5-20250929, skills[ {type: anthropic, skill_id: pptx, version: latest}, {type: anthropic, skill_id: xlsx, version: latest}, {type: anthropic, skill_id: docx, version: latest}, ] )4.3 框架自动完成了什么从源码libs/agno/agno/models/anthropic/claude.py可以看到当skills参数被设置时Agno 会在__post_init__阶段调用_setup_skills_configuration()自动完成以下工作自动合并必需 beta向betas数组注入[code-execution-2025-08-25, skills-2025-10-02]若已存在则不重复添加见 claude.py 第 296-314 行自动注入代码执行工具在请求参数中追加{type: code_execution_20250825, name: code_execution}工具——文档的生成与处理依赖代码执行能力见 claude.py 第 685-692 行自动设置容器将container{skills: self.skills}写入请求参数见 claude.py 第 588-589 行自动切换 beta API 客户端请求路径会走 beta 接口is_skills_or_code_execution等判断会匹配self.skills见 claude.py 第 418 行自动解析 file ID响应解析阶段会从bash_code_execution_tool_result块中提取file_id写入provider_data[file_ids]供后续文件下载使用见 claude.py 第 1096-1110 行。也就是说使用 Agno 时你无需手动写betas和container只需一行skills[...]。五、仓库配套示例详解示例位于cookbook/90_models/anthropic/skills/目录共四个脚本覆盖从单技能到多技能的工作流。5.1agent_with_powerpoint.pyPPT 专家 Agent在 agent_with_powerpoint.py 中Agent 被设定为「演示文稿专家」powerpoint_agent Agent( namePowerPoint Creator, modelClaude( idclaude-sonnet-4-5-20250929, skills[{type: anthropic, skill_id: pptx, version: latest}], ), instructions[ You are a professional presentation creator with access to PowerPoint skills., Create well-structured presentations with clear slides and professional design., Keep text concise - no more than 6 bullet points per slide., ], markdownTrue, )脚本内置了一个 Q4 业务复盘演示文档的完整 prompt标题页、关键指标、成就、挑战、Q1 目标五页结构运行后调用agent.run(prompt)生成q4_review.pptx并演示了如何从response.messages中读取provider_data配合download_skill_files()下载沙箱文件细节见第六节。适合场景商务演示文稿生成、市场分析报告、幻灯片设计与排版。5.2agent_with_excel.pyExcel 数据分析 Agentagent_with_excel.py 展示了数据技能Agent 被定义为「数据分析专家」prompt 要求生成一份 2026 年 1 月销售仪表盘——包含 5 名销售代表的数据表、总收入计算、按人柱状图、配额达成率以及绿色/红色条件格式最终保存为sales_dashboard.xlsx。适合场景数据分析与可视化、财务计算、CSV 转 Excel。5.3agent_with_documents.pyWord 文档 Agentagent_with_documents.py 演示docx技能生成一份《移动应用开发项目提案》包含执行摘要、项目概述、工作范围12 周时间线、团队、预算拆分与成功指标六个章节保存为mobile_app_proposal.docx。适合场景合同与提案起草、会议纪要、模板化文档生成。5.4multi_skill_agent.py多技能编排 Agentmulti_skill_agent.py 一次性启用pptx、xlsx、docx三个技能Agent 扮演「综合商务文档创作者」。示例 prompt 要求一次生成「销售报告包」一个带总计公式和柱状图的 Excelsales_report.xlsx加一份 Word 摘要sales_summary.docx并保持两份文件信息一致。这展示了多技能的编排价值Excel 数据 → PowerPoint 汇报 → PDF 归档整套商务工作流可在一个 Agent 会话内完成且技能采用渐进式披露按需加载。六、⚠️ 关键点下载沙箱中生成的文件技能生成的文件不会自动保存到本地文件系统。这是最容易踩坑的地方。文件生成的完整链路是Claude 在沙箱执行环境中创建文件如.pptx、.xlsx工具结果中返回一个file ID必须用 Anthropic Files API 单独下载到本地。6.1 直连 API 的下载方式import anthropic client anthropic.Anthropic() # 1. 创建文档注意带上代码执行工具与两个 beta response client.beta.messages.create( modelclaude-sonnet-4-5-20250929, max_tokens4096, betas[code-execution-2025-08-25, skills-2025-10-02], container{skills: [{type: anthropic, skill_id: pptx, version: latest}]}, messages[{role: user, content: Create a presentation...}], tools[{type: code_execution_20250825, name: code_execution}] ) # 2. 从工具结果中提取 file ID file_id None for block in response.content: if block.type tool_use and hasattr(block, result): file_id block.result.get(file_id) # 3. 下载文件 if file_id: file_content client.beta.files.download(file_idfile_id) with open(presentation.pptx, wb) as f: f.write(file_content)6.2 Agno 场景下的下载使用 Agno 时file ID 会被框架自动解析进response.messages[*].provider_data。仓库示例使用了一个download_skill_files()辅助函数provider_dataclient 默认文件名以 agent_with_powerpoint.py 为例from anthropic import Anthropic from file_download_helper import download_skill_files client Anthropic(api_keyos.getenv(ANTHROPIC_API_KEY)) if response.messages: for msg in response.messages: if hasattr(msg, provider_data) and msg.provider_data: files download_skill_files( msg.provider_data, client, default_filenameq4_review.pptx ) if files: print(fDownloaded {len(files)} file(s):) for f in files: print(f - {f}) break也可以手动遍历provider_data按源码中_parse_provider_response的逻辑读取file_ids字段由bash_code_execution_tool_result块解析而来再调用 Files API 下载。七、配置参数速查配置项取值说明模型推荐claude-sonnet-4-5-20250929或更新版本推荐用于 skills模型最低claude-3-5-sonnet-20241022需要具备代码执行能力betaskills-2025-10-02启用 skills 的 beta 参数Agno 自动注入betacode-execution-2025-08-25代码执行 betaAgno 自动注入container.skills[pptx]或[pptx, xlsx, docx, pdf]启用单个或全部技能本地可选库python-pptx、openpyxl、python-docx、PyPDF2、pdfplumber仅用于沙箱生成后的本地处理八、性能与使用建议Token 开销progressive disclosure 使技能按需加载最大限度降低 token 消耗生成耗时单个文档创建通常需要 10~30 秒取决于内容复杂度文件体积生成文件一般在 50KB~5MB 之间并发多个文档类型的技能可以并行使用。典型应用场景商务自动化Excel 数据自动转 PPT 汇报、财务分析与可视化、合同/提案生成、会议纪要数据分析CSV/Excel 可视化、统计图表、数据清洗转换、交互式仪表盘文档处理PDF 文本提取与分析、格式转换、模板化生成、批量处理教育领域课件生成、作业与测验制作、课程材料排版、论文分析。九、已知限制文件大小超过 100MB 的大文档可能触及 token 上限复杂排版部分高级格式化特性可能不受支持外部资源技能无法抓取外部图片或数据源OCRPDF 技能聚焦文本提取不支持扫描件的 OCR 识别。十、故障排查现象排查方向「Skills not available」错误确认betas[skills-2025-10-02]是否正确确认 API Key 有权访问支持 skills 的 Claude 模型确认账号已开通 skills beta 访问权限代码执行超时降低文档复杂度或体积把大任务拆分为多个小任务尽量使用简单格式文件未生成检查响应中是否有错误确认代码执行成功完成检查沙箱内文件路径与权限十一、进一步阅读示例目录cookbook/90_models/anthropic/skills/含README.md、TEST_LOG.md及四个示例脚本Agno 模型层实现libs/agno/agno/models/anthropic/claude.pyskills参数、beta 合并、代码执行工具注入与 file_id 解析均在_setup_skills_configuration、get_request_params、_parse_provider_response中实现更多 Claude 用法cookbook/90_models/anthropic/目录下还有code_execution.py、betas.py、thinking.py、structured_output.py等示例可对照学习Anthropic 官方文档Claude Agent Skills 快速入门与 Files API见 README 中 Additional Resources 一节授权说明该集成遵循与 Agno 框架相同的许可证。【免费下载链接】agnoBuild, run, and manage agent platforms.项目地址: https://gitcode.com/GitHub_Trending/ag/agno创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考