
ai playground
使用 Google ADK 构建 AI 代理的初学者指南。
Repository Info
About This Server
使用 Google ADK 构建 AI 代理的初学者指南。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
概要
- 初心者が
Google ADKを使って AI エージェント構築をする記事ですADK:google が開発した AI エージェントフレームワーク- 参考:Qiita | 🤖 Google Agent Development Kit (ADK) 入門ガイド
- 本記事では、ブラウザ上でエージェントと対話し、以下ができるところまでやります - 入力->エージェント A->スクリプト i->エージェント B->出力 !Drawing 2025-04-20 01.22.59.excalidraw.png
環境構築
1. Ollama を手にいれよう!
- Ollama は、ローカル LLM を簡単に動かせるアプリ!
- Ollama | Downloadからインストール
- モデルをダウンロードしてみよう
ollama pull gemma3
ollama pull mistral-small3.1
- 本記事で使うのは、基本的に上記2モデルです
- 興味がある人は、Ollama | Modelsから好きなモデルを選んで動かしてみてください
2. AI を走らせてみよう
ollama run gemma3
- ターミナル上で会話が始まるぞ!
!スクリーンショット 2025-04-19 202510.png
3. python 環境をセットアップしよう
- Installing uvを参考に
uvをインストールuvは、Python バージョン管理ツール
- python をインストール
uv install python
参考: Python Coding Best Practice
4. ライブラリをインストールしよう
uv pip install google-adk litellm
google-adk:- google が開発した AI エージェントフレームワーク!
litellm:- LLM の API インターフェース!
エージェントを構築しよう
- ここからコードを書くよ!
1. 簡単な対話エージェントを構築してみよう
ディレクトリ構成
.
├── chat_agent
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-313.pyc
│ │ └── agent.cpython-313.pyc
│ └── agent.py
├── .env
├── pyproject.toml
└── uv.lock
コード
# おまじない
from . import agent
# 環境変数をフレームワークが読みに行って、やり取りしてくれる
OPENAI_API_BASE=http://localhost:11434/v1
OPENAI_API_KEY=anything
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
root_agent = LlmAgent(
model=LiteLlm(model="ollama_chat/gemma3"),
name="chat_agent",
description=(
"chat agent that can chat with users and answer questions."
),
instruction="""
You are a chat agent that can answer questions and have conversations
with users. You can also perform calculations and provide information
about various topics.
""",
)
- コードが書けたら、
uv run adk webでサーバが立ちあがる! localhost:8000(デフォルト)にブラウザからアクセスすると、エージェントがいるはず!とりあえず動きました!🎉 !スクリーンショット 2025-04-19 203024.png
2. AI に python スクリプトを実行してもらおう
toolsとして、AI に python スクリプトを渡しますtoolの説明は丁寧に書こう!I/O の形式まで書けると Good- 参考:Agent Development Kit | Function tools
ディレクトリ構成
.
├── die_agent
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-313.pyc
│ │ └── agent.cpython-313.pyc
│ ├── .env
│ ├── agent.py
│ └── tools # 新しいやつ!
│ └── roll_die.py
├── pyproject.toml
└── uv.lock
コード
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from pydantic import BaseModel, Field
from die_agent.tools.roll_die import roll_die
root_agent = LlmAgent(
model=LiteLlm(model="ollama_chat/mistral-small3.1"),
name="dir_agent",
description=("Agent that can roll a die."),
instruction=("You can ask user to roll a die."),
tools=[
roll_die,
],
)
import random
def roll_die():
"""
Roll an 6-sided die and return the result.
Args:
None
Returns:
dict: {"result": int, "status": str}
"""
return {
"result": random.randint(1, 6),
"status": "success",
}
- コードが書けたら、
uv run adk webをして、localhost:8000にアクセス!動きましたか? !スクリーンショット 2025-04-19 234336.png
3. マルチエージェントにしてみよう
- いよいよマルチエージェント!エージェント A のダイスの結果を使って、エージェント B におみくじをひいてもらいます
- 増える概念:
output_key:各エージェントの出力は、context にキーバリューで保存されます。その key を指定するSequential agents:サブエージェントに登録したエージェントを、順番に呼び出してくれる
- 注釈:
- うちの PC が悲鳴をあげたので、この項ではモデルを gemini にしました
- gemini を使う場合、
.envには以下が必要。AI Studioで無料発行できますGOOGLE_API_KEY="XXX"
- 参考:Agent Development Kit | Sequential agents
ディレクトリ構成
.
├── README.md
├── omikuji_agent
│ ├── __init__.py
│ ├── agent.py
│ ├── agents
│ │ ├── die_agent.py
│ │ └── omikuji_agent.py
│ └── tools
│ ├── omikuji.py
│ └── roll_die.py
├── .env
├── pyproject.toml
└── uv.lock
コード
from google.adk.agents.sequential_agent import SequentialAgent
from google.adk.agents import LlmAgent
from omikuji_agent.agents.die_agent import die_agent
from omikuji_agent.agents.omikuji_agent import omikuji_agent
root_agent = SequentialAgent(
name="CodePipelineAgent",
sub_agents=[die_agent, omikuji_agent],
)
from google.adk.agents import LlmAgent
from omikuji_agent.tools.roll_die import roll_die
die_agent = LlmAgent(
model="gemini-2.0-flash",
name="die_agent",
description=("Agent that can roll a die."),
instruction=("You can ask user to roll a die."),
tools=[
roll_die,
],
output_key="die_result",
)
from google.adk.agents import LlmAgent
from omikuji_agent.tools.omikuji import omikuji
omikuji_agent = LlmAgent(
# model=LiteLlm(model="ollama_chat/mistral-small3.1"),
model="gemini-2.0-flash",
name="omikuji_agent",
description=("Agent that can give a omikuji result. "),
instruction=(
"""
You can draw an omikuji.
Take the number proveded in the session state key 'die_result' as a parameter.
"""
),
tools=[
omikuji,
],
)
import random
def roll_die():
"""
Roll an 6-sided die and return the result.
Args:
None
Returns:
dict: {"result": int, "status": str}
"""
return {
"result": random.randint(1, 6),
"status": "success",
}
def omikuji(id: int):
"""
Returns a omikuji result based on the given id. id is 1-based. If id is out of range, return error.
Args:
id (int): The id of the fortune result.
Returns:
dict: {"result": str, "status": str, "input": dict}
"""
fortunes = [
"大吉",
"中吉",
"小吉",
"吉",
"凶",
"大凶",
]
if id < 0 or id > len(fortunes):
return {"result": "Invalid fortune id.", "status": "error", "input": {"id": id}}
id -= 1
return {
"result": fortunes[id],
"input": {"id": id},
"status": "success",
}
- コードが書けたら、
uv run adk webをして、localhost:8000にアクセス!動いたら OK! !スクリーンショット 2025-04-20 003927.png
まとめ
- 短いコードでエーアイが動いて嬉しい!
- 次は MCP サーバとかで色々動かす記事を書こうと思う
- 不足や誤りを発見しましたら、ご指摘いただけると助かります。
Quick Start
Clone the repository
git clone https://github.com/oda251/ai-playgroundInstall dependencies
cd ai-playground
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.