diff --git a/cdk/agents/lib/pet-clinic-agents-stack.js b/cdk/agents/lib/pet-clinic-agents-stack.js index 6ab875c3..c8d250fc 100644 --- a/cdk/agents/lib/pet-clinic-agents-stack.js +++ b/cdk/agents/lib/pet-clinic-agents-stack.js @@ -105,7 +105,10 @@ class PetClinicAgentsStack extends Stack { AgentName: 'pet_clinic_agent', ImageUri: primaryAgentImage.imageUri, ExecutionRole: agentCoreRole.roleArn, - Entrypoint: 'pet_clinic_agent.py' + Entrypoint: 'pet_clinic_agent.py', + EnvironmentVariables: { + NUTRITION_AGENT_ARN: nutritionAgent.agentArn + } }); this.nutritionAgentImageUri = nutritionAgentImage.imageUri; diff --git a/pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py b/pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py index 4c0246b5..486729b5 100644 --- a/pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py +++ b/pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py @@ -3,6 +3,7 @@ import requests import os import boto3 +import uuid from strands.models import BedrockModel from bedrock_agentcore.runtime import BedrockAgentCoreApp @@ -54,12 +55,21 @@ def get_nutritional_supplements(pet_type): result += f" Recommended products available at our clinic: {data['products']}" return result +@tool +def create_order(product_name, pet_type, quantity=1): + """Create an order for a recommended product. Requires pet_type and quantity.""" + data = get_nutrition_data(pet_type) + if data['products'] and product_name.lower() in data['products'].lower(): + order_id = f"ORD-{uuid.uuid4().hex[:8].upper()}" + return f"Order {order_id} created for {quantity}x {product_name}. Total: ${quantity * 29.99:.2f}. Expected delivery: 3-5 business days." + return f"Sorry, can't make the order. {product_name} is not available in our inventory for {pet_type}." + def create_nutrition_agent(): model = BedrockModel( model_id=BEDROCK_MODEL_ID, ) - tools = [get_feeding_guidelines, get_dietary_restrictions, get_nutritional_supplements] + tools = [get_feeding_guidelines, get_dietary_restrictions, get_nutritional_supplements, create_order] system_prompt = ( "You are a specialized pet nutrition expert at our veterinary clinic, providing accurate, evidence-based dietary guidance for pets. " @@ -71,7 +81,8 @@ def create_nutrition_agent(): "- Emphasize that we carry high-quality, veterinarian-recommended food brands at our clinic\n" "- Give actionable dietary recommendations including feeding guidelines, restrictions, and supplements\n" "- Expand on basic nutrition facts with comprehensive guidance for age, weight, and health conditions\n" - "- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance" + "- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance\n" + "- If asked to order or purchase a product, use the create_order tool to place the order" ) return Agent(model=model, tools=tools, system_prompt=system_prompt) diff --git a/pet_clinic_ai_agents/primary_agent/pet_clinic_agent.py b/pet_clinic_ai_agents/primary_agent/pet_clinic_agent.py index d2a62735..efc6128e 100644 --- a/pet_clinic_ai_agents/primary_agent/pet_clinic_agent.py +++ b/pet_clinic_ai_agents/primary_agent/pet_clinic_agent.py @@ -37,9 +37,10 @@ def get_appointment_availability(): return "We have appointments available: Today 3:00 PM, Tomorrow 10:00 AM and 2:30 PM. Call (555) 123-PETS to schedule." @tool -def consult_nutrition_specialist(query, agent_arn, context=None): - """Delegate nutrition questions to the specialized nutrition agent. Requires the nutrition agent ARN as a parameter.""" +def consult_nutrition_specialist(query): + """Delegate nutrition questions to the specialized nutrition agent.""" + agent_arn = os.environ.get('NUTRITION_AGENT_ARN') if not agent_arn: return "Nutrition specialist configuration error. Please call (555) 123-PETS ext. 201." @@ -68,7 +69,7 @@ def consult_nutrition_specialist(query, agent_arn, context=None): agent_app = BedrockAgentCoreApp() system_prompt = ( - "You are a helpful pet clinic assistant. You can help with:\n" + "You are a helpful assistant at our pet clinic. We offer comprehensive veterinary services including:\n" "- General clinic information (hours, contact info)\n" "- Emergency situations and contacts\n" "- Directing clients to appropriate specialists\n" @@ -76,12 +77,15 @@ def consult_nutrition_specialist(query, agent_arn, context=None): "- Basic medical guidance and when to seek veterinary care\n\n" "IMPORTANT GUIDELINES:\n" "- ONLY use the consult_nutrition_specialist tool for EXPLICIT nutrition-related questions (diet, feeding, supplements, food recommendations, what to feed, can pets eat X, nutrition advice)\n" + "- Delegate pet food product orders to the nutrition specialist using the consult_nutrition_specialist tool\n" "- DO NOT use the nutrition agent for general clinic questions, appointments, hours, emergencies, or non-nutrition medical issues\n" "- NEVER expose or mention agent ARNs in your responses to users\n" "- NEVER mention using tools, APIs, or external services - present all information as your own knowledge\n" "- When consulting the nutrition specialist, explain to the customer that you need to speak with our nutrition specialist\n" "- If the specialist returns an error or indicates unavailability, inform the customer that our specialist is currently unavailable\n" - "- For nutrition questions, always include a specific product recommendation\n" + "- For nutrition questions, always include a specific product recommendation and direct customers to purchase from our pet clinic\n" + "- Always recommend purchasing products from our pet clinic\n" + "- If a requested product is not available, politely inform the customer that we don't currently carry that item at our pet clinic\n" "- For medical concerns, provide general guidance and recommend scheduling a veterinary appointment\n" "- For emergencies, immediately provide emergency contact information" )