create-atomic-schema
它能做什么
它介绍如何编写 Atomic Agents 框架中智能体和工具所使用的输入与输出结构。适用于定义 AI 应用各部分所期望和返回的数据的开发者。
适用场景
- ✓当开发者需要一个由语言模型为智能体填写的输出结构时。
- ✓当开发者想在现有智能体或工具的输入中添加一个字段时。
- ✓当开发者想为工具分别定义成功和失败时的输出结构时。
技能链接
https://github.com/Eigenwise/atomic-agents/blob/main/claude-plugin/atomic-agents/skills/create-atomic-schema/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为一个规划智能体设计输出结构,它返回一个包含负责人和截止日期的步骤列表。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能先询问谁会使用这个结构定义,以及需要哪些字段和失败情况,然后编写一个带文档字符串和字段说明的结构定义类,因为这些说明也会引导模型。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Create an Atomic Agents Schema
Author a BaseIOSchema pair (input and/or output) that becomes the contract between an agent or tool and its caller. The framework enforces docstrings on every subclass, and Instructor flows field descriptions into the LLM prompt — so the schema is part of the prompt, not just typing.
For deep material (validators, discriminated unions, error envelopes), the authority is ../framework/references/schemas.md. This skill is the action-oriented path: clarify → write → validate.
When this fires vs the umbrella framework skill
- This skill: the user is creating or modifying a specific schema — e.g. "design the output schema for the planner agent", "add a field to
WeatherInput", "split the result into success and failure variants". frameworkskill: the user is asking about Atomic Agents in general or doing something other than authoring schemas.
Phase 1 — Clarify
Ask only what is not already obvious from context. Bundle into one message; do not interrogate one-at-a-time.
- Caller — is this for an
AtomicAgent, aBaseTool, both (an agent that emits a tool-input schema), or a nested sub-schema? - Direction — input only, output only, or a paired Input/Output?
- Fields — what fields does the caller need, with which types? (Required vs optional, defaults, constraints.)
- Failure modes — can this legitimately fail? If yes, plan a typed error variant rather than raising. See
../framework/references/schemas.md→ "Error-schema pattern".
If the user is mid-conversation about an existing schema, skip questions answered in context.
Phase 2 — Write
Place schema(s) where they will be imported from. Conventional locations:
<project>/agents/<agent_name>/schemas.py— agent-owned schemas<project>/tools/<tool_name>_tool.py— tool I/O lives next to the tool<project>/schemas/<topic>.py— schemas shared across multiple components
Required ingredients on every schema
- Subclass
BaseIOSchema(notBaseModel). - A non-empty class docstring — the framework raises at import otherwise. Write it for the LLM, because Instructor uses it as the schema's
description. - Every
Field(...)carries adescription=written for the LLM. - Use
Literal[...]for closed sets before reaching forEnum— flatter JSON Schema, easier for Instructor.
Minimal template
from typing import Optional, Literal
from pydantic import Field
from atomic_agents import BaseIOSchema
class WeatherInput(BaseIOSchema):
"""A request for current weather conditions."""
city: str = Field(..., description="City name, e.g. 'Brussels' or 'New York'.")
units: Literal["metric", "imperial"] = Field(
default="metric",
description="Unit system for the temperature.",
)
class WeatherOutput(BaseIOSchema):
"""Current weather conditions for a city."""
status: Literal["ok", "error"] = Field(..., description="Outcome code.")
temperature_c: Optional[float] = Field(
default=None, description="Temperature in Celsius when status='ok'."
)
summary: Optional[str] = Field(
default=None, description="Human-readable summary when status='ok'."
)
error: Optional[str] = Field(
default=None, description="Failure message when status='error'."
)
When to add validators
- Field-level for normalization (lowercase, strip, enum coercion) and single-field validation.
- Model-level (
@model_validator(mode="after")) for cross-field rules (start ≤ end, mutually exclusive flags).
Validation errors trigger Instructor retries and fire the parse:error hook — they're a feature, not a failure path. Do not swallow them.
When to use discriminated unions
If the caller must exhaustively handle multiple result shapes, prefer a union over an inflated single schema:
class SearchSuccess(BaseIOSchema):
"""Successful search result."""
kind: Literal["ok"] = "ok"
results: list[str] = Field(..., description="Matching items.")
class SearchFailure(BaseIOSchema):
"""Search could not complete."""
kind: Literal["error"] = "error"
code: Literal["rate_limited", "no_results", "upstream_error"] = Field(
..., description="Machine-readable failure code."
)
message: str = Field(..., description="Human-readable failure reason.")
class SearchOutput(BaseIOSchema):
"""Search outcome — success or typed failure."""
result: SearchSuccess | Se
常见问题
为什么结构定义需要文档字符串?
该框架要求如此,而且这些说明有助于语言模型正确填写每个字段。
结构定义可以有失败版本吗?
可以。该技能涵盖了可能失败的输出的成功和错误两种变体。
它面向谁?
面向需要带类型数据约定的 Atomic Agents 应用开发者。
详情
作者的原始描述
Design and write a `BaseIOSchema` input/output pair for an Atomic Agents agent or tool — docstrings, field descriptions, validators, error variants. Use when the user asks to "create a schema", "design the input/output schema", "define an `IOSchema`", "write a `BaseIOSchema`", "model the agent's output", or runs `/atomic-agents:create-atomic-schema`.
repo: Eigenwise/atomic-agents
热度
- GitHub 星标
- 6.3k
- 排名
- #14239
- 许可证
- MIT
- 更新时间
- 2026/10/29
评论
- …
同一仓库的更多技能
create-atomic-agent
6.3k帮你的智能体构建一个新的 Atomic Agents 智能体,包括带类型的输入和输出、系统提示词,以及所选的 AI 服务商。
create-atomic-context-provider
6.3k帮你的智能体为 Atomic Agents 智能体添加上下文提供者,使当前时间或检索到的文档等最新细节出现在其提示词中。
create-atomic-tool
6.3k帮你的智能体为 Atomic Agents 应用构建一个带类型的工具,例如智能体可以调用的 API 封装或计算器。
framework
6.3k帮你的智能体正确使用 Atomic Agents Python 框架,涵盖结构定义、智能体、工具、提示词和服务商设置。