AIインフォグラフィックス集

AI Infographics Collection

AIエージェントの3層アーキテクチャ図解

AIエージェントの3層アーキテクチャ図解

Perception / Reasoning / Action を直感的に理解

2025年4月29日

全体像
見かた
Perception で "理解できる形式" に変換 → Reasoning で計画 → Action で外部ツールを叩く。
1 ループ完了ごとに必要なら再度 Perception に戻り、連続タスクをこなします。
👁️

1. Perception入力層

項目 役割 代表ライブラリ
プリプロセッサ 文書クレンジング・正規化 langchain.text_splitter
Tokenizer / Embedder テキスト → トークン or ベクトル OpenAI Embeddings, SentenceTransformers
メモリ/コンテキスト 過去会話・RAG ドキュメント保持 langchain.memory, pgvector
ポイント
  • ゴミ入力はゴミ出力(GIGO)。正規化&RAG で情報を"整えて"渡すとハルシネ減。
  • ベクトル検索の k は 3〜5 件がベター:多すぎると推論が散漫に。
🧠

2. Reasoning推論層

コンポーネント 役割
LLM 意味理解・推論・生成
Planner どのツールをどう順番で使うか決定
メモリ / CoT 中間思考を外に出して一貫性を担保
LangChain 例
from langchain.agents import initialize_agent, Tool
agent = initialize_agent([search_tool, calc_tool], llm,
                       agent_type="chat-zero-shot-react-description")
agent("来週の東京の天気と平均気温を教えて")
ポイント
  • Chain-of-Thought を有効に → "Step-by-step" 指示で精度向上。
  • Planner ≠ LLM 本体 に分けるとルールベースの条件分岐も簡単。
🚀

3. Action実行層

ツール種別 ライブラリ
API 呼び出し Salesforce / Slack / Weather requests, langchain.tools.APITool
DB / VectorStore Postgres / Redis psycopg2, redis-py
外部プログラム Python 関数・Shell Cmd subprocess, LangChain PythonREPL
RPA UIPath / Playwright 操作 UIPath SDK, Playwright Python
ポイント
  • idempotent(再実行安全) なツール設計に。
  • ツール実行ログは 監査ログ として永続化 → ガバナンス対応可。
4. 最小構成で動かすレシピ
from langchain import OpenAI
from langchain.memory import ConversationBufferMemory
from langchain.agents import initialize_agent, Tool

memory = ConversationBufferMemory()
tools  = [search_tool, email_draft_tool]

llm    = OpenAI(temperature=0)
agent  = initialize_agent(tools, llm, memory=memory,
                          agent_type="chat-zero-shot-react-description")

agent("顧客ID 512 の質問に回答メールを作って")
  1. Perception: search_tool が社内 KB ベクトル検索
  2. Reasoning: "検索→要約→メールテンプレ" と計画
  3. Action: email_draft_tool が下書きを作成 → 人間が承認
5. よくある質問
どこまで自律させる? まずは "提案 → 人が承認" の半自動。KPI 安定後に自動実行域を拡大。
複数エージェントの利点? 役割分担で責務を明確化(例:Planner / Critic / Executor)。故障点を局所化できる。
安全対策は? ガードレール層で RateLimit・ContentFilter・Auth。全アクションを監査ログへ。
6. まとめ
  • Perception="取り込み整える"、Reasoning="考える/計画"、Action="動く"
  • まずは 小スコープ で 1 ループを実装し、ガードレール+評価指標を整備
  • 成熟したら マルチエージェント化・自動改善 を段階的に導入しよう