에이전트와 상호작용

이 가이드에서는 Interactions API 를 사용하여 Agent Platform의 관리형 에이전트 API에서 배포된 에이전트와 상호작용하는 방법을 설명합니다. Agents API 및 기본 제공 Antigravity 기본 에이전트를 사용하여 빌드된 커스텀 에이전트와 상호작용하는 방법(동적으로 구성 포함)을 알아봅니다. 또한 상호작용 중에 환경 ID (env_id)를 사용하여 샌드박스 환경을 관리하고 재사용하는 방법과 모델 컨텍스트 프로토콜 (MCP) 서버와 같은 구성을 동적으로 재정의하는 방법을 설명합니다.

API에 대한 자세한 내용은 Interaction API 참조 문서를 확인하세요.

시작하기 전에

에이전트와의 상호작용을 시작하기 전에 환경을 설정합니다.

  1. 계정에 로그인합니다. Google Cloud 를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. Google Cloud신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $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 API.

    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 API

  5. Make sure that you have the following role or roles on the project: Agent Platform User (roles/aiplatform.user) or Agent Platform Administrator (roles/aiplatform.admin)

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  6. 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

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

  8. Enable the Agent Platform API.

    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 API

  9. Make sure that you have the following role or roles on the project: Agent Platform User (roles/aiplatform.user) or Agent Platform Administrator (roles/aiplatform.admin)

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  10. 에이전트가 Google Cloud 모델 컨텍스트 프로토콜 (MCP) 도구를 사용하는 경우 사용자 계정과 연결된 서비스 계정 모두에 MCP 도구 사용자 (roles/mcp.toolUser) 역할을 부여합니다.

Antigravity 에이전트와 상호작용

Agent Platform에서 관리형 에이전트 API를 사용하는 가장 간단한 방법은 서드 파티 Antigravity 기본 에이전트와 직접 상호작용하는 것입니다. 커스텀 에이전트 리소스를 만들 필요가 없으며 즉석에서 에이전트를 호출할 수 있습니다.

상호작용을 시작하려면 antigravity-preview-05-2026 (또는 최신 미리보기 변형)과 같은 기본 에이전트 대상을 지정하고 즉석 원격 환경을 요청합니다.

REST

요청 변수

API를 호출하기 전에 다음 변수를 바꿉니다.

  • PROJECT_ID: 프로젝트 ID입니다. Google Cloud
  • LOCATION: 상호작용의 리전 위치입니다. global 리전만 지원됩니다.

HTTP 메서드 및 URL

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions

JSON 요청 본문

{
  "stream": true,
  "background": true,
  "store": true,
  "agent": "antigravity-preview-05-2026",
  "environment": {
    "type": "remote"
  },
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "Who are you, can you execute python code? Show me an example."
        }
      ]
    }
  ]
}

curl 명령어

curl -X POST "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "stream": true,
      "background": true,
      "store": true,
      "agent": "antigravity-preview-05-2026",
      "environment": {"type": "remote"},
      "input": [
          {
              "type": "user_input",
              "content": [
                  {
                      "type": "text",
                      "text": "Who are you, can you execute python code? Show me an example."
                  }
              ]
          }
      ]
  }'

응답 예시

초기 상호작용 후 서비스는 스트리밍 응답을 반환합니다. interaction.complete 데이터에 포함된 interaction.idenvironment_id는 세션 상태를 유지하기 위해 후속 호출에서 사용할 수 있습니다. interaction.id는 대화 기록을 계속하는 데 사용되고 environment_id는 동일한 샌드박스 환경을 재사용할 수 있도록 합니다. 자세한 내용은 세션 상태 관리를 참조하세요.

event: interaction.complete
data: {
  "interaction": {
    "id": "1234567890",
    "status": "completed",
    "usage": {
      "total_tokens": 51132,
      "total_input_tokens": 48984,
      "input_tokens_by_modality": [
        {
          "modality": "text",
          "tokens": 48984
        }
      ],
      "total_output_tokens": 769,
      "output_tokens_by_modality": [
        {
          "modality": "text",
          "tokens": 769
        }
      ],
      "total_thought_tokens": 1379
    },
    "created": "2026-05-15T22:26:05Z",
    "updated": "2026-05-15T22:26:05Z",
    "environment_id": "env_CAE1234567890",
    "object": "interaction"
  },
  "event_type": "interaction.complete"
}

Python

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

from google import genai

client = genai.Client(
    vertexai=True,
    project="PROJECT_ID",
    location="global",
)

stream = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Who are you, can you execute python code? Show me an example.",
    environment={"type": "remote"},
    stream=True,
    background=True,
    store=True,
)

for event in stream:
    print(event)

스트리밍 응답은 InteractionSSEEvent 객체를 생성합니다. 최종 interaction.complete 이벤트에는 environment_id 및 상호작용 id이 포함되어 있으며, 이를 후속 호출에서 재사용하여 세션 상태 및 대화 기록을 유지할 수 있습니다. 자세한 내용은 세션 상태 관리를 참조하세요.

JavaScript

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({
    vertexai: true,
    project: "PROJECT_ID",
    location: "global",
});

const stream = await client.interactions.create({
    agent: "antigravity-preview-05-2026",
    input: "Who are you, can you execute python code? Show me an example.",
    environment: { type: "remote" },
    stream: true,
    background: true,
    store: true,
});

for await (const event of stream) {
    console.log(event);
}

스트리밍 응답은 이벤트 객체를 생성합니다. 최종 interaction.complete 이벤트에는 environment_id 및 상호작용 id이 포함되어 있으며, 이를 후속 호출에서 재사용하여 세션 상태 및 대화 기록을 유지할 수 있습니다. 자세한 내용은 세션 상태 관리를 참조하세요.

Agents API를 사용하여 만든 커스텀 에이전트와 상호작용

에이전트 만들기 및 관리에 설명된 대로 만든 커스텀 에이전트와 상호작용하려면 에이전트 ID를 사용하여 지정해야 합니다.

커스텀 에이전트를 가져오거나 나열하여 ID를 찾는 방법에 대한 자세한 내용은 에이전트 나열을 참조하세요.

환경 구성 및 초기화

커스텀 에이전트와 상호작용할 때 다음을 수행합니다.

  • 기본 동작: 기본 환경으로 에이전트를 만드는 경우 요청에 AGENT_ID를 지정합니다.

  • 환경 명시적으로 정의: 에이전트를 만들 때 환경 구성을 정의하지 않은 경우 초기 상호작용 요청의 environment 블록에서 환경을 명시적으로 정의해야 합니다.

    예를 들면 다음과 같습니다.

    "environment": {"type": "remote"}
    

초기 상호작용 API 호출 중에 샌드박스 환경에서 기능을 동적으로 구성하여 특정 작업 요구사항을 충족할 수 있습니다. 예를 들면 다음과 같습니다.

  • Cloud Storage를 사용하여 스킬 연결: Cloud Storage 버킷을 연결하여 대용량 데이터 또는 영구 파일 디렉터리를 컨테이너 파일 시스템에 로드합니다.

  • 스킬 레지스트리를 사용하여 스킬 연결: 특정 기능 또는 런타임 워크플로를 제공하기 위해 커스텀 도구, 스크립트 또는 사전 패키지된 에이전트 스킬 목록을 제공합니다. 스킬 레지스트리를 참조하세요.

환경 구성 구조 목록과 멀티턴 대화 상태를 유지하는 방법의 예시는 환경 ID로 세션 상태 관리를 참조하세요.

커스텀 에이전트에 상호작용 보내기

에이전트 ID를 지정하여 커스텀 에이전트에 상호작용을 보냅니다.

REST

요청 변수

API를 호출하기 전에 다음 변수를 바꿉니다.

  • PROJECT_ID: 프로젝트 ID입니다. Google Cloud
  • LOCATION: global 리전만 지원됩니다.
  • AGENT_ID: 등록된 에이전트 리소스의 커스텀 식별자입니다. 커스텀 에이전트를 가져오거나 나열하여 ID를 찾는 방법에 대한 자세한 내용은 에이전트 나열을 참조하세요.

HTTP 메서드 및 URL

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions

JSON 요청 본문

{
  "stream": true,
  "background": true,
  "store": true,
  "agent": "AGENT_ID",
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "Tell me the name of python packages used for data analysis."
        }
      ]
    }
  ]
}

curl 명령어

curl -X POST "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "stream": true,
      "background": true,
      "store": true,
      "agent": "AGENT_ID",
      "input": [
          {
              "type": "user_input",
              "content": [
                  {
                      "type": "text",
                      "text": "Tell me the name of python packages used for data analysis."
                  }
              ]
          }
      ]
  }'

응답 예시

초기 상호작용 후 서비스는 스트리밍 응답을 반환합니다. interaction.complete 데이터에 포함된 interaction.idenvironment_id는 세션 상태를 유지하기 위해 후속 호출에서 사용할 수 있습니다. interaction.id는 대화 기록을 계속하는 데 사용되고 environment_id는 동일한 샌드박스 환경을 재사용할 수 있도록 합니다. 자세한 내용은 세션 상태 관리를 참조하세요.

data: {
  "interaction": {
    "id": "1234567890",
    "status": "completed",
    "usage": {
      "total_tokens": 7558,
      "total_input_tokens": 6822,
      "input_tokens_by_modality": [
        {
          "modality": "text",
          "tokens": 6822
        }
      ],
      "total_output_tokens": 278,
      "output_tokens_by_modality": [
        {
          "modality": "text",
          "tokens": 278
        }
      ],
      "total_thought_tokens": 458
    },
    "created": "2026-05-15T22:38:56Z",
    "updated": "2026-05-15T22:38:56Z",
    "environment_id": "env_CAE1234567890",
    "object": "interaction"
  },
  "event_type": "interaction.complete"
}

Python

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

from google import genai

client = genai.Client(
    vertexai=True,
    project="PROJECT_ID",
    location="global",
)

stream = client.interactions.create(
    agent="AGENT_ID",
    input="Tell me the name of python packages used for data analysis.",
    stream=True,
    background=True,
    store=True,
)

for event in stream:
    print(event)

JavaScript

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({
    vertexai: true,
    project: "PROJECT_ID",
    location: "global",
});

const stream = await client.interactions.create({
    agent: "AGENT_ID",
    input: "Tell me the name of python packages used for data analysis.",
    stream: true,
    background: true,
    store: true,
});

for await (const event of stream) {
    console.log(event);
}

세션 상태 및 멀티턴 상호작용 관리

기본적으로 특정 환경 컨테이너 또는 대화 기록을 타겟팅하지 않는 한 상호작용은 스테이트리스(Stateless)입니다. 멀티턴 어시스턴트 흐름에서 대화 전반에 걸쳐 로컬 파일, 코드 실행 컨텍스트, 시스템 수정사항, 런타임 설치 오픈소스 소프트웨어 라이브러리, 대화 기록을 보관할 수 있습니다.

  • 대화를 계속하려면: 이전 상호작용의 ID를 previous_interaction_id 매개변수에 전달합니다.
  • 만든 환경을 계속 사용하려면: 이전 상호작용에서 반환된 환경 ID 를 environment 매개변수에 전달합니다.

environment 필드의 다음 매개변수를 사용하여 주요 환경 구성을 선택할 수 있습니다.

JSON 구조 설명
"environment": {"type": "remote"} 새 표준 샌드박스 환경을 프로비저닝합니다. 초기 상호작용 중에 이 옵션을 사용합니다.
"environment": "env_CAEQ..." 이 환경 ID와 연결된 모든 라이브러리, 스크립트, 파일, 상태를 보존하여 기존의 영구 샌드박스 컨테이너를 재사용합니다.
"environment": {"type": "remote", "sources": [{"type": "gcs", "source": "gs://YOUR_BUCKET/YOUR_FILE", "target": "YOUR_TARGET_PATH"}]} 새 원격 샌드박스를 프로비저닝하고 Google Cloud Storage에 저장된 것과 같이 지정된 `sources`의 커스텀 스킬 또는 파일로 미리 로드합니다.

동일한 샌드박스 컨테이너를 재사용하고 대화를 계속하는 후속 상호작용 요청을 보내려면 environment_id 필드에서 반환된 environment를 전달하고 previous_interaction_id를 지정합니다. 다음 예시에서는 에이전트와 상호작용할 때 상태 저장 세션을 계속하는 방법을 보여줍니다.

REST

요청 변수

API를 호출하기 전에 다음 변수를 바꿉니다.

  • PROJECT_ID: 프로젝트 ID입니다. Google Cloud
  • LOCATION: global 리전만 지원됩니다.
  • AGENT_ID 등록된 에이전트 리소스의 커스텀 식별자 (antigravity-preview-05-2026)입니다.
  • PREVIOUS_INTERACTION_ID: 이전 상호작용에서 반환된 상호작용 ID입니다.
  • ENV_ID: 이전 상호작용에서 반환된 환경 ID입니다.

HTTP 메서드 및 URL

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions

JSON 요청 본문

{
  "stream": true,
  "background": true,
  "store": true,
  "agent": "AGENT_ID",
  "previous_interaction_id": "PREVIOUS_INTERACTION_ID",
  "environment": "ENV_ID",
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "What did I ask you before and what did you do?"
        }
      ]
    }
  ]
}

curl 명령어

curl -X POST "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
      "stream": true,
      "background": true,
      "store": true,
      "agent": "AGENT_ID",
      "previous_interaction_id": "PREVIOUS_INTERACTION_ID",
      "environment": "ENV_ID",
      "input": [
          {
              "type": "user_input",
              "content": [
                  {
                      "type": "text",
                      "text": "What did I ask you before and what did you do?"
                  }
              ]
          }
      ]
  }'

Python

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

from google import genai

client = genai.Client(
    vertexai=True,
    project="PROJECT_ID",
    location="global",
)

stream = client.interactions.create(
    agent="AGENT_ID",
    input="What did I ask you before and what did you do?",
    previous_interaction_id="PREVIOUS_INTERACTION_ID",
    environment="ENV_ID",
    stream=True,
    background=True,
    store=True,
)

for event in stream:
    print(event)

Python SDK에서 environment_id 문자열을 environment 매개변수로 직접 전달하여 기존 샌드박스 컨테이너를 재사용합니다. previous_interaction_id를 사용하여 대화 기록을 계속합니다.

JavaScript

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({
    vertexai: true,
    project: "PROJECT_ID",
    location: "global",
});

const stream = await client.interactions.create({
    agent: "AGENT_ID",
    input: "What did I ask you before and what did you do?",
    previous_interaction_id: "PREVIOUS_INTERACTION_ID",
    environment: "ENV_ID",
    stream: true,
    background: true,
    store: true,
});

for await (const event of stream) {
    console.log(event);
}

JavaScript SDK에서 environment_id 문자열을 environment 매개변수로 직접 전달하여 기존 샌드박스 컨테이너를 재사용합니다. previous_interaction_id를 사용하여 대화 기록을 계속합니다.

상호작용 중 구성 재정의

커스텀 에이전트 정의에는 일반적으로 도구, 스킬, 서드 파티 연결의 기본 구성이 포함되지만 기본 에이전트 리소스 구성을 수정하지 않고도 상호작용별로 이러한 정의를 동적으로 조정할 수 있습니다.

일반적인 사용 사례는 런타임에 모델 컨텍스트 프로토콜 (MCP) 서버에 대한 연결을 동적으로 재정의하는 것입니다. 상호작용 요청 본문에 지정된 도구 또는 MCP 서버는 해당 상호작용 턴 동안 에이전트의 사전 구성된 도구를 완전히 재정의합니다.

상호작용 시 MCP 서버를 재정의하거나 정의하려면 상호작용 요청의 tools 목록 내부에 mcp_server 유형 도구를 추가합니다.

REST

요청 변수

API를 호출하기 전에 다음 변수를 바꿉니다.

  • PROJECT_ID: 프로젝트 ID입니다. Google Cloud
  • LOCATION: 상호작용 위치입니다. global 리전만 지원됩니다.
  • AGENT_ID: 에이전트 리소스의 커스텀 식별자입니다.
  • MCP_SERVER_URL: 새 MCP 서버의 원격 HTTP 게이트웨이 URL입니다.
  • MCP_SERVER_NAME: 대상 MCP 호스트 도메인의 설명 라벨입니다.
  • MCP_HEADER_KEY: 선택사항입니다. 헤더 키 이름 (예: Authorization).
  • MCP_HEADER_VALUE: 선택사항입니다. 사용자 인증 정보 값 (예: Bearer <token>).

HTTP 메서드 및 URL

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions

JSON 요청 본문

{
  "stream": true,
  "background": true,
  "store": true,
  "agent": "agents/AGENT_ID",
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "Analyze our database and summarize recent purchase events."
        }
      ]
    }
  ],
  "tools": [
    {
      "type": "mcp_server",
      "url": "MCP_SERVER_URL",
      "name": "MCP_SERVER_NAME",
      "headers": {
        "MCP_HEADER_KEY": "MCP_HEADER_VALUE"
      }
    }
  ]
}

curl 명령어

curl -X POST "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/interactions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Api-Revision: 2026-05-20" \
  -d '{
     "stream": true,
     "background": true,
     "store": true,
     "agent": "agents/AGENT_ID",
     "input": [
         {
             "type": "user_input",
             "content": [
                 {
                     "type": "text",
                     "text": "Analyze our database and summarize recent purchase events."
                 }
             ]
         }
     ],
     "tools": [
         {
             "type": "mcp_server",
             "url": "MCP_SERVER_URL",
             "name": "MCP_SERVER_NAME",
             "headers": {
                 "MCP_HEADER_KEY": "MCP_HEADER_VALUE"
             }
         }
     ]
  }'

Python

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

from google import genai

client = genai.Client(
    vertexai=True,
    project="PROJECT_ID",
    location="global",
)

stream = client.interactions.create(
    agent="AGENT_ID",
    input="Analyze our database and summarize recent purchase events.",
    tools=[
        {
            "type": "mcp_server",
            "url": "MCP_SERVER_URL",
            "name": "MCP_SERVER_NAME",
            "headers": {
                "MCP_HEADER_KEY": "MCP_HEADER_VALUE"
            },
        }
    ],
    stream=True,
    background=True,
    store=True,
)

for event in stream:
    print(event)

JavaScript

이 코드를 실행하기 전에 REST 탭에 설명된 변수를 설정합니다.

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({
    vertexai: true,
    project: "PROJECT_ID",
    location: "global",
});

const stream = await client.interactions.create({
    agent: "AGENT_ID",
    input: "Analyze our database and summarize recent purchase events.",
    tools: [
        {
            type: "mcp_server",
            url: "MCP_SERVER_URL",
            name: "MCP_SERVER_NAME",
            headers: {
                "MCP_HEADER_KEY": "MCP_HEADER_VALUE",
            },
        },
    ],
    stream: true,
    background: true,
    store: true,
});

for await (const event of stream) {
    console.log(event);
}

다음 단계

개요

자율 에이전트를 빌드하기 위한 구성 기반의 REST 우선 환경인 Agent Platform의 관리형 에이전트 API에 대해 알아봅니다.

참조

격리된 샌드박스 컨테이너, 권한, 사전 설치된 패키지/도구에 대해 알아봅니다.