튜토리얼: 익스프레스 모드의 Agent Platform API

익스프레스 모드의 Gemini Enterprise Agent Platform을 사용하면 Agent Platform에서 사용할 수 있는 핵심 생성형 AI 기능을 사용해 볼 수 있습니다. 이 튜토리얼에서는 빠른 모드에서 Agent Platform API를 사용하여 다음 작업을 완료하는 방법을 보여줍니다.

  • 빠른 모드용 Google 생성형 AI SDK를 설치하고 초기화합니다.
  • 다음을 포함하여 Gemini for Google Cloud API에 요청을 전송합니다.

    • 스트리밍 요청
    • 비스트리밍 요청
    • 함수 호출 요청

시작하기 전에

이 문서에 설명된 태스크를 수행하기 전에 익스프레스 모드에 가입하세요.

빠른 모드용 SDK 설치 및 초기화

Google 생성형 AI SDK를 사용하면 Google 생성형 AI 모델과 기능을 사용하여 AI 기반 애플리케이션을 빌드할 수 있습니다. 빠른 모드에서 Agent Platform을 사용하는 경우 google-genai 패키지를 설치하고 초기화하여 생성된 API 키를 사용해 인증합니다.

설치

익스프레스 모드용 Google 생성형 AI SDK를 설치하려면 다음 명령어를 실행합니다.

# Developer TODO: If you're using Colab, uncomment the following lines:
# from google.colab import auth
# auth.authenticate_user()

!pip install --upgrade google-genai

Colaboratory를 사용하는 경우 설치 후 메시지가 표시되면 런타임을 다시 시작합니다.

초기화

익스프레스 모드의 API 키를 구성하고 enterprise=True로 클라이언트를 초기화합니다. API 키를 가져오는 방법에 대한 자세한 내용은 익스프레스 모드의 Agent Platform 개요를 참조하세요.

from google import genai
from google.genai import types

# Developer TODO: Replace YOUR_API_KEY with your API key.
API_KEY = "YOUR_API_KEY"

client = genai.Client(
    enterprise=True, api_key=API_KEY
)

Gemini for Google Cloud API에 요청 보내기

Gemini for Google Cloud API에 스트리밍 또는 비스트리밍 요청을 보낼 수 있습니다. 스트리밍 요청은 요청이 처리될 때 청크로 응답을 반환합니다. 비스트리밍 요청은 처리가 완료된 후 전체 응답을 반환합니다.

스트리밍 요청

스트리밍 요청을 보내려면 client.models.generate_content_stream()를 호출하고 각 청크가 도착할 때마다 출력합니다.

from google import genai
from google.genai import types

def generate():
  client = genai.Client(enterprise=True, api_key="YOUR_API_KEY")

  config = types.GenerateContentConfig(
      thinking_config=types.ThinkingConfig(
          thinking_level="MEDIUM",
      ),
      seed=5,
      max_output_tokens=1024,
      stop_sequences=["STOP!"],
      safety_settings=[
          types.SafetySetting(
              category="HARM_CATEGORY_HATE_SPEECH",
              threshold="BLOCK_ONLY_HIGH",
          )
      ],
  )
  for chunk in client.models.generate_content_stream(
      model="gemini-3.8-flash",
      contents="Explain bubble sort to me",
      config=config,
  ):
    print(chunk.text, end="")

generate()

비스트리밍 요청

다음 코드 샘플은 Gemini 3.8 Flash(gemini-3.8-flash)에 비스트리밍 요청을 전송하는 함수를 정의합니다. 사고 수준, 출력 파라미터, 안전 설정을 구성하는 방법을 보여줍니다.

from google import genai
from google.genai import types

def generate():
  client = genai.Client(enterprise=True, api_key="YOUR_API_KEY")

  config = types.GenerateContentConfig(
      thinking_config=types.ThinkingConfig(
          thinking_level="MEDIUM",
      ),
      seed=5,
      max_output_tokens=1024,
      stop_sequences=["STOP!"],
      safety_settings=[
          types.SafetySetting(
              category="HARM_CATEGORY_HATE_SPEECH",
              threshold="BLOCK_ONLY_HIGH",
          )
      ],
  )
  response = client.models.generate_content(
      model="gemini-3.8-flash",
      contents="Explain bubble sort to me",
      config=config,
  )
  print(response.text)

generate()

함수 호출 요청

다음 코드 샘플은 함수 도구를 선언하고, 초기 프롬프트를 3.8 Flash에 전송하고, 응답에서 함수 호출 부분을 수신한 후 일치하는 FunctionResponse를 모델로 다시 전송하여 최종 응답을 생성합니다.

from google import genai
from google.genai import types

client = genai.Client(enterprise=True, api_key="YOUR_API_KEY")

get_weather_declaration = types.FunctionDeclaration(
    name="get_current_weather",
    description="Gets the current weather in a given city.",
    parameters={
        "type": "OBJECT",
        "properties": {
            "location": {
                "type": "STRING",
                "description": "The city and state, such as Boston, MA.",
            },
            "unit": {
                "type": "STRING",
                "enum": ["C", "F"],
            },
        },
        "required": ["location"],
    },
)
tools = [types.Tool(function_declarations=[get_weather_declaration])]

prompt = "What is the weather in Boston?"
first_response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents=prompt,
    config=types.GenerateContentConfig(tools=tools),
)

function_call = first_response.function_calls[0]
contents = [
    types.Content(role="user", parts=[types.Part(text=prompt)]),
    first_response.candidates[0].content,
    types.Content(
        role="user",
        parts=[
            types.Part(
                function_response=types.FunctionResponse(
                    id=function_call.id,
                    name=function_call.name,
                    response={"weather": "sunny", "temperature": "72F"},
                )
            )
        ],
    ),
]

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents=contents,
    config=types.GenerateContentConfig(tools=tools),
)
print(response.text)

삭제

이 튜토리얼에서는 Google Cloud 리소스를 만들지 않으므로 요금이 청구되지 않도록 정리할 필요가 없습니다.

다음 단계

  • 익스프레스 모드에서 Agent Platform의 Agent Studio 튜토리얼을 사용해 보세요.
  • 익스프레스 모드의 Agent Platform에 대한 전체 API 참조를 확인하세요.