create-atomic-tool
它能做什么
它介绍如何编写一个带类型输入和输出的工具,供 AI 智能体调用,包括可选的异步支持,以及从环境变量读取密钥。适用于为智能体增加功能的开发者。
适用场景
- ✓当开发者想让智能体通过一个带类型的工具调用外部 API 时。
- ✓当开发者想为智能体添加一个简单的计算器或查询工具时。
- ✓当开发者需要工具清楚地报告错误,例如速率限制或数据缺失时。
技能链接
https://github.com/Eigenwise/atomic-agents/blob/main/claude-plugin/atomic-agents/skills/create-atomic-tool/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请创建一个工具,查询某个城市的天气,并返回气温和天气状况。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能先询问工具的功能及其依赖,然后编写输入和输出结构定义、配置类和运行方法,其中密钥从环境变量中读取。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Create an Atomic Agents Tool
A tool is a deterministic capability an agent can invoke. In Atomic Agents, every tool is a BaseTool[InSchema, OutSchema] subclass with a typed run() (and optional run_async()). The input/output schemas double as the tool's signature for the LLM and as Pydantic validation at runtime.
For deep material (MCP interop, distributing as a standalone package, advanced error patterns), the authority is ../framework/references/tools.md. This skill is the action-oriented path: clarify → write → verify.
When this fires vs the umbrella framework skill
- This skill: the user is creating a specific tool — wrapping an API, building a calculator, scraping a page, querying a DB.
frameworkskill: questions about Atomic Agents in general, or the user is doing something other than authoring a tool.
Phase 1 — Clarify
Bundle into one message:
- What does the tool do? One sentence. This becomes the class docstring and feeds the LLM's tool description.
- Inputs and outputs. Names, types, units. If unclear, propose a schema pair and confirm.
- External dependencies. HTTP API? DB? Local computation only? If HTTP, what auth (API key env var, OAuth, none)?
- Sync, async, or both? If the rest of the project is async or the call is I/O bound, plan a
run_async()alongsiderun(). - Failure modes. Rate limits, not-found, network errors — how should the agent see them? Default: typed failure output, not raised exceptions.
Skip any question already answered in context.
Phase 2 — Plan
Confirm the location and shape in one short block, then proceed:
- File:
<project>/tools/<tool_name>_tool.py(in-project tool — see../framework/references/project-structure.md). - Schemas:
<ToolName>Input,<ToolName>Output, optionally a typed failure shape. - Config:
<ToolName>Config(BaseToolConfig)if the tool needs API keys, base URLs, timeouts, retries. - Sync vs async: pick one or both.
- Error pattern: typed failure output (preferred) vs raise (only for programmer error).
Phase 3 — Implement
Skeleton — local computation, no config
from pydantic import Field
from atomic_agents import BaseIOSchema, BaseTool
class CalculatorInput(BaseIOSchema):
"""Arithmetic expression to evaluate."""
expression: str = Field(..., description="Python-style arithmetic, e.g. '2 + 2 * 3'.")
class CalculatorOutput(BaseIOSchema):
"""Result of evaluating the expression."""
result: float = Field(..., description="Numeric result.")
class CalculatorTool(BaseTool[CalculatorInput, CalculatorOutput]):
"""Evaluate simple arithmetic expressions safely."""
def run(self, params: CalculatorInput) -> CalculatorOutput:
import ast, operator as op
ops = {ast.Add: op.add, ast.Sub: op.sub, ast.Mult: op.mul, ast.Div: op.truediv}
def ev(n):
if isinstance(n, ast.Constant): return n.value
if isinstance(n, ast.BinOp): return ops[type(n.op)](ev(n.left), ev(n.right))
raise ValueError("unsupported")
return CalculatorOutput(result=ev(ast.parse(params.expression, mode="eval").body))
Skeleton — HTTP-backed, with config and typed failure
import os
import httpx
from typing import Literal, Optional
from pydantic import Field
from atomic_agents import BaseIOSchema, BaseTool, BaseToolConfig
class WeatherConfig(BaseToolConfig):
api_key: str = Field(
default_factory=lambda: os.environ.get("WEATHER_API_KEY", ""),
description="API key for the weather service.",
)
base_url: str = Field(
default="https://api.weather.example/v1",
description="Base URL for the weather API.",
)
timeout: float = Field(default=15.0, ge=1.0, le=120.0, description="Request timeout (s).")
class WeatherInput(BaseIOSchema):
"""A request for current weather conditions."""
city: str = Field(..., description="City name, e.g. 'Brussels'.")
class WeatherOutput(BaseIOSchema):
"""Current weather conditions, or a typed failure."""
status: Literal["ok", "error"] = Field(..., description="Outcome code.")
temperature_c: Optional[float] = Field(default=None, description="Temperature in Celsius.")
summary: Optional[str] = Field(default=None, description="Human-readable summary.")
error: Optional[str] = Field(default=None, description="Failure message when status='error'.")
class WeatherTool(BaseTool[WeatherInput, WeatherOutput]):
"""
常见问题
API 密钥放在哪里?
该技能说明,密钥从环境变量中读取,而不是写入代码。
它需要异步支持吗?
只有在项目本身是异步的,或调用需要等待 I/O 时才需要。该技能可以添加异步版本。
错误是如何返回的?
该技能描述了带类型的失败输出,使智能体在出错时能得到清晰的结果。
详情
作者的原始描述
Build a `BaseTool[InSchema, OutSchema]` subclass — input/output schemas, `BaseToolConfig`, `run()` (and optional `run_async()`), env-driven secrets, typed failure outputs. Use when the user asks to "add a tool", "create a tool", "wrap an API as a tool", "build a `BaseTool`", "make a calculator/search/weather tool", or runs `/atomic-agents:create-atomic-tool`.
repo: Eigenwise/atomic-agents
热度
- GitHub 星标
- 6.3k
- 排名
- #14240
- 许可证
- MIT
- 更新时间
- 2026/10/29
评论
- …
同一仓库的更多技能
create-atomic-agent
6.3k帮你的智能体构建一个新的 Atomic Agents 智能体,包括带类型的输入和输出、系统提示词,以及所选的 AI 服务商。
create-atomic-context-provider
6.3k帮你的智能体为 Atomic Agents 智能体添加上下文提供者,使当前时间或检索到的文档等最新细节出现在其提示词中。
create-atomic-schema
6.3k帮你的智能体为 Atomic Agents 智能体和工具设计带类型的输入与输出结构定义,并附上清晰的字段说明。
framework
6.3k帮你的智能体正确使用 Atomic Agents Python 框架,涵盖结构定义、智能体、工具、提示词和服务商设置。