🏗️framework
- プラグイン
- atomic-agents
- ソース
- GitHub で見る ↗
説明
Atomic Agents Python フレームワークのガイド — スキーマ、エージェント、ツール、コンテキストプロバイダー、プロンプト、オーケストレーション、およびプロバイダー設定を対象とする。 次のような場合に使用: `atomic_agents` からインポートを行うコード、`AtomicAgent`・`BaseTool`・`BaseIOSchema` を定義するコード、またはユーザーが atomic-agents プロジェクトにおけるマルチエージェントオーケストレーションや LLM プロバイダーの接続設定について質問している場合。
原文を表示
Guide for the Atomic Agents Python framework — schemas, agents, tools, context providers, prompts, orchestration, and provider configuration. Use when code imports from `atomic_agents`, defines an `AtomicAgent`, `BaseTool`, or `BaseIOSchema`, or the user asks about multi-agent orchestration or LLM-provider wiring in an atomic-agents project.
ユースケース
- ✓atomic_agentsのインポートコードを書くとき
- ✓AtomicAgent・BaseTool・BaseIOSchemaを定義するとき
- ✓マルチエージェントオーケストレーションについて質問するとき
- ✓LLMプロバイダーの接続設定について質問するとき
本文(日本語訳)
Atomic Agents フレームワーク
Atomic Agents は、型付き・構造化された入出力を備えた LLM アプリケーション構築のための軽量 Python フレームワークです。Instructor と Pydantic の上に構築されており、ユーザー・Agent・ツール・コンテキスト間のあらゆるやり取りがバリデーション済みのスキーマとして扱われます。
このスキルは Claude にフレームワークの概要を提供し、タスクに応じて専用のリファレンスファイルへ誘導します。
コアの抽象概念
| 概念 | クラス | 役割 |
|---|---|---|
| スキーマ | BaseIOSchema |
型付きの入出力コントラクト — Agent・ツールの I/O はすべてこれ |
| Agent | AtomicAgent[In, Out] |
入力スキーマから出力スキーマへの LLM ベースの変換器 |
| Config | AgentConfig |
クライアント・モデル・履歴・プロンプト・ロール・API パラメータを結線 |
| プロンプト | SystemPromptGenerator |
background / steps / output_instructions の三節構成プロンプト |
| 履歴 | ChatHistory |
会話状態。シリアライズ可能でトークンカウント付き |
| ツール | BaseTool[In, Out] |
Agent が呼び出せる決定論的な機能 |
| コンテキスト | BaseDynamicContextProvider |
実行時にシステムプロンプトへ注入される動的セクション |
これらの要素間の通信はすべて BaseIOSchema のサブクラスを用い、docstring による説明が必須です。
標準的なインポート
from atomic_agents import (
AtomicAgent, AgentConfig,
BasicChatInputSchema, BasicChatOutputSchema,
BaseIOSchema, BaseTool, BaseToolConfig,
)
from atomic_agents.context import (
ChatHistory, Message,
SystemPromptGenerator, BaseDynamicContextProvider,
)
# オプション: MCP 相互運用
from atomic_agents.connectors.mcp import fetch_mcp_tools, MCPTransportType
atomic_agents.lib.base.* や atomic_agents.agents.base_agent のような旧パスは廃止済みのため使用しないでください。可能な限りトップレベルのパッケージからインポートしてください。
最小構成の Agent
import os, instructor, openai
from atomic_agents import AtomicAgent, AgentConfig, BasicChatInputSchema, BasicChatOutputSchema
from atomic_agents.context import ChatHistory
client = instructor.from_openai(openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"]))
agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](
config=AgentConfig(
client=client,
model="gpt-5-mini",
history=ChatHistory(),
)
)
reply = agent.run(BasicChatInputSchema(chat_message="Hello"))
print(reply.chat_message)
AtomicAgent と BaseTool は PEP 695 ジェネリクスを使用しており、型パラメータは実行時の情報を保持します。明示的に記述し、正確な型を維持してください。
完全な実行可能バージョン: atomic-examples/quickstart/quickstart/1_0_basic_chatbot.py
作成に特化したスキル
最もよくある 4 種類の作成タスクには、単なるリファレンス情報ではなく、段階的なワークフロー(明確化 → 記述 → 検証 → 引き渡し)を提供する専用の Atomic スキルが用意されています。ユーザーが何か具体的なものを構築しているときはこれらを優先してください。
| ユーザーの意図 | Atomic スキル |
|---|---|
| 「スキーマを作りたい」「入出力スキーマを設計したい」 | atomic-agents:create-atomic-schema |
「Agent を作りたい」「別の Agent を追加したい」「AtomicAgent を組み込みたい」 |
atomic-agents:create-atomic-agent |
「ツールを追加したい」「API をツールとしてラップしたい」「BaseTool を作りたい」 |
atomic-agents:create-atomic-tool |
| 「コンテキストプロバイダーを追加したい」「X をプロンプトに注入したい」「RAG を組み込みたい」 | atomic-agents:create-atomic-context-provider |
これらのスキルは対応するフレーズで自動的にトリガーされます。以下のリファレンスファイルは、これらのスキル(および Claude 自身)がより詳細な情報を参照する際に読み込むものです。
タスクごとのルーティング
タスクに合致するリファレンスファイルを選択してください。各ファイルは参照時にのみ読み込まれます。
| タスク | リファレンス |
|---|---|
| 入出力スキーマの設計・検証 | references/schemas.md |
| Agent の構築・設定・実行 | references/agents.md |
| Agent が呼び出すツールの作成 | references/tools.md |
| システムプロンプトへの動的データ注入 | references/context-providers.md |
| システムプロンプトの構成 | references/prompts.md |
| 複数 Agent の協調 | references/orchestration.md |
| 会話状態とマルチ Agent メモリの管理 | references/memory.md |
| テレメトリ・リトライ・ログの登録 | references/hooks.md |
| LLM プロバイダーの切り替えやロールの設定 | references/providers.md |
プロジェクト構成や pyproject.toml の決定 |
references/project-structure.md |
| Agent・ツールのテスト作成 | references/testing.md |
概念が不明な場合は、ユーザーの動詞から出発してください:
スキーマを作る → create-atomic-schema スキル、
天気 API を組み込む → create-atomic-tool スキル、
プロンプトにユーザー名を注入する → create-atomic-context-provider スキル、
Agent 間でルーティングする → orchestration リファレンス。
作業スタイル
プロジェクトで別途指定がない限り、以下のデフォルトに従ってください。各リファレンスファイルにより詳しい説明があります。
スキーマはコントラクトです。
Agent を書く前に BaseIOSchema のペアを設計してください。フィールドの説明は Instructor を通じて LLM プロンプトに流れ込むため、開発者だけでなくモデルを意識して記述してください。すべてのサブクラスに空でない docstring が必要です — フレームワークはクラス定義時にこれを強制します。
システムプロンプトは三節構成です。
SystemPromptGenerator(background=..., steps=..., output_instructions=...) を使用してください。ペルソナは background に、順序立てた手順は steps に、出力フォーマットのルールは output_instructions に記述します。省略した場合は合理的なデフォルトにフォールバックします。
プロバイダークライアントは必ず Instructor でラップしてください。
instructor.from_openai(...) / instructor.from_anthropic(...) / instructor.from_genai(...) — これなしでは Agent が出力スキーマを強制できません。
プロバイダー固有の設定には model_api_parameters を使用してください。
temperature / max_tokens / reasoning_effort などは AgentConfig の model_api_parameters dict に設定します。Agent 自体には設定しません。
エラーとリトライはフックを通じて処理してください。
run() を try/except で囲むのではなく、parse:error / completion:error / completion:last_attempt のハンドラーを登録してください。詳細は references/hooks.md を参照。
ツールは成功時に出力スキーマを返します。
失敗はバリデーションエラーまたは呼び出し元がパターンマッチできる型付きの結果スキーマとして表面化させてください — 本当に回復不能な失敗でない限り、run() を通じて例外を raise しないでください。
ユーザーがゼロから始める場合
新規プロジェクトのスキャフォールディング(新しいディレクトリ・pyproject.toml・最初の Agent の作成)は、兄弟スキルの new-app が担当します。ユーザーが「新しいプロジェクト」「ゼロから始めたい」などと言った場合はこれを提案してください。
ユーザーが既存のコードベースを理解したい場合
プロジェクトに atomic-agents のファイルが複数あり、ユーザーが「調べたい」「マッピングしたい」「X がどう動くか理解したい」などと言った場合は、atomic-explorer サブエージェントに委譲してください。このサブエージェントは関連ファイルを独立したコンテキストで読み込み、コンパクトなアーキテクチャマップ(Agent・ツール・スキーマ・コンテキストプロバイダー・オーケストレーション・必読ファイルリスト)を返します。プロンプトにスコープ(プロジェクトルート・モジュールパス・機能)を指定して Task ツール経由で呼び出してください。
小規模プロジェクト(単一の main.py + 1〜2 つの Agent)の場合は、メインスレッドで直接ファイルを読むほうが効率的です。独立したコンテキストを使うメリットは薄いです。
ユーザーがレビューを求める場合
メインスレッドでレビューするのではなく、atomic-reviewer サブエージェントに委譲してください。このサブエージェントは読み取り専用ツールを持つ独立したコンテキストで動作するため、ファイル探索が親の会話に混入しません。プロンプトにスコープ(diff・パス・モジュール)を指定して Task ツール経由で呼び出してください。レビュー結果は親スレッドが活用できる単一の構造化レポートとして返されます。
バージョンと互換性
- Python 3.12 以上(PEP 695 ジェネリクスを内部で使用)
- Instructor 1.14 以上、プロバイダー extras 付き(
instructor[openai]・instructor[anthropic]など)— ワークスペースは Instructor の extras を通じてプロバイダー SDK を取得 - Pydantic 2
- MCP 相互運用については
atomic_agents.connectors.mcpを参照 —fetch_mcp_tools・MCPFactory・MCPTransportTypeは安定版
アンチパターン(レビュー時に指摘すること)
BaseIOSchemaの代わりに素のBaseModelを使用しているBaseIOSchemaサブクラスの docstring がない(フレームワークはインポート時に raise する)Field(..., description="...")の description が欠けている — Instructor はプロンプト生成に description を活用するAgentConfig.clientに素のプロバイダークライアントを渡している(必ず Instructor でラップすること)。なお、埋め込み・画像生成・音声・モデレーション用の生 SDK 使用は問題ない — フレームワークが対象とするのは構造化チャット/補完のみ- API キーを環境変数ではなくハードコードしている
- 長時間稼働セッションで
ChatHistoryを無制限に拡張している BaseDynamicContextProvider.get_info()内でブロッキング I/O を行っている — これはagent.run()のたびに実行される- スキーマの問題を修正せず
ValidationErrorを握りつぶしている MCPTransportType.STREAMABLE_HTTPを使用している — 正しい値はHTTP_STREAMChatHistory.load(...)をクラスメソッドとして呼び出している — これは self を変更するインスタンスメソッド
より詳細なガイダンスは上記の該当リファレンスファイルを参照してください。コードレビューの実行時は atomic-reviewer サブエージェントに委譲してください。
原文(English)を表示
Atomic Agents Framework
Atomic Agents is a lightweight Python framework for building LLM applications with typed, structured input and output. It layers on top of Instructor and Pydantic so every interaction between user, agent, tool, and context is a validated schema.
This skill orients Claude on the framework and routes to focused reference files as the task requires.
Core abstractions
| Concept | Class | Role |
|---|---|---|
| Schema | BaseIOSchema |
Typed input/output contract — every agent/tool I/O is one |
| Agent | AtomicAgent[In, Out] |
LLM-backed transformer from input schema to output schema |
| Config | AgentConfig |
Wires client, model, history, prompt, roles, API params |
| Prompt | SystemPromptGenerator |
Three-section prompt: background, steps, output_instructions |
| History | ChatHistory |
Conversation state, serializable, token-counted |
| Tool | BaseTool[In, Out] |
Deterministic capability the agent can invoke |
| Context | BaseDynamicContextProvider |
Dynamic section injected into the system prompt at runtime |
All communication between these uses BaseIOSchema subclasses with docstring-required descriptions.
Canonical imports
from atomic_agents import (
AtomicAgent, AgentConfig,
BasicChatInputSchema, BasicChatOutputSchema,
BaseIOSchema, BaseTool, BaseToolConfig,
)
from atomic_agents.context import (
ChatHistory, Message,
SystemPromptGenerator, BaseDynamicContextProvider,
)
# Optional: MCP interop
from atomic_agents.connectors.mcp import fetch_mcp_tools, MCPTransportType
Do not use legacy paths like atomic_agents.lib.base.* or atomic_agents.agents.base_agent — those were retired. Import from the top-level package where possible.
Minimum viable agent
import os, instructor, openai
from atomic_agents import AtomicAgent, AgentConfig, BasicChatInputSchema, BasicChatOutputSchema
from atomic_agents.context import ChatHistory
client = instructor.from_openai(openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"]))
agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](
config=AgentConfig(
client=client,
model="gpt-5-mini",
history=ChatHistory(),
)
)
reply = agent.run(BasicChatInputSchema(chat_message="Hello"))
print(reply.chat_message)
AtomicAgent and BaseTool use PEP 695 generics — the type parameters carry runtime information, so write them explicitly and keep them accurate. Full runnable version: atomic-examples/quickstart/quickstart/1_0_basic_chatbot.py.
Targeted creation skills
For the four most common authoring tasks, dedicated atomic skills give a step-by-step workflow (clarify → write → verify → hand off) instead of just reference material. Prefer them when the user is actively building something specific.
| User intent | Atomic skill |
|---|---|
| "create a schema" / "design the input/output schema" | atomic-agents:create-atomic-schema |
"create an agent" / "add another agent" / "wire up an AtomicAgent" |
atomic-agents:create-atomic-agent |
"add a tool" / "wrap an API as a tool" / "build a BaseTool" |
atomic-agents:create-atomic-tool |
| "add a context provider" / "inject X into the prompt" / "wire up RAG" | atomic-agents:create-atomic-context-provider |
These skills auto-trigger on the matching phrasing. The reference files below are what they (and you) load for deeper material.
Decision routing
Pick the reference file that matches the task. Each is loaded only when read.
| Task | Reference |
|---|---|
| Design or validate an input/output schema | references/schemas.md |
| Build, configure, or run an agent | references/agents.md |
| Write a tool the agent will invoke | references/tools.md |
| Inject dynamic data into the system prompt | references/context-providers.md |
| Structure the system prompt | references/prompts.md |
| Coordinate multiple agents | references/orchestration.md |
| Manage conversation state and multi-agent memory | references/memory.md |
| Register telemetry, retries, or logging | references/hooks.md |
| Swap LLM provider or configure roles | references/providers.md |
Decide the project layout or pyproject.toml |
references/project-structure.md |
| Write tests for agents and tools | references/testing.md |
When a concept is unclear, start from the user's verb: create a schema → create-atomic-schema skill, hook up a weather API → create-atomic-tool skill, inject user name into prompt → create-atomic-context-provider skill, route between agents → orchestration reference.
Working style
Follow these defaults unless the project says otherwise. The reference files go deeper on each.
Schemas are the contract. Design the BaseIOSchema pair before writing the agent. Field descriptions flow into the LLM prompt via Instructor, so write them for the model, not just the developer. Every subclass needs a non-empty docstring — the framework enforces this at class-definition time.
System prompts have three sections. Use SystemPromptGenerator(background=..., steps=..., output_instructions=...). Put persona in background, the ordered procedure in steps, and output-format rules in output_instructions. The agent falls back to a sensible default when omitted.
Wrap the provider client with Instructor. Always. instructor.from_openai(...), instructor.from_anthropic(...), instructor.from_genai(...) — without this the agent cannot enforce output schemas.
Use model_api_parameters for provider knobs. temperature, max_tokens, reasoning_effort, etc. live in the model_api_parameters dict on AgentConfig, not on the agent itself.
Errors and retries flow through hooks. Register handlers for parse:error, completion:error, completion:last_attempt rather than wrapping run() in try/except. See references/hooks.md.
Tools return the output schema on success. Failure should surface as validation errors or typed result schemas the caller pattern-matches on — don't raise through run() unless the failure is truly unrecoverable.
When the user is starting from nothing
Scaffolding a brand-new project (fresh directory, pyproject.toml, first agent) is handled by the sibling skill new-app. Suggest it when the user says "new project", "start from scratch", or equivalent.
When the user wants to understand an existing codebase
Delegate to the atomic-explorer subagent when the project has more than a handful of atomic-agents files and the user asks to "explore", "map", "understand how X works", or similar. The subagent reads the relevant files in isolated context and returns a compact architecture map (agents, tools, schemas, context providers, orchestration, essential-reading list). Invoke via the Task tool with the scope (project root, module path, or feature) in the prompt.
For a small project (a single main.py + one or two agents), reading the files directly in the main thread is fine — the isolation upside is thin.
When the user wants a review
Delegate to the atomic-reviewer subagent — do not review in the main thread. The subagent runs in isolated context with read-only tools, keeping the review's file exploration out of the parent conversation. Invoke it via the Task tool with the scope (diff, paths, or module) in the prompt. Review findings return as a single structured report the parent thread can act on.
Versioning and compatibility
- Python 3.12+ (PEP 695 generics are used internally).
- Instructor 1.14+ with provider extras (
instructor[openai],instructor[anthropic], etc.) — the workspace uses Instructor's extras to pull provider SDKs. - Pydantic 2.
- For MCP interop, see
atomic_agents.connectors.mcp—fetch_mcp_tools,MCPFactory,MCPTransportTypeare stable.
Anti-patterns (surface these in review)
- Plain
BaseModelinstead ofBaseIOSchema. - Missing docstrings on
BaseIOSchemasubclasses (framework raises at import). Field(..., description="...")missing — Instructor leans on descriptions for prompt generation.- Raw provider client passed as
AgentConfig.client(must be wrapped in Instructor). Raw SDK use for embeddings, image generation, audio, or moderation is fine — the framework only covers structured chat/completions. - Hardcoded API keys instead of env vars.
- Unbounded
ChatHistoryon long-running sessions. - Blocking I/O inside
BaseDynamicContextProvider.get_info()— it runs on everyagent.run(). - Catching
ValidationErrorto hide schema problems instead of fixing descriptions or constraints. MCPTransportType.STREAMABLE_HTTP— the correct value isHTTP_STREAM.ChatHistory.load(...)called as a classmethod — it is an instance method that mutates self.
For deeper guidance load the relevant reference file above. For code-review runs, delegate to the atomic-reviewer subagent.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。