Vertex AI Extensions이 지원 중단됨에 따라 기존 워크플로를 Gemini Enterprise Agent Platform (Agent Platform)으로 이전해야 합니다. 이 가이드에서는 세 가지 핵심 확장 프로그램 카테고리의 이전 경로를 설명합니다.
코드 인터프리터 확장 프로그램
마이그레이션: Agent Platform 코드 실행 샌드박스
대안: Gemini API CodeExecution 도구
코드 인터프리터 확장 프로그램을 Agent Platform Code Execution Sandbox로 이전해야 합니다. 이 관리형 서비스는 신뢰할 수 없는 AI 생성 코드를 실행하도록 특별히 설계된 안전하고 격리된 상태 저장 샌드박스 환경을 제공합니다. 프로그래매틱 실행, 금융 계산, 데이터 과학 워크플로에 적합합니다.
또는 생성 패스 중에 Gemini 모델이 코드를 기본적으로 자동으로 작성하고 실행하도록 하려면 google-genai SDK의 내장 code_execution 도구를 사용하면 됩니다.
마이그레이션 예
Vertex AI 확장 프로그램:
from vertexai.preview import extensions
extension = extensions.Extension.from_hub("code_interpreter")
response = extension.execute(
operation_id="generate_and_execute_code",
operation_params={"code": "import math\nprint(math.sqrt(15376))"}
)
Agent Platform 코드 실행 샌드박스:
옵션 1: 에이전트 개발 키트 (ADK) 사용
from google.adk.code_executors.agent_engine_sandbox_code_executor import (
AgentEngineSandboxCodeExecutor,
)
from vertexai.preview.reasoning_engines import Agent
root_agent = Agent(
model="gemini-2.0-flash-001",
name="agent_engine_code_execution_agent",
instruction=base_system_instruction()
+ """
You need to assist the user with their queries by looking at the data and the
context in the conversation. Your final answer should summarize the code and
code execution relevant to the user query.
Include all pieces of data required to answer the question, such as a table
from code execution results. If the query can be answered directly without
writing code, generate the textual response directly. Take care not to manually
run commands like `pip install`. When plotting trends, sort data by the x-axis.
""",
code_executor=AgentEngineSandboxCodeExecutor(
sandbox_resource_name=None,
agent_engine_resource_name=None,
),
)
옵션 2: 생성형 AI 클라이언트 SDK 사용
from google import genai
# Initialize Gemini model
model = genai.Client().models
# Ask Gemini to generate code for a calculation
prompt = """
Write Python code to calculate the mean and standard deviation of these numbers:
[23, 45, 67, 89, 12, 34, 56]
Return only the Python code, no explanations.
"""
response = model.generate_content(
model="gemini-2.5-flash",
contents=prompt
)
generated_code = response.text.replace("```python", "").replace("```", "").strip()
# Execute the generated code in Agent Engine Sandbox using new pattern
exec_response = client.agent_engines.sandboxes.execute_code(
name=sandbox_resource_name,
input_data={"code": generated_code},
)
# Parse response with new file handling logic
for output in exec_response.outputs:
if output.mime_type == "application/json" and output.metadata is None:
result = json.loads(output.data.decode("utf-8"))
if result.get("msg_out"):
print(result.get("msg_out"))
if result.get("msg_err"):
print(f"Error occurred: {result.get('msg_err')}")
옵션 3: 동적 수동 도구로 정의
import json
import re
from google.genai.types import FunctionDeclaration, Tool
def execute_python_code(code: str) -> str:
"""Execute Python code in a secure sandbox.
Args:
code: Python code to execute
Returns:
The output from code execution
"""
# Extract code block if wrapped in markdown
code_match = re.search(r"```python\n(.*?)\n```", code, re.DOTALL)
code_to_execute = code_match.group(1) if code_match else code
# Execute in sandbox
response = client.agent_engines.sandboxes.execute_code(
name=sandbox_resource_name, input_data={"code": code_to_execute}
)
# Parse response using new pattern
for output in response.outputs:
if output.mime_type == "application/json" and output.metadata is None:
result = json.loads(output.data.decode("utf-8"))
if result.get("msg_err"):
return f"Error: {result.get('msg_err')}"
return result.get("msg_out", "Code executed successfully")
return "Code executed (no output)"
# Create a tool from the function
code_tool = Tool(
function_declarations=[FunctionDeclaration.from_func(execute_python_code)]
)
Google 검색 확장 프로그램
다음으로 이전: Google 검색을 사용한 그라운딩
Google 검색을 사용한 그라운딩으로 이전하세요. 이 기능은 신뢰할 수 있는 검색 색인과 최신 공개 정보에 모델 응답을 고정하여 사실성 비율을 높입니다.
마이그레이션 예
Vertex AI 확장 프로그램:
from vertexai.preview import extensions
extension = extensions.Extension.from_hub("google_search")
response = extension.execute(
operation_id="search",
operation_params={"query": "What is the next total solar eclipse in the US?"}
)
Google GenAI SDK를 사용하여 Google 검색으로 그라운딩:
from google import genai
from google.genai.types import GenerateContentConfig, GoogleSearch, Tool
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-flash",
contents="When is the next total solar eclipse in the United States?",
config=GenerateContentConfig(
tools=[Tool(google_search=GoogleSearch())],
temperature=0.0,
),
)
print(response.text)
커스텀 확장자
다음으로 이전: 함수 호출 (도구 사용)
OpenAPI 사양으로 구성한 맞춤 확장 프로그램을 함수 호출로 이전합니다. 함수 호출을 사용하면 소스 파일 내에서 외부 플랫폼 API를 정의하고 인터페이스 추상화를 모델에 전달할 수 있습니다.
마이그레이션 예
Vertex AI 확장 프로그램:
from vertexai.preview import extensions
extension = extensions.Extension.create(
manifest={
"name": "my_custom_api",
"apiSpec": {"openApiYaml": "..."}
}
)
Google 생성형 AI SDK를 사용한 도구 사용:
from google import genai
from google.genai.types import GenerateContentConfig
def get_order_status(order_id: str) -> str:
"""Returns the current status of a customer order.
Args:
order_id: The unique identifier of the order.
"""
statuses = {"123": "Shipped", "456": "Processing"}
return statuses.get(order_id, "Order not found")
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.0-pro",
contents="Can you check the status of my order 123?",
config=GenerateContentConfig(
tools=[get_order_status],
),
)
print(response.text)