diff --git a/python/agents/order-processing/deployment/deploy.py b/python/agents/order-processing/deployment/deploy.py index 0b469b346..02910c484 100644 --- a/python/agents/order-processing/deployment/deploy.py +++ b/python/agents/order-processing/deployment/deploy.py @@ -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() @@ -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.""" @@ -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( @@ -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) diff --git a/python/agents/order-processing/deployment/test_deployment.py b/python/agents/order-processing/deployment/test_deployment.py index 9b3d4298c..b06e5649f 100644 --- a/python/agents/order-processing/deployment/test_deployment.py +++ b/python/agents/order-processing/deployment/test_deployment.py @@ -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"] @@ -51,13 +45,16 @@ 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( @@ -65,13 +62,18 @@ def pretty_print_event(event): 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) @@ -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 + ) +) diff --git a/python/agents/order-processing/order_processing/__init__.py b/python/agents/order-processing/order_processing/__init__.py index 44f7dab56..626296e25 100644 --- a/python/agents/order-processing/order_processing/__init__.py +++ b/python/agents/order-processing/order_processing/__init__.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -from . import agent \ No newline at end of file +from . import agent # noqa: F401 diff --git a/python/agents/order-processing/order_processing/agent.py b/python/agents/order-processing/order_processing/agent.py index 67d25464e..c9f3e610d 100644 --- a/python/agents/order-processing/order_processing/agent.py +++ b/python/agents/order-processing/order_processing/agent.py @@ -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], ) diff --git a/python/agents/order-processing/order_processing/order_processing_tool.py b/python/agents/order-processing/order_processing/order_processing_tool.py index 25132b2d0..945ee1ad2 100644 --- a/python/agents/order-processing/order_processing/order_processing_tool.py +++ b/python/agents/order-processing/order_processing/order_processing_tool.py @@ -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. @@ -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,