-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add code snippets for Agent Engine #13735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9d91e47
9c654f5
dfcecdb
b52e0a5
6c75f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import vertexai | ||
| import os | ||
|
|
||
| PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
| LOCATION = os.getenv("GOOGLE_CLOUD_LOCATION") | ||
|
|
||
| client = vertexai.Client(project=PROJECT_ID, location=LOCATION) | ||
|
|
||
| # [START agentengine_quickstart_adk_tool] | ||
| 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() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The HTTP request to the Frankfurter API does not handle potential errors, such as network issues or non-200 status codes. This could lead to unexpected behavior or crashes if the API is unavailable or returns an error. It's good practice to check for a successful response by adding |
||
| # [END agentengine_quickstart_adk_tool] | ||
|
|
||
| def quickstart_adk_example(staging_bucket: str) -> reasoning_engines.ReasoningEngine: | ||
|
yeesian marked this conversation as resolved.
Outdated
|
||
|
|
||
| # [START agentengine_quickstart_adk_agent_init] | ||
| from google.adk.agents import Agent | ||
| from vertexai import agent_engines | ||
|
|
||
| agent = Agent( | ||
| model="gemini-2.0-flash", | ||
| name='currency_exchange_agent', | ||
|
yeesian marked this conversation as resolved.
Outdated
|
||
| tools=[get_exchange_rate], | ||
| ) | ||
|
|
||
| app = agent_engines.AdkApp(agent=agent) | ||
| # [END agentengine_quickstart_adk_agent_init] | ||
|
|
||
| # [START agentengine_quickstart_adk_testlocally] | ||
| async for event in app.async_stream_query( | ||
| user_id="USER_ID", | ||
| message="What is the exchange rate from US dollars to SEK today?", | ||
| ): | ||
| print(event) | ||
| # [END agentengine_quickstart_adk_testlocally] | ||
|
|
||
| # [START agentengine_quickstart_adk_deploy] | ||
| remote_agent = client.agent_engines.create( | ||
| agent=app, | ||
| config={ | ||
| "requirements": ["google-cloud-aiplatform[agent_engines,adk]"], | ||
| "staging_bucket": staging_bucket, | ||
| } | ||
| ) | ||
| # [END agentengine_quickstart_adk_deploy] | ||
|
|
||
| events = [] | ||
| # [START agentengine_quickstart_adk_testremotely] | ||
| 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) | ||
| # [END agentengine_quickstart_adk_testremotely] | ||
| events.append(event) | ||
|
yeesian marked this conversation as resolved.
Outdated
|
||
|
|
||
| remote_agent.delete(force=True) | ||
| return events | ||
Uh oh!
There was an error while loading. Please reload this page.