-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_agent.py
More file actions
78 lines (66 loc) · 2.88 KB
/
Copy pathdeploy_agent.py
File metadata and controls
78 lines (66 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import logging
import vertexai
from vertexai.preview import reasoning_engines
from procurement.agent import root_agent
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def deploy():
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
location = os.getenv("GOOGLE_CLOUD_LOCATION", "us-central1")
staging_bucket = os.getenv("GOOGLE_CLOUD_STORAGE_BUCKET")
if not project_id:
raise ValueError("GOOGLE_CLOUD_PROJECT environment variable is not set.")
if not staging_bucket:
logger.warning("GOOGLE_CLOUD_STORAGE_BUCKET is not set. Vertex AI requires a staging bucket.")
logger.info("Please set GOOGLE_CLOUD_STORAGE_BUCKET in your .env file.")
return
logger.info(f"Initializing Vertex AI (Project: {project_id}, Location: {location}, Bucket: {staging_bucket})")
vertexai.init(project=project_id, location=location, staging_bucket=staging_bucket)
# Wrap the agent in AdkApp
# AdkApp automatically handles the Runner and streaming interface required by Agent Engine
logger.info("Wrapping agent in AdkApp...")
app = reasoning_engines.AdkApp(
agent=root_agent,
enable_tracing=True,
)
logger.info("Deploying Reasoning Engine... This may take a few minutes.")
try:
# Create the Reasoning Engine
remote_agent = reasoning_engines.ReasoningEngine.create(
app,
requirements=[
"google-cloud-aiplatform[adk,agent_engines]",
"pymongo",
"dnspython",
"python-dotenv",
"fastapi>=0.115.2",
"uvicorn>=0.35.0",
"pydantic>=2.11.7",
"google-genai",
"ag-ui-protocol>=0.1.7",
"aiohttp>=3.12.0",
"google-adk>=1.14.0",
"google-api-python-client>=2.187.0",
"google-auth-oauthlib>=1.2.3",
"google-auth-httplib2>=0.2.1",
"motor>=3.7.1"
],
extra_packages=["./procurement", "./ag_ui_adk", "./credentials.json", "./token.json", "./procurement/.env"],
display_name="procurement-buying-support-agent",
description="Autonomous Procurement Agent",
)
logger.info("✅ Deployment Successful!")
logger.info(f"Resource Name: {remote_agent.resource_name}")
logger.info(f"Reasoning Engine ID: {remote_agent.resource_name.split('/')[-1]}")
logger.info("\nCopy this ID and update your .env file:")
logger.info(f'REASONING_ENGINE_ID="{remote_agent.resource_name.split("/")[-1]}"')
except Exception as e:
logger.error(f"❌ Deployment Failed: {e}")
raise
if __name__ == "__main__":
# Load env vars if not already loaded
from dotenv import load_dotenv
load_dotenv("procurement/.env")
deploy()