빠른 시작: 에이전트 개발 키트로 에이전트 빌드

이 빠른 시작에서는 Google Cloud 프로젝트 설정, 에이전트 개발 키트 (ADK) 설치, 기본 에이전트 설정, 개발자 사용자 인터페이스 실행을 안내합니다.

이 빠른 시작에서는 Python 3.10 이상 및 터미널 액세스가 있는 로컬 IDE (VS Code, PyCharm 등)를 사용하고 있다고 가정합니다. 에이전트는 로컬 애플리케이션 개발에 권장되는 머신에서 완전히 실행됩니다.

시작하기 전에

다음 단계를 완료합니다.

Google Cloud 프로젝트 설정

Google Cloud 프로젝트를 설정하고 Vertex AI API를 사용 설정합니다.

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. 사용자 인증 정보를 설정합니다.

    로컬 터미널에서 Google Cloud CLI를 설정하고 인증합니다. Google AI Studio의 Gemini API에 익숙한 경우 Vertex AI의 Gemini API는 API 키 대신 ID 및 액세스 관리를 사용하여 액세스를 관리한다는 점에 유의하세요.

    1. Google Cloud CLI를 설치하고 초기화합니다.

    2. 이전에 gcloud CLI를 설치한 경우 이 명령어를 실행하여 gcloud 구성요소가 업데이트되었는지 확인합니다.

      gcloud components update
    3. 다음 명령어를 실행하여 로컬 애플리케이션 기본 사용자 인증 정보 (ADC) 파일을 생성합니다. 에이전트는 로컬 애플리케이션 개발 중에 이러한 사용자 인증 정보를 사용하여 Vertex AI에 액세스합니다.

      gcloud auth application-default login

      자세한 내용은 애플리케이션 기본 사용자 인증 정보 설정을 참고하세요.

    가상 환경 설정 및 ADK 설치

    • 가상 환경을 만들고 활성화합니다 (권장).

      # Create
      python -m venv .venv
      # Activate (uncomment the line relevant to your environment)
      # macOS/Linux: source .venv/bin/activate
      # Windows CMD: .venv\Scripts\activate.bat
      # Windows PowerShell: .venv\Scripts\Activate.ps1
      
    • ADK를 설치합니다.

      pip install google-adk
      

    에이전트 만들기

    터미널을 사용하여 폴더 구조를 만듭니다.

    mkdir multi_tool_agent/
    touch \
    multi_tool_agent/__init__.py \
    multi_tool_agent/agent.py \
    multi_tool_agent/.env
    

    구조:

    parent_folder/
        multi_tool_agent/
            __init__.py
            agent.py
            .env
    

    다음 코드를 복사하여 만든 다음 세 파일에 붙여넣습니다.

    • \_\_init\_\_.py

      from . import agent
      
    • .env

      # If using Gemini via Vertex AI on Google CLoud
      GOOGLE_CLOUD_PROJECT="your-project-id"
      GOOGLE_CLOUD_LOCATION="your-location" #e.g. us-central1
      GOOGLE_GENAI_USE_VERTEXAI="True"
      
    • agent.py

      from google.adk.agents import Agent
      
      def get_weather(city: str) -> dict:
          """Retrieves the current weather report for a specified city.
      
          Returns:
              dict: A dictionary containing the weather information with a 'status' key ('success' or 'error') and a 'report' key with the weather details if successful, or an 'error_message' if an error occurred.
          """
          if city.lower() == "new york":
              return {"status": "success",
                      "report": "The weather in New York is sunny with a temperature of 25 degrees Celsius (77 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:
              dict: A dictionary containing the current time for a specified city information with a 'status' key ('success' or 'error') and a 'report' key with the current time details in a city if successful, or an 'error_message' if an error occurred.
          """
          import datetime
          from zoneinfo import ZoneInfo
      
          if city.lower() == "new york":
              tz_identifier = "America/New_York"
          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)
          return {"status": "success",
                  "report": f"""The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}"""}
      
      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="I can answer your questions about the time and weather in a city.",
          tools=[get_weather, get_current_time]
      )
      

    에이전트에는 모의 구현이 포함된 두 가지 함수 도구가 있습니다.

    에이전트 실행 및 테스트

    1. 터미널에서 상담사의 상위 디렉터리로 이동합니다 (예: cd .. 사용).

      parent_folder/      <-- navigate to this directory
          multi_tool_agent/
              __init__.py
              agent.py
              .env
      
    2. 다음 명령어를 실행하여 개발자 웹 UI를 실행합니다.

      adk web
      

      브라우저에서 제공된 URL (일반적으로 http://localhost:8000 또는 http://127.0.0.1:8000)을 엽니다. 이 연결은 로컬 머신에만 유지됩니다. multi_tool_agent를 선택하고 상담사와 상호작용합니다.

    사용해 볼 만한 프롬프트 예시

    다음과 같은 프롬프트를 사용해 볼 수 있습니다.

    • 뉴욕 날씨는 어때?
    • 뉴욕은 지금 몇 시야?
    • 파리 날씨는 어때?
    • 파리는 지금 몇 시야?

    다음 단계