in build.py [0:0]
def run_agent_engine_deployment() -> str:
# TODO figure out a better way to dynamically get these env after they are written
navigate_to_directory(BACKEND_PATH)
sys.path.insert(0, os.getcwd())
from app.orchestration.server_utils import get_agent_from_config
from app.utils.utils import deploy_agent_to_agent_engine
agent_manager = get_agent_from_config(
agent_orchestration_framework=AGENT_ORCHESTRATION_FRAMEWORK,
agent_foundation_model=AGENT_FOUNDATION_MODEL,
industry_type=AGENT_INDUSTRY_TYPE
)
remote_agent = None
if AGENT_ORCHESTRATION_FRAMEWORK == "llamaindex_agent":
remote_agent = deploy_agent_to_agent_engine(
agent_manager,
AGENT_NAME,
AGENT_DESCRIPTION
)
elif AGENT_ORCHESTRATION_FRAMEWORK == "langgraph_vertex_ai_agent_engine_agent" or AGENT_ORCHESTRATION_FRAMEWORK == "langchain_vertex_ai_agent_engine_agent":
remote_agent = deploy_agent_to_agent_engine(
agent_manager.agent_executor,
AGENT_NAME,
AGENT_DESCRIPTION
)
if not remote_agent.resource_name:
raise Exception("Error deploying Agent to Agent Engine.")
try:
# If AGENT_ENGINE_RESOURCE_ID is set, then the agent will query the remote agent
with open(BACKEND_CONFIG_FILE.replace(f"{BACKEND_PATH}/", ""), "a", encoding="utf-8") as f:
f.write(f"\nAGENT_ENGINE_RESOURCE_ID: {remote_agent.resource_name}\n")
f.close()
except FileNotFoundError:
print(f"`{BACKEND_CONFIG_FILE.replace(f'{BACKEND_PATH}/', '')}` file not found.")
navigate_to_directory(".")
# Retrieve the project number associated with your project ID
project_number = subprocess.run(
["gcloud", "projects", "describe", PROJECT_ID, "--format=value(projectNumber)"],
check=True,
capture_output=True,
text=True
).stdout.strip()
# Add Discovery Engine Editor to the Agent Engine Service account
iam_command = [
"gcloud",
"projects",
"add-iam-policy-binding",
PROJECT_ID,
f"--member=serviceAccount:service-{project_number}@gcp-sa-aiplatform-re.iam.gserviceaccount.com",
"--role=roles/discoveryengine.editor",
"--no-user-output-enabled"
]
subprocess.run(iam_command, check=True)
return remote_agent.resource_name