에이전트 개발 키트를 사용하여 Agent Runtime에서 에이전트 개발 및 배포

에이전트 런타임을 사용하면 에이전트 개발 키트 (ADK)로 개발된 에이전트를 호스팅할 수 있습니다. 이 문서에서는 ADK를 사용하여 에이전트를 만들고, 배포하고, 테스트하는 방법을 설명합니다.

이 빠른 시작에서는 다음 단계를 안내합니다.

  • Google Cloud 프로젝트를 설정합니다.
  • Python용 Agent Platform SDK 및 ADK를 설치합니다.
  • 환전 에이전트를 개발해 줘.
  • 에이전트를 Agent Runtime에 배포합니다.
  • 배포된 에이전트를 테스트합니다.

다음 대체 ADK 빠른 시작을 사용할 수도 있습니다.

  • ADK 빠른 시작: ADK 빠른 시작은 전적으로 사용자 머신에서 실행되며 로컬 IDE와 터미널 액세스를 사용한다고 가정합니다.
  • 에이전트 스타터 팩: Agent Platform을 위해 빌드된 프로덕션에 즉시 사용 가능한 생성형 AI 에이전트 템플릿 모음입니다.

에이전트 개발 키트가 아닌 지원되는 프레임워크를 사용하는 빠른 시작은 Agent Runtime에서 에이전트 개발 및 배포를 참고하세요.

시작하기 전에

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Agent Platform and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

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

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Agent Platform and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

Agent Runtime을 사용하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.

역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

Python용 Agent Platform SDK 설치 및 초기화

  1. 다음 명령어를 실행하여 Agent Platform SDK for Python 및 기타 필수 패키지를 설치합니다.

    pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,adk]>=1.112
  2. 사용자로 인증

    로컬 셸

    다음 명령어를 실행합니다.

    gcloud auth application-default login

    Colab

    다음 코드를 실행합니다.

    from google.colab import auth
    
    auth.authenticate_user(project_id="PROJECT_ID")
    

    Cloud Shell

    어떤 조치도 필요하지 않습니다.

  3. 다음 코드를 실행하여 Agent Platform을 가져오고 SDK를 초기화합니다.

    Google Cloud 프로젝트

    import vertexai
    
    client = vertexai.Client(
        project="PROJECT_ID",               # Your project ID.
        location="LOCATION",                # Your cloud region.
    )
    

    각 항목의 의미는 다음과 같습니다.

    • PROJECT_ID는 에이전트를 개발하고 배포하는 데 사용되는 Google Cloud 프로젝트 ID입니다.

    • LOCATION: 지원되는 리전 중 하나입니다.

에이전트 개발

  1. 에이전트를 위한 환율 도구를 개발합니다.

    def get_exchange_rate(
        currency_from: str = "USD",
        currency_to: str = "EUR",
        currency_date: str = "latest",
    ):
        """Retrieves the exchange rate between two currencies on a specified date."""
        import requests
    
        response = requests.get(
            f"https://api.frankfurter.app/{currency_date}",
            params={"from": currency_from, "to": currency_to},
        )
        return response.json()
    
  2. 에이전트를 인스턴스화합니다.

    from google.adk.agents import Agent
    from vertexai import agent_engines
    
    agent = Agent(
        model="gemini-2.0-flash",
        name='currency_exchange_agent',
        tools=[get_exchange_rate],
    )
    
    app = agent_engines.AdkApp(agent=agent)
    
  3. 로컬에서 에이전트를 테스트합니다.

    async for event in app.async_stream_query(
        user_id="USER_ID",
        message="What is the exchange rate from US dollars to SEK today?",
    ):
        print(event)
    

    여기서 USER_ID는 사용자 정의 ID이며 128자(영문 기준)로 제한됩니다.

에이전트 배포

Agent Platform에서 reasoningEngine 리소스를 만들어 에이전트를 배포합니다.

remote_agent = client.agent_engines.create(
    agent=app,
    config={
        "requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
        "staging_bucket": "STAGING_BUCKET",
        "identity_type": types.IdentityType.AGENT_IDENTITY,
    }
)

여기서 STAGING_BUCKETgs://이 접두사로 붙은 Cloud Storage 버킷입니다.

에이전트 사용

쿼리를 전송하여 배포된 에이전트를 테스트합니다.

async for event in remote_agent.async_stream_query(
    user_id="USER_ID",
    message="What is the exchange rate from US dollars to SEK today?",
):
    print(event)

삭제

이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.

remote_agent.delete(force=True)

다음 단계

가이드

Agent Platform 런타임을 사용하도록 환경을 설정합니다.

가이드

개발 요구사항에 따라 Agent Platform 런타임에 에이전트를 배포하는 다섯 가지 방법을 알아봅니다.

가이드

Agent Platform 관리형 런타임에 배포된 에이전트를 관리하는 방법을 알아봅니다.

가이드

Agent Platform 런타임으로 에이전트를 사용합니다.

리소스

Google Agent Platform 리소스 및 지원을 확인하세요.