Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions python/agents/order-processing/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import logging
import os

# Add the project root to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if project_root not in sys.path:
sys.path.insert(0, project_root)
import sys # noqa: F401

import vertexai
from dotenv import load_dotenv, set_key
from order_processing.agent import root_agent
from vertexai import agent_engines
from vertexai.preview.reasoning_engines import AdkApp
from order_processing.agent import root_agent
import logging
import os
from dotenv import set_key, load_dotenv

# Add the project root to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if project_root not in sys.path:
sys.path.insert(0, project_root)

load_dotenv()

Expand All @@ -44,9 +43,10 @@
project=GOOGLE_CLOUD_PROJECT,
location=GOOGLE_CLOUD_LOCATION,
staging_bucket=f"gs://{STAGING_BUCKET}",
service_account=AGENT_SERVICE_ACCOUNT
service_account=AGENT_SERVICE_ACCOUNT,
)


# Function to update the .env file
def update_env_file(agent_engine_id, env_file_path):
"""Updates the .env file with the agent engine ID."""
Expand All @@ -56,6 +56,7 @@ def update_env_file(agent_engine_id, env_file_path):
except Exception as e:
print(f"Error updating .env file: {e}")


logger.info("deploying app...")

app = AdkApp(
Expand All @@ -72,16 +73,18 @@ def update_env_file(agent_engine_id, env_file_path):
"google-cloud-aiplatform[adk,agent-engines]>=1.100.0,<2.0.0",
"google-adk>=1.5.0,<2.0.0",
"python-dotenv",
"google-cloud-secret-manager"
"google-cloud-secret-manager",
],
extra_packages=[
"./order_processing",
],
service_account = AGENT_SERVICE_ACCOUNT
service_account=AGENT_SERVICE_ACCOUNT,
)

# log remote_app
logging.info(f"Deployed agent to Vertex AI Agent Engine successfully, resource name: {remote_app.resource_name}")
logging.info(
f"Deployed agent to Vertex AI Agent Engine successfully, resource name: {remote_app.resource_name}"
)

# Update the .env file with the new Agent Engine ID
update_env_file(remote_app.resource_name, ENV_FILE_PATH)
47 changes: 26 additions & 21 deletions python/agents/order-processing/deployment/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import asyncio
import json
import os

# Add the project root to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if project_root not in sys.path:
sys.path.insert(0, project_root)

import os
import vertexai
from vertexai import agent_engines
from google.adk.sessions import VertexAiSessionService
from dotenv import load_dotenv
import json
import asyncio
from google.adk.sessions import VertexAiSessionService
from vertexai import agent_engines


def pretty_print_event(event):
"""Pretty prints an event with truncation for long content."""
if "content" not in event:
print(f"[{event.get('author', 'unknown')}]: {event}")
return

author = event.get("author", "unknown")
parts = event["content"].get("parts", [])

for part in parts:
if "text" in part:
text = part["text"]
Expand All @@ -51,27 +45,35 @@ def pretty_print_event(event):
print(f" Args: {args}")
elif "functionResponse" in part:
func_response = part["functionResponse"]
print(f"[{author}]: Function response: {func_response.get('name', 'unknown')}")
print(
f"[{author}]: Function response: {func_response.get('name', 'unknown')}"
)
# Truncate response if too long
response = json.dumps(func_response.get("response", {}))
if len(response) > 100:
response = response[:97] + "..."
print(f" Response: {response}")


load_dotenv()

vertexai.init(
project=os.getenv("GOOGLE_CLOUD_PROJECT"),
location=os.getenv("GOOGLE_CLOUD_LOCATION"),
)

session_service = VertexAiSessionService(project=os.getenv("GOOGLE_CLOUD_PROJECT"),location=os.getenv("GOOGLE_CLOUD_LOCATION"))
session_service = VertexAiSessionService(
project=os.getenv("GOOGLE_CLOUD_PROJECT"),
location=os.getenv("GOOGLE_CLOUD_LOCATION"),
)
AGENT_ENGINE_ID = os.getenv("AGENT_ENGINE_ID")

session = asyncio.run(session_service.create_session(
app_name=AGENT_ENGINE_ID,
user_id="123",
))
session = asyncio.run(
session_service.create_session(
app_name=AGENT_ENGINE_ID,
user_id="123",
)
)

agent_engine = agent_engines.get(AGENT_ENGINE_ID)

Expand All @@ -86,5 +88,8 @@ def pretty_print_event(event):
):
pretty_print_event(event)

asyncio.run(session_service.delete_session(app_name=AGENT_ENGINE_ID, user_id=123, session_id=session.id))

asyncio.run(
session_service.delete_session(
app_name=AGENT_ENGINE_ID, user_id=123, session_id=session.id
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import agent
from . import agent # noqa: F401
6 changes: 3 additions & 3 deletions python/agents/order-processing/order_processing/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

from google.adk.agents import Agent
from .order_processing_tool import order_processing_tool

from .order_processing_tool import order_processing_tool

root_agent = Agent(
model='gemini-2.5-flash',
name='order_processing_agent',
model="gemini-2.5-flash",
name="order_processing_agent",
instruction="Help the user with creating orders, leverage the tools you have access to",
tools=[order_processing_tool],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
# limitations under the License.

import os

from dotenv import load_dotenv
from google.adk.tools.application_integration_tool.application_integration_toolset import ApplicationIntegrationToolset
from google.adk.tools.application_integration_tool.application_integration_toolset import (
ApplicationIntegrationToolset,
)

load_dotenv()

GOOGLE_CLOUD_PROJECT=os.getenv("GOOGLE_CLOUD_PROJECT")
GOOGLE_CLOUD_LOCATION=os.getenv("GOOGLE_CLOUD_LOCATION")
APPINT_PROCESS_NAME=os.getenv("APPINT_PROCESS_NAME")
APPINT_PROCESS_TRIGGER=os.getenv("APPINT_PROCESS_TRIGGER")
GOOGLE_CLOUD_PROJECT = os.getenv("GOOGLE_CLOUD_PROJECT")
GOOGLE_CLOUD_LOCATION = os.getenv("GOOGLE_CLOUD_LOCATION")
APPINT_PROCESS_NAME = os.getenv("APPINT_PROCESS_NAME")
APPINT_PROCESS_TRIGGER = os.getenv("APPINT_PROCESS_TRIGGER")

TOOL_INSTR="""
TOOL_INSTR = """
**Tool Instructions: Order Processing**
You are an order processing assistant. Your primary goal is to help users place new orders by gathering the necessary information and using the available tools to submit the request.

Expand Down Expand Up @@ -55,7 +58,7 @@

order_processing_tool = ApplicationIntegrationToolset(
project=GOOGLE_CLOUD_PROJECT,
location=GOOGLE_CLOUD_LOCATION,
location=GOOGLE_CLOUD_LOCATION,
integration=APPINT_PROCESS_NAME,
triggers=[APPINT_PROCESS_TRIGGER],
tool_instructions=TOOL_INSTR,
Expand Down