Vertex AI Agent Engine에서 에이전트 개발 및 배포
이 페이지에서는 다음 에이전트 프레임워크를 사용하여 지정된 날짜에 두 통화 간의 환율을 반환하는 에이전트를 만들고 배포하는 방법을 보여줍니다.
시작하기 전에
- 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.
-
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI 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 theserviceusage.services.enable
permission. Learn how to grant roles. -
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI 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 theserviceusage.services.enable
permission. Learn how to grant roles. -
Vertex AI 사용자(
roles/aiplatform.user
) -
스토리지 관리자(
roles/storage.admin
) 다음 명령어를 실행하여 Vertex AI SDK for Python 및 기타 필수 패키지를 설치합니다.
ADK
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,adk]>=1.112
LangGraph
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,langchain]>=1.112
LangChain
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,langchain]>=1.112
AG2
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,ag2]>=1.112
LlamaIndex
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,llama_index]>=1.112
사용자로 인증
Colab
다음 코드를 실행합니다.
from google.colab import auth auth.authenticate_user(project_id="PROJECT_ID")
Cloud Shell
어떤 조치도 필요하지 않습니다.
로컬 셸
다음 명령어를 실행합니다.
gcloud auth application-default login
다음 코드를 실행하여 Vertex AI Agent Engine을 가져오고 SDK를 초기화합니다.
import vertexai client = vertexai.Client( project="PROJECT_ID", # Your project ID. location="LOCATION", # Your cloud region. )
Vertex AI Agent Engine을 사용하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.
역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.
커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.
Python용 Vertex AI SDK 설치 및 초기화
에이전트 개발
먼저 도구를 개발합니다.
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()
그런 다음 에이전트를 인스턴스화합니다.
ADK
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)
LangGraph
from vertexai import agent_engines
agent = agent_engines.LanggraphAgent(
model="gemini-2.0-flash",
tools=[get_exchange_rate],
model_kwargs={
"temperature": 0.28,
"max_output_tokens": 1000,
"top_p": 0.95,
},
)
LangChain
from vertexai import agent_engines
agent = agent_engines.LangchainAgent(
model="gemini-2.0-flash",
tools=[get_exchange_rate],
model_kwargs={
"temperature": 0.28,
"max_output_tokens": 1000,
"top_p": 0.95,
},
)
AG2
from vertexai import agent_engines
agent = agent_engines.AG2Agent(
model="gemini-2.0-flash",
runnable_name="Get Exchange Rate Agent",
tools=[get_exchange_rate],
)
LlamaIndex
from vertexai.preview import reasoning_engines
def runnable_with_tools_builder(model, runnable_kwargs=None, **kwargs):
from llama_index.core.query_pipeline import QueryPipeline
from llama_index.core.tools import FunctionTool
from llama_index.core.agent import ReActAgent
llama_index_tools = []
for tool in runnable_kwargs.get("tools"):
llama_index_tools.append(FunctionTool.from_defaults(tool))
agent = ReActAgent.from_tools(llama_index_tools, llm=model, verbose=True)
return QueryPipeline(modules = {"agent": agent})
agent = reasoning_engines.LlamaIndexQueryPipelineAgent(
model="gemini-2.0-flash",
runnable_kwargs={"tools": [get_exchange_rate]},
runnable_builder=runnable_with_tools_builder,
)
마지막으로 로컬에서 에이전트를 테스트합니다.
ADK
for event in app.stream_query(
user_id="USER_ID",
message="What is the exchange rate from US dollars to SEK today?",
):
print(event)
여기서 USER_ID는 사용자 정의 ID이며 128자(영문 기준)로 제한됩니다.
LangGraph
agent.query(input={"messages": [
("user", "What is the exchange rate from US dollars to SEK today?"),
]})
LangChain
agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
AG2
agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
LlamaIndex
agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
에이전트 배포
에이전트를 배포하려면 다음 안내를 따르세요.
ADK
remote_agent = client.agent_engines.create(
agent=app,
config={
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
}
)
LangGraph
remote_agent = client.agent_engines.create(
agent,
config={
"requirements": ["google-cloud-aiplatform[agent_engines,langchain]"],
},
)
LangChain
remote_agent = client.agent_engines.create(
agent,
config={
"requirements": ["google-cloud-aiplatform[agent_engines,langchain]"],
},
)
AG2
from vertexai import agent_engines
remote_agent = agent_engines.create(
agent,
config={
"requirements": ["google-cloud-aiplatform[agent_engines,ag2]"],
},
)
LlamaIndex
from vertexai import agent_engines
remote_agent = agent_engines.create(
agent,
config={
"requirements": ["google-cloud-aiplatform[agent_engines,llama_index]"],
},
)
이렇게 하면 Vertex AI에 reasoningEngine
리소스가 생성됩니다.
에이전트 사용
쿼리를 전송하여 배포된 에이전트를 테스트합니다.
ADK
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)
LangGraph
remote_agent.query(input={"messages": [
("user", "What is the exchange rate from US dollars to SEK today?"),
]})
LangChain
remote_agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
AG2
remote_agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
LlamaIndex
remote_agent.query(
input="What is the exchange rate from US dollars to SEK today?"
)
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.
remote_agent.delete(force=True)