|
| 1 | +--- |
| 2 | +date: 2025-10-28 |
| 3 | +order: 2 |
| 4 | +subtitle: '' |
| 5 | +title: ADK Basic Setup |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | +Now let’s properly test ADK. |
| 10 | + |
| 11 | +Everything here is tested using the Python SDK. |
| 12 | + |
| 13 | +## Test environment |
| 14 | + |
| 15 | +Here’s what I’m using: |
| 16 | + |
| 17 | +- Python 3.12 |
| 18 | +- uv |
| 19 | +- gpt-5-nano |
| 20 | + |
| 21 | +ADK really shines with Gemini and Vertex AI. However, to compare its strengths and differences with other tools, we’ll use a third-party LLM. |
| 22 | + |
| 23 | +## Environment setup |
| 24 | + |
| 25 | +First, set up uv as follows. If you don’t have pyenv or uv installed, install them first or skip these steps and use your own setup. |
| 26 | + |
| 27 | +```bash |
| 28 | +mkdir adk-test && cd adk-test |
| 29 | +pyenv local 3.12.7 |
| 30 | +uv init |
| 31 | +uv venv |
| 32 | +uv add google-adk |
| 33 | +``` |
| 34 | + |
| 35 | +With the commands above, the environment setup is complete. |
| 36 | + |
| 37 | +## Create an ADK Agent |
| 38 | + |
| 39 | +```bash |
| 40 | +uv run adk create my_agent |
| 41 | +``` |
| 42 | + |
| 43 | +When you run this command, you’ll see options like below. I chose 2. |
| 44 | + |
| 45 | +```bash |
| 46 | +Choose a model for the root agent: |
| 47 | +1. gemini-2.5-flash |
| 48 | +2. Other models (fill later) |
| 49 | +Choose model (1, 2): 2 |
| 50 | +``` |
| 51 | + |
| 52 | +## Configure the LLM model |
| 53 | + |
| 54 | +Now prepare the LLM model. I’ll set this up using pydantic. |
| 55 | + |
| 56 | +```bash |
| 57 | +uv add pydantic-settings |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +```python |
| 63 | +"""pydantic Settings""" |
| 64 | + |
| 65 | +from pydantic_settings import BaseSettings, SettingsConfigDict |
| 66 | + |
| 67 | + |
| 68 | +class Settings(BaseSettings): |
| 69 | + """Settings for the application""" |
| 70 | + |
| 71 | + model_config = SettingsConfigDict(env_file=".env") |
| 72 | + OPENAI_API_KEY: str = "" |
| 73 | + OPENAI_MODEL: str = "gpt-5-nano" |
| 74 | + |
| 75 | +settings = Settings() |
| 76 | +``` |
| 77 | + |
| 78 | +Set it up like above, then provide OPENAI_API_KEY via a .env file or by exporting it, for example: export OPENAI_API_KEY="sk-~~". |
| 79 | + |
| 80 | +Next, set up litellm. With ADK, to use models other than Gemini or Vertex AI, you need to go through the litellm library. This adds an extra dependency and a middle layer, which makes it more complex than a direct integration—likely one downside of ADK. |
| 81 | + |
| 82 | +```bash |
| 83 | +uv add litellm |
| 84 | +``` |
| 85 | + |
| 86 | +After that, configure my_agent/agent.py like this: |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +```python |
| 91 | +"""My Agent""" |
| 92 | + |
| 93 | +from google.adk.agents.llm_agent import Agent |
| 94 | +from google.adk.models.lite_llm import LiteLlm |
| 95 | + |
| 96 | +from settings import settings |
| 97 | + |
| 98 | +root_agent = Agent( |
| 99 | + model=LiteLlm(model=settings.OPENAI_MODEL), |
| 100 | + name="root_agent", |
| 101 | + description="A helpful assistant for user questions.", |
| 102 | + instruction="Answer user questions to the best of your knowledge", |
| 103 | +) |
| 104 | +``` |
| 105 | + |
| 106 | +## Run the Agent |
| 107 | + |
| 108 | +We’ve now set up a very simple Agent. Let’s run it. |
| 109 | + |
| 110 | +```bash |
| 111 | +uv run adk run my_agent |
| 112 | +``` |
| 113 | + |
| 114 | +When you run the command above, you’ll see a [user]: prompt, and it will respond to your input. |
| 115 | + |
| 116 | +```bash |
| 117 | +[user]: hello |
| 118 | +23:24:51 - LiteLLM:INFO: utils.py:3416 - |
| 119 | +LiteLLM completion() model= gpt-5-nano; provider = openai |
| 120 | +[root_agent]: Hello! How can I help today? I can answer questions, explain concepts, help with writing, brainstorm ideas, plan tasks, or provide quick summaries. If you have a topic in mind, tell me and I’ll dive in. |
| 121 | +``` |
| 122 | + |
| 123 | +## Use the web interface |
| 124 | + |
| 125 | +If you want a more distinctive ADK experience, there’s also a way to test via the web. |
| 126 | + |
| 127 | +```bash |
| 128 | +uv run adk web |
| 129 | +``` |
| 130 | + |
| 131 | +Visit http://127.0.0.1:8000/ and you’ll see a screen like this. |
| 132 | + |
| 133 | + |
| 134 | +*ADK web interface initial screen* |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +This is ADK’s built-in web interface, which lets you visually monitor the Agent’s execution. After entering a prompt, you can monitor the run as shown below. |
| 139 | + |
| 140 | + |
| 141 | +*Agent run monitoring screen* |
| 142 | + |
| 143 | +If you have time, I recommend watching the video Introducing Agent Development Kit: https://www.youtube.com/watch?v=zgrOwow_uTQ |
0 commit comments