STELLAR CHART (星海図へ戻る)
Voyage ID: post-28
GENAI-FOUNDATIONS✦ DRAFT (下書き)Difficulty: Level 2

Agent Development Kit (ADK) とは

Reading: 15 min

Agent Development Kit (ADK) とは

Agent Development Kit (ADK) とは、AIエージェントの開発とデプロイのための柔軟でモジュール化されたフレームワークです。ADKは、一般的なLLM(大規模言語モデル)やオープンソースの生成AIツールと連携して使用でき、GoogleのエコシステムとGeminiモデルとの緊密な統合に重点を置いて設計されています。ADKを使うことで、GeminiモデルやGoogle AIツールを活用したシンプルなエージェントを簡単に始められる一方、より複雑なエージェントアーキテクチャやオーケストレーションに必要な制御と構造も提供します。

利用するには... **pip install google-sdk**

Let's get started !

Quick Start(what u can)

lets deep dive into official documents, modify it.

Configuration & Environments

Using GCP for Environment.

Config on terminal

pip install google-sdk #for install adk library
pip show google-sdk # (optional)for check installation

understanding contents in agent.py

import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent

def get_weather(city : str) -> dict:
    """Retrieves the current weather report for a specified city.

    Args:
        city (str): The name of the city for which to retrieve the weather report.

    Returns:
        dict: status and result or error msg.
    """
    if city.lower() == "dublin":
        return {
            "status" : "sccess",
            "report" : (
                "The weather in Dublin is cloudy with a temperature of 8 degrees"
                " Celsius (47 degrees Fahrenheit)." 
            ),
        }
    else:
        return {
            "status" : "error",
            "error_message" : f"Weather information for '{city}' is not available."
        }


def get_current_time(city : str) -> dict:
    """Returns the current time in a specified city.

    Args:
        city (str): The name of the city for which to retrieve the current time.

    Returns:
        dict: status and result or error msg.
    """
    if city.lower() == "dublin":
        tz_identifier = "Europe/Dublin" #https://gist.github.com/Soheab/3bec6dd6c1e90962ef46b8545823820d#etc
    else:
        return {
            "status": "error",
            "error_message" : (
                f"Sorry, I don't have timezone information for {city}."
            )
        }
    tz = ZoneInfo(tz_identifier)
    now = datetime.datetime.now(tz)
    report = (
        f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
    )
    return {"status": "success", "report": report}

root_agent = Agent(
    name = "weather_time_agent",
    model = "gemini-2.0-flash",
    description = (
        "Agent to answer questions about the. time and weather in a city."
    ),
    instruction = (
        "You are a helpful agent who can answer user questions about time and weather in a city."
    ),
    tools = [get_weather, get_current_time]
)

name (Required): Every agent needs a unique string identifier. This name is crucial for internal operations, especially in multi-agent systems where agents need to refer to or delegate tasks to each other. Choose a descriptive name that reflects the agent's function (e.g., customer_support_routerbilling_inquiry_agent). Avoid reserved names like user.

description (Optional, Recommended for Multi-Agent): Provide a concise summary of the agent's capabilities. This description is primarily used by other LLM agents to determine if they should route a task to this agent. Make it specific enough to differentiate it from peers (e.g., "Handles inquiries about current billing statements," not just "Billing agent").

model (Required): Specify the underlying LLM that will power this agent's reasoning. This is a string identifier like "gemini-2.0-flash". The choice of model impacts the agent's capabilities, cost, and performance. See the Models page for available options and considerations.

### Guiding the Agent: Instructions (instruction)¶ The `instruction` parameter is arguably the most critical for shaping an `LlmAgent`'s behavior. It's a string (or a function returning a string) that tells the agent: - - Its core task or goal. - - Its personality or persona (e.g., "You are a helpful assistant," "You are a witty pirate"). - - Constraints on its behavior (e.g., "Only answer questions about X," "Never reveal Y"). - - How and when to use its `tools`. You should explain the purpose of each tool and the circumstances under which it should be called, supplementing any descriptions within the tool itself. - - The desired format for its output (e.g., "Respond in JSON," "Provide a bulleted list"). **Tips for Effective Instructions:** - - **Be Clear and Specific:** Avoid ambiguity. Clearly state the desired actions and outcomes. - - **Use Markdown:** Improve readability for complex instructions using headings, lists, etc. - - **Provide Examples (Few-Shot):** For complex tasks or specific output formats, include examples directly in the instruction. - - **Guide Tool Use:** Don't just list tools; explain *when* and *why* the agent should use them.
### Equipping the Agent: Tools (tools)¶ Tools give your `LlmAgent` capabilities beyond the LLM's built-in knowledge or reasoning. They allow the agent to interact with the outside world, perform calculations, fetch real-time data, or execute specific actions. - - **`tools` (Optional):** Provide a list of tools the agent can use. Each item in the list can be: * A Python function (automatically wrapped as a `FunctionTool`). * An instance of a class inheriting from `BaseTool`. * An instance of another agent (`AgentTool`, enabling agent-to-agent delegation - see [Multi-Agents](https://google.github.io/adk-docs/agents/multi-agents/)). The LLM uses the function/tool names, descriptions (from docstrings or the `description`field), and parameter schemas to decide which tool to call based on the conversation and its instructions.
🐾
NAVIGATOR AI TOOLKIT

マンチカン航海士の知恵袋

マンチカン航海士が記事全文を読んでいるニャ... 🐾