【MCP】AutoGenで作る自律型LLMアシスタント:MCP連携で3つの外部サービスを自動操作 2025/10/8

エージェント

🚀 目標

ユーザーが

「来週の打ち合わせデータをまとめて」
と言うと、AutoGenの3エージェントが次のように動きます👇

👩‍💼 User
   ↓
🤖 CalendarAgent → Googleカレンダーで予定取得
🤖 DBAgent → 社内DBから会議関連データ取得
🤖 NotionAgent → Notionページにまとめ投稿

🧠 システム構成イメージ

+-------------------------------+
|         AutoGen Core          |
|     (LLM Orchestrator)        |
+-------------------------------+
     |       |         |
     ↓       ↓         ↓
CalendarAgent  DBAgent  NotionAgent
  |(Google)     |(DB)     |(Notion)
  ↓              ↓          ↓
Google Calendar  社内DB     Notion

💻 実装例(Python)

from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager

# --- 各エージェント定義 ---
calendar_agent = AssistantAgent(
    name="CalendarAgent",
    system_message="You are in charge of Google Calendar operations.",
)

db_agent = AssistantAgent(
    name="DBAgent",
    system_message="You are in charge of retrieving related data from the internal DB.",
)

notion_agent = AssistantAgent(
    name="NotionAgent",
    system_message="You are responsible for writing the result to Notion.",
)

user_proxy = UserProxyAgent(name="User")

# --- グループチャット設定 ---
groupchat = GroupChat(
    agents=[user_proxy, calendar_agent, db_agent, notion_agent],
    messages=[],
    max_round=6,
)

manager = GroupChatManager(groupchat=groupchat)

# --- シミュレーション開始 ---
user_proxy.initiate_chat(
    manager,
    message="来週の打ち合わせデータをまとめて",
)

🪄 どう動くか(簡単な流れ)

ステップ担当エージェント内容
User「来週の打ち合わせデータをまとめて」と指示
CalendarAgentGoogle Calendar MCPを呼び、予定一覧を取得
DBAgent会議名をキーに社内DBから関連データを検索
NotionAgent結果をNotionのMCPに送ってページ作成
Manager各エージェントの出力を整理してユーザーに報告

🧩 MCPサーバー接続イメージ(擬似コード)

各エージェントの中で、実際にはこんな形でMCPを呼びます👇

from mcp import Client

# CalendarAgent 内部で
calendar = Client("mcp://google-calendar")
events = calendar.call("get_events", {"time_range": "next_week"})

# DBAgent 内部で
db = Client("mcp://internal-db")
records = db.call("search_meeting_data", {"keyword": "design review"})

# NotionAgent 内部で
notion = Client("mcp://notion")
notion.call("create_page", {"title": "Meeting Summary", "content": str(records)})

💬 実行結果の例

👤 User: 来週の打ち合わせデータをまとめて
🤖 CalendarAgent: Googleカレンダーから3件の予定を取得しました。
🤖 DBAgent: それぞれの会議について関連資料を社内DBから取得しました。
🤖 NotionAgent: Notionに「来週の打ち合わせまとめ」を作成しました。
✅ 完了しました! → https://notion.so/meeting-summary-2025

🧭 解説(初心者向け)

用語意味
AutoGenMicrosoft開発のマルチエージェント実行フレームワーク
AssistantAgent各タスクを担当するAIエージェント(専門家)
GroupChatManager複数のエージェントが対話で協力する調整役
MCP“Model Context Protocol” — LLMが外部ツールを呼ぶ共通規格
MCPサーバーGoogleカレンダーやNotionなどを橋渡しする中継サーバー

🧭 応用ヒント

  • candidate_func を使えば、どのエージェントが次に発言すべきか自動で選べます。
  • n8nDify と組み合わせれば、Slack通知や定期実行も可能です。
  • FastAPIStreamlit と組み合わせると、Web UIで操作可能に。

コメント

タイトルとURLをコピーしました