Atomic Agents(AIエージェント開発の軽量フレームワーク)の Python フレームワークガイド。スキーマ、エージェント、ツール、コンテキストプロバイダー(文脈情報の供給元)、プロンプト、オーケストレーション(複数エージェントの統合制御)、プロバイダー設定などについて説明します。 次のような場合に使用: - コードが `atomic_agents` からインポートしている - `AtomicAgent`、`BaseTool`、または `BaseIOSchema` を定義している - マルチエージェント(複数AIエージェント)のオーケストレーションについてユーザーが質問している - 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 は、型付きで構造化された入出力を備えた LLM(大規模言語モデル)アプリケーションを構築するための軽量な Python フレームワークです。Instructor と Pydantic の上に構築されており、ユーザー、エージェント、ツール、コンテキストの間のすべてのやり取りが検証済みのスキーマになります。
このスキルは Claude にこのフレームワークについて説明し、タスクに応じて焦点を絞ったリファレンスファイルへ案内します。
| 概念 | クラス | 役割 |
|---|---|---|
| スキーマ | BaseIOSchema |
入出力の型付き仕様 — すべてのエージェント/ツール I/O に適用 |
| エージェント | AtomicAgent[In, Out] |
入力スキーマから出力スキーマへ変換する LLM 駆動の処理 |
| 設定 | AgentConfig |
クライアント、モデル、履歴、プロンプト、ロール、API パラメータを設定 |
| プロンプト | SystemPromptGenerator |
3 セクション構成のプロンプト:背景、手順、出力指示 |
| 履歴 | ChatHistory |
会話の状態(保存・復元可能、トークン数も計算) |
| ツール | BaseTool[In, Out] |
エージェントが実行できる確定的な機能 |
| コンテキスト | BaseDynamicContextProvider |
実行時にシステムプロンプトに埋め込まれる動的情報 |
これらすべての通信は BaseIOSchema のサブクラスを使用し、説明用のドキュメント文字列が必須です。
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 などの古いパスは使用しないでください — これらは廃止されています。可能な限りトップレベルのパッケージからインポートしてください。
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-agents:create-atomic-schema |
「エージェントを作成する」「別のエージェントを追加する」「AtomicAgent を組み込む」 |
atomic-agents:create-atomic-agent |
「ツールを追加する」「API をツールとしてラップする」「BaseTool を構築する」 |
atomic-agents:create-atomic-tool |
| 「コンテキストプロバイダを追加する」「X をプロンプトに埋め込む」「RAG を組み込む」 | atomic-agents:create-atomic-context-provider |
| 「エージェントが動作しない / クラッシュしている / おかしな出力をしている」+トレースバックやエラー | atomic-agents:troubleshoot |
これらのスキルは該当するフレーズで自動的に起動します。下記のリファレンスファイルは、これらのスキル(およびあなた)がより深い内容を必要とするときに読み込みます。
タスクに合ったリファレンスファイルを選んでください。各ファイルは読まれる時だけ読み込まれます。
| タスク | リファレンス |
|---|---|
| 入出力スキーマを設計または検証する | references/schemas.md |
| エージェントを構築、設定、または実行する | references/agents.md |
| エージェントが実行するツールを作成する | references/tools.md |
| 動的データをシステムプロンプトに埋め込む | references/context-providers.md |
| システムプロンプトを構造化する | references/prompts.md |
| 複数のエージェント間の連携を調整する | references/orchestration.md |
| 会話の状態と複数エージェント間のメモリを管理する | references/memory.md |
| テレメトリ(利用状況の監視)、リトライ、ログを登録する | references/hooks.md |
| LLM プロバイダを切り替えるまたはロールを設定する | references/providers.md |
プロジェクトレイアウトまたは pyproject.toml を決定する |
references/project-structure.md |
| エージェントとツールのテストを作成する | references/testing.md |
概念が不明な場合は、ユーザーの動詞から始めてください:スキーマを作成 → create-atomic-schema スキル、天気 API を組み込む → create-atomic-tool スキル、ユーザー名をプロンプトに埋め込む → create-atomic-context-provider スキル、エージェント間でルーティングする → オーケストレーション(複数エージェント間の連携)リファレンス。
プロジェクト内に別途指定がない限り、これらのデフォルトに従ってください。リファレンスファイルで詳しく説明しています。
スキーマが契約です。 エージェントを記述する前に BaseIOSchema ペアを設計してください。フィールドの説明は Instructor を経由して LLM プロンプトに流れ込むため、開発者のためではなくモデル向けに記述してください。すべてのサブクラスには空でないドキュメント文字列が必要です — フレームワークはクラス定義時にこれを強制します。
システムプロンプトは 3 セクション構成です。 SystemPromptGenerator(background=..., steps=..., output_instructions=...) を使用してください。ペルソナ(会話キャラクター)を background に、順序付きの手順を steps に、出力形式ルールを output_instructions に置きます。省略時はエージェントが妥当なデフォルトにフォールバックします。
プロバイダクライアントを Instructor でラップしてください。 必ず。instructor.from_openai(...)、instructor.from_anthropic(...)、instructor.from_genai(...) — これなしではエージェントが出力スキーマを強制できません。
プロバイダの設定には model_api_parameters を使用してください。 temperature、max_tokens、reasoning_effort などは AgentConfig の model_api_parameters 辞書に配置します。エージェント自体には置きません。
エラーとリトライはフック経由で処理してください。 run() を try/except でラップするのではなく、parse:error、completion:error、completion:last_attempt のハンドラを登録してください。references/hooks.md を参照。
ツールは成功時に出力スキーマを返します。 失敗は検証エラーまたは呼び出し元がパターンマッチング(型による条件分岐)できる型付きの結果スキーマとして表示する — 失敗が本当に回復不可能でない限り run() からは例外を発生させないでください。
新規プロジェクトのスキャフォルディング(新しいディレクトリ、pyproject.toml、最初のエージェント)は兄弟スキル new-app が担当します。ユーザーが「新しいプロジェクト」「ゼロから始める」などと言ったときは、このスキルを提案してください。
プロジェクトに複数の Atomic Agents ファイルがあり、ユーザーが「探索する」「マッピング」「X がどのように動作するかを理解する」などと言った場合は、atomic-explorer サブエージェント(下位のエージェント)に委譲してください。サブエージェントは関連ファイルを独立したコンテキストで読み込み、コンパクトなアーキテクチャマップ(エージェント、ツール、スキーマ、コンテキストプロバイダ、オーケストレーション、必読ファイルリスト)を返します。Task ツールで、スコープ(プロジェクトルート、モジュールパス、機能)をプロンプトに指定して実行してください。
小規模プロジェクト(単一の main.py + 1、2 個のエージェント)の場合は、メインスレッドで直接ファイルを読む方が問題ありません — 独立実行のメリットが薄いためです。
具体的なエラー、トレースバック、または間違った出力レポートは troubleshoot スキルへルーティングしてください — このスキルはフレームワークの実際のエラーメッセージをキーにした症状表、およびプロバイダごとの障害パターンを含みます。レビューは現在動作していないコードのためです。トラブルシューティングはコードが現在燃えているときのためです。
atomic-reviewer サブエージェントに委譲してください — メインスレッドでレビューしないでください。サブエージェントは読み取り専用ツール付きの独立コンテキストで実行され、レビューのファイル探索を親スレッドから分離します。Task ツールで、スコープ(差分、パス、モジュール)をプロンプトに指定して実行してください。レビュー結果は、親スレッドが対応できる単一の構造化レポートとして返されます。
instructor[openai]、instructor[anthropic] など)— ワークスペースは Instructor のエクストラを使用してプロバイダ SDK をインストールatomic_agents.connectors.mcp を参照 — fetch_mcp_tools、MCPFactory、MCPTransportType は安定版BaseIOSchema を使わず BaseModel を直接使用BaseIOSchema サブクラスのドキュメント文字列が欠落(フレームワークはインポート時に検出)Field(..., description="...") の説明が欠落 — Instructor はプロンプト生成時に説明に依存AgentConfig.client として渡す(生の SDK をエンベディング、画像生成、オーディオ、モデレーション用に使用するのは問題ありません — フレームワークは構造化チャット/完成度のみカバー)ChatHistoryBaseDynamicContextProvider.get_info() 内の同期 I/O(ブロッキング動作) — agent.run() 呼び出しのたびに実行されますValidationError をキャッチする(代わりに説明と制約を修正)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.
| 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.
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.
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.
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 |
| "my agent is broken / crashing / returning garbage" + a traceback or error | atomic-agents:troubleshoot |
These skills auto-trigger on the matching phrasing. The reference files below are what they (and you) load for deeper material.
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.
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.
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.
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.
A concrete error, traceback, or wrong-output report routes to the troubleshoot skill — it carries a symptom table keyed on the framework's real error messages plus the per-provider failure modes. Review is for code that isn't currently on fire; troubleshoot is for code that is.
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.
instructor[openai], instructor[anthropic], etc.) — the workspace uses Instructor's extras to pull provider SDKs.atomic_agents.connectors.mcp — fetch_mcp_tools, MCPFactory, MCPTransportType are stable.BaseModel instead of BaseIOSchema.BaseIOSchema subclasses (framework raises at import).Field(..., description="...") missing — Instructor leans on descriptions for prompt generation.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.ChatHistory on long-running sessions.BaseDynamicContextProvider.get_info() — it runs on every agent.run().ValidationError to hide schema problems instead of fixing descriptions or constraints.MCPTransportType.STREAMABLE_HTTP — the correct value is HTTP_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 による自動翻訳です。