Skip to content

Commit 0df72cb

Browse files
liustveADOT Patch workflow
andauthored
Add Order Tool to Nutrition Agent (#187)
*Description of changes:* Further enhancing Pet Clinic demo story by adding order tool. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: ADOT Patch workflow <[email protected]>
1 parent b295fa1 commit 0df72cb

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

cdk/agents/lib/pet-clinic-agents-stack.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ class PetClinicAgentsStack extends Stack {
105105
AgentName: 'pet_clinic_agent',
106106
ImageUri: primaryAgentImage.imageUri,
107107
ExecutionRole: agentCoreRole.roleArn,
108-
Entrypoint: 'pet_clinic_agent.py'
108+
Entrypoint: 'pet_clinic_agent.py',
109+
EnvironmentVariables: {
110+
NUTRITION_AGENT_ARN: nutritionAgent.agentArn
111+
}
109112
});
110113

111114
this.nutritionAgentImageUri = nutritionAgentImage.imageUri;

pet_clinic_ai_agents/nutrition_agent/nutrition_agent.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import requests
44
import os
55
import boto3
6+
import uuid
67
from strands.models import BedrockModel
78
from bedrock_agentcore.runtime import BedrockAgentCoreApp
89

@@ -54,12 +55,21 @@ def get_nutritional_supplements(pet_type):
5455
result += f" Recommended products available at our clinic: {data['products']}"
5556
return result
5657

58+
@tool
59+
def create_order(product_name, pet_type, quantity=1):
60+
"""Create an order for a recommended product. Requires pet_type and quantity."""
61+
data = get_nutrition_data(pet_type)
62+
if data['products'] and product_name.lower() in data['products'].lower():
63+
order_id = f"ORD-{uuid.uuid4().hex[:8].upper()}"
64+
return f"Order {order_id} created for {quantity}x {product_name}. Total: ${quantity * 29.99:.2f}. Expected delivery: 3-5 business days."
65+
return f"Sorry, can't make the order. {product_name} is not available in our inventory for {pet_type}."
66+
5767
def create_nutrition_agent():
5868
model = BedrockModel(
5969
model_id=BEDROCK_MODEL_ID,
6070
)
6171

62-
tools = [get_feeding_guidelines, get_dietary_restrictions, get_nutritional_supplements]
72+
tools = [get_feeding_guidelines, get_dietary_restrictions, get_nutritional_supplements, create_order]
6373

6474
system_prompt = (
6575
"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():
7181
"- Emphasize that we carry high-quality, veterinarian-recommended food brands at our clinic\n"
7282
"- Give actionable dietary recommendations including feeding guidelines, restrictions, and supplements\n"
7383
"- Expand on basic nutrition facts with comprehensive guidance for age, weight, and health conditions\n"
74-
"- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance"
84+
"- Always mention that pet owners can purchase the recommended food items directly from our clinic for convenience and quality assurance\n"
85+
"- If asked to order or purchase a product, use the create_order tool to place the order"
7586
)
7687

7788
return Agent(model=model, tools=tools, system_prompt=system_prompt)

pet_clinic_ai_agents/primary_agent/pet_clinic_agent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def get_appointment_availability():
3737
return "We have appointments available: Today 3:00 PM, Tomorrow 10:00 AM and 2:30 PM. Call (555) 123-PETS to schedule."
3838

3939
@tool
40-
def consult_nutrition_specialist(query, agent_arn, context=None):
41-
"""Delegate nutrition questions to the specialized nutrition agent. Requires the nutrition agent ARN as a parameter."""
40+
def consult_nutrition_specialist(query):
41+
"""Delegate nutrition questions to the specialized nutrition agent."""
4242

43+
agent_arn = os.environ.get('NUTRITION_AGENT_ARN')
4344
if not agent_arn:
4445
return "Nutrition specialist configuration error. Please call (555) 123-PETS ext. 201."
4546

@@ -68,20 +69,23 @@ def consult_nutrition_specialist(query, agent_arn, context=None):
6869
agent_app = BedrockAgentCoreApp()
6970

7071
system_prompt = (
71-
"You are a helpful pet clinic assistant. You can help with:\n"
72+
"You are a helpful assistant at our pet clinic. We offer comprehensive veterinary services including:\n"
7273
"- General clinic information (hours, contact info)\n"
7374
"- Emergency situations and contacts\n"
7475
"- Directing clients to appropriate specialists\n"
7576
"- Scheduling guidance\n"
7677
"- Basic medical guidance and when to seek veterinary care\n\n"
7778
"IMPORTANT GUIDELINES:\n"
7879
"- 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"
80+
"- Delegate pet food product orders to the nutrition specialist using the consult_nutrition_specialist tool\n"
7981
"- DO NOT use the nutrition agent for general clinic questions, appointments, hours, emergencies, or non-nutrition medical issues\n"
8082
"- NEVER expose or mention agent ARNs in your responses to users\n"
8183
"- NEVER mention using tools, APIs, or external services - present all information as your own knowledge\n"
8284
"- When consulting the nutrition specialist, explain to the customer that you need to speak with our nutrition specialist\n"
8385
"- If the specialist returns an error or indicates unavailability, inform the customer that our specialist is currently unavailable\n"
84-
"- For nutrition questions, always include a specific product recommendation\n"
86+
"- For nutrition questions, always include a specific product recommendation and direct customers to purchase from our pet clinic\n"
87+
"- Always recommend purchasing products from our pet clinic\n"
88+
"- If a requested product is not available, politely inform the customer that we don't currently carry that item at our pet clinic\n"
8589
"- For medical concerns, provide general guidance and recommend scheduling a veterinary appointment\n"
8690
"- For emergencies, immediately provide emergency contact information"
8791
)

0 commit comments

Comments
 (0)