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.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
Agent Engine을 사용하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.
-
Vertex AI 사용자(
roles/aiplatform.user
) -
스토리지 관리자(
roles/storage.admin
)
역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.
Python용 Vertex AI SDK 설치 및 초기화
다음 명령어를 실행하여 Python용 Vertex AI SDK 및 기타 필수 패키지를 설치합니다.
LangGraph
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,langchain]
LangChain
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,langchain]
AG2
pip install --upgrade --quiet google-cloud-aiplatform[agent_engines,ag2]
사용자로 인증
Colab
다음 코드를 실행합니다.
from google.colab import auth auth.authenticate_user(project_id="PROJECT_ID")
Cloud Shell
어떤 조치도 필요하지 않습니다.
로컬 셸
다음 명령어를 실행합니다.
gcloud auth application-default login
다음 코드를 실행하여 Agent Engine을 가져오고 SDK를 초기화합니다.
import vertexai from vertexai import agent_engines vertexai.init( project="PROJECT_ID", # Your project ID. location="LOCATION", # Your cloud region. staging_bucket="gs://BUCKET_NAME", # Your staging bucket. )
에이전트 개발
먼저 도구를 개발합니다.
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()
그런 다음 에이전트를 인스턴스화합니다.
LangGraph
from vertexai.preview.reasoning_engines import LanggraphAgent
agent = LanggraphAgent(
model="gemini-1.5-flash-001",
tools=[get_exchange_rate],
model_kwargs={
"temperature": 0.28,
"max_output_tokens": 1000,
"top_p": 0.95,
},
)
LangChain
from vertexai.preview.reasoning_engines import LangchainAgent
agent = LangchainAgent(
model="gemini-1.5-flash-001",
tools=[get_exchange_rate],
model_kwargs={
"temperature": 0.28,
"max_output_tokens": 1000,
"top_p": 0.95,
},
)
AG2
from vertexai.preview.reasoning_engines import AG2Agent
agent = AG2Agent(
model="gemini-1.5-flash-001",
runnable_name="Get Exchange Rate Agent",
tools=[get_exchange_rate],
)
마지막으로 로컬에서 에이전트를 테스트합니다.
LangGraph
agent.query(input={"messages": [
("user", "What's the exchange rate from US dollars to Swedish currency?"),
]})
LangChain
agent.query(
input="What's the exchange rate from US dollars to Swedish currency?"
)
AG2
agent.query(
input="What's the exchange rate from US dollars to Swedish currency?"
)
에이전트 배포
에이전트를 배포하려면 다음 안내를 따르세요.
LangGraph
remote_agent = agent_engines.create(
agent,
requirements=["google-cloud-aiplatform[agent_engines,langchain]"],
)
LangChain
remote_agent = agent_engines.create(
agent,
requirements=["google-cloud-aiplatform[agent_engines,langchain]"],
)
AG2
remote_agent = agent_engines.create(
agent,
requirements=["google-cloud-aiplatform[agent_engines,ag2]"],
)
이렇게 하면 Vertex AI에 reasoningEngine
리소스가 생성됩니다.
상담사 사용
쿼리를 전송하여 배포된 에이전트를 테스트합니다.
LangGraph
remote_agent.query(input={"messages": [
("user", "What's the exchange rate from US dollars to Swedish currency?"),
]})
LangChain
remote_agent.query(
input="What's the exchange rate from US dollars to Swedish currency?"
)
AG2
remote_agent.query(
input="What's the exchange rate from US dollars to Swedish currency?"
)
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.
remote_agent.delete()