Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions examples/agents/adk/14_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,41 @@
from settings import settings


def main():
# Tools
def lookup_customer(customer_id: str) -> dict:
"""Look up customer information by ID."""
customers = {
"C001": {"name": "Alice Smith", "tier": "gold", "balance": 1500.00},
"C002": {"name": "Bob Jones", "tier": "silver", "balance": 320.50},
"C003": {"name": "Carol White", "tier": "bronze", "balance": 50.00},
}
customer = customers.get(customer_id.upper())
if customer:
return {"found": True, "customer_id": customer_id, **customer}
return {"found": False, "error": f"Customer {customer_id} not found"}

def apply_discount(customer_id: str, discount_percent: float) -> dict:
"""Apply a discount to a customer's account."""
if discount_percent > 50:
return {"error": "Discount cannot exceed 50%"}
return {
"status": "success",
"customer_id": customer_id,
"discount_applied": f"{discount_percent}%",
"message": f"Applied {discount_percent}% discount to {customer_id}",
}

def check_order_status(order_id: str) -> dict:
"""Check the status of an order."""
orders = {
"ORD-1001": {"status": "shipped", "tracking": "TRK-98765", "eta": "2025-04-20"},
"ORD-1002": {"status": "processing", "tracking": None, "eta": "2025-04-25"},
}
return orders.get(order_id.upper(), {"error": f"Order {order_id} not found"})
def lookup_customer(customer_id: str) -> dict:
"""Look up customer information by ID."""
customers = {
"C001": {"name": "Alice Smith", "tier": "gold", "balance": 1500.00},
"C002": {"name": "Bob Jones", "tier": "silver", "balance": 320.50},
"C003": {"name": "Carol White", "tier": "bronze", "balance": 50.00},
}
customer = customers.get(customer_id.upper())
if customer:
return {"found": True, "customer_id": customer_id, **customer}
return {"found": False, "error": f"Customer {customer_id} not found"}


def apply_discount(customer_id: str, discount_percent: float) -> dict:
"""Apply a discount to a customer's account."""
if discount_percent > 50:
return {"error": "Discount cannot exceed 50%"}
return {
"status": "success",
"customer_id": customer_id,
"discount_applied": f"{discount_percent}%",
"message": f"Applied {discount_percent}% discount to {customer_id}",
}


def check_order_status(order_id: str) -> dict:
"""Check the status of an order."""
orders = {
"ORD-1001": {"status": "shipped", "tracking": "TRK-98765", "eta": "2025-04-20"},
"ORD-1002": {"status": "processing", "tracking": None, "eta": "2025-04-25"},
}
return orders.get(order_id.upper(), {"error": f"Order {order_id} not found"})


def main():
agent = Agent(
name="customer_service_agent",
model=settings.llm_model,
Expand Down
72 changes: 37 additions & 35 deletions examples/agents/adk/15_global_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,44 @@
from settings import settings


def main():
def get_product_info(product_name: str) -> dict:
"""Look up product information."""
products = {
"widget pro": {
"name": "Widget Pro",
"price": 49.99,
"category": "electronics",
"in_stock": True,
"rating": 4.7,
},
"gadget max": {
"name": "Gadget Max",
"price": 89.99,
"category": "electronics",
"in_stock": False,
"rating": 4.2,
},
"smart lamp": {
"name": "Smart Lamp",
"price": 34.99,
"category": "home",
"in_stock": True,
"rating": 4.5,
},
}
return products.get(product_name.lower(), {"error": f"Product '{product_name}' not found"})

def get_store_hours(location: str) -> dict:
"""Get store hours for a location."""
stores = {
"downtown": {"hours": "9 AM - 9 PM", "open_today": True},
"mall": {"hours": "10 AM - 8 PM", "open_today": True},
}
return stores.get(location.lower(), {"error": f"Location '{location}' not found"})
def get_product_info(product_name: str) -> dict:
"""Look up product information."""
products = {
"widget pro": {
"name": "Widget Pro",
"price": 49.99,
"category": "electronics",
"in_stock": True,
"rating": 4.7,
},
"gadget max": {
"name": "Gadget Max",
"price": 89.99,
"category": "electronics",
"in_stock": False,
"rating": 4.2,
},
"smart lamp": {
"name": "Smart Lamp",
"price": 34.99,
"category": "home",
"in_stock": True,
"rating": 4.5,
},
}
return products.get(product_name.lower(), {"error": f"Product '{product_name}' not found"})


def get_store_hours(location: str) -> dict:
"""Get store hours for a location."""
stores = {
"downtown": {"hours": "9 AM - 9 PM", "open_today": True},
"mall": {"hours": "10 AM - 8 PM", "open_today": True},
}
return stores.get(location.lower(), {"error": f"Location '{location}' not found"})


def main():
agent = Agent(
name="store_assistant",
model=settings.llm_model,
Expand Down
126 changes: 65 additions & 61 deletions examples/agents/adk/16_customer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,72 @@
from settings import settings


def main():
# ── Domain tools ──────────────────────────────────────────────

def get_account_details(account_id: str) -> dict:
"""Retrieve account details for a customer."""
accounts = {
"ACC-001": {
"name": "Alice Johnson",
"email": "alice@example.com",
"plan": "Premium",
"balance": 142.50,
"status": "active",
},
"ACC-002": {
"name": "Bob Martinez",
"email": "bob@example.com",
"plan": "Basic",
"balance": 0.00,
"status": "active",
},
}
return accounts.get(account_id.upper(), {"error": f"Account {account_id} not found"})

def get_billing_history(account_id: str, num_months: int = 3) -> dict:
"""Get billing history for an account."""
history = {
"ACC-001": [
{"month": "March 2025", "amount": 49.99, "status": "paid"},
{"month": "February 2025", "amount": 49.99, "status": "paid"},
{"month": "January 2025", "amount": 42.50, "status": "paid"},
],
}
records = history.get(account_id.upper(), [])
return {"account_id": account_id, "billing_history": records[:num_months]}

def submit_support_ticket(account_id: str, category: str, description: str) -> dict:
"""Submit a support ticket for a customer issue."""
valid_categories = ["billing", "technical", "account", "general"]
if category.lower() not in valid_categories:
return {"error": f"Invalid category. Must be one of: {valid_categories}"}
return {
"ticket_id": "TKT-2025-0042",
"account_id": account_id,
"category": category,
"status": "open",
"message": f"Ticket created for {category} issue",
}

def update_account_plan(account_id: str, new_plan: str) -> dict:
"""Update the subscription plan for an account."""
plans = {"basic": 19.99, "premium": 49.99, "enterprise": 99.99}
price = plans.get(new_plan.lower())
if not price:
return {"error": f"Invalid plan. Available: {list(plans.keys())}"}
return {
"status": "success",
"account_id": account_id,
"new_plan": new_plan,
"new_price": f"${price}/month",
"effective_date": "Next billing cycle",
}
# ── Domain tools ──────────────────────────────────────────────

def get_account_details(account_id: str) -> dict:
"""Retrieve account details for a customer."""
accounts = {
"ACC-001": {
"name": "Alice Johnson",
"email": "alice@example.com",
"plan": "Premium",
"balance": 142.50,
"status": "active",
},
"ACC-002": {
"name": "Bob Martinez",
"email": "bob@example.com",
"plan": "Basic",
"balance": 0.00,
"status": "active",
},
}
return accounts.get(account_id.upper(), {"error": f"Account {account_id} not found"})


def get_billing_history(account_id: str, num_months: int = 3) -> dict:
"""Get billing history for an account."""
history = {
"ACC-001": [
{"month": "March 2025", "amount": 49.99, "status": "paid"},
{"month": "February 2025", "amount": 49.99, "status": "paid"},
{"month": "January 2025", "amount": 42.50, "status": "paid"},
],
}
records = history.get(account_id.upper(), [])
return {"account_id": account_id, "billing_history": records[:num_months]}


def submit_support_ticket(account_id: str, category: str, description: str) -> dict:
"""Submit a support ticket for a customer issue."""
valid_categories = ["billing", "technical", "account", "general"]
if category.lower() not in valid_categories:
return {"error": f"Invalid category. Must be one of: {valid_categories}"}
return {
"ticket_id": "TKT-2025-0042",
"account_id": account_id,
"category": category,
"status": "open",
"message": f"Ticket created for {category} issue",
}


def update_account_plan(account_id: str, new_plan: str) -> dict:
"""Update the subscription plan for an account."""
plans = {"basic": 19.99, "premium": 49.99, "enterprise": 99.99}
price = plans.get(new_plan.lower())
if not price:
return {"error": f"Invalid plan. Available: {list(plans.keys())}"}
return {
"status": "success",
"account_id": account_id,
"new_plan": new_plan,
"new_price": f"${price}/month",
"effective_date": "Next billing cycle",
}


def main():
agent = Agent(
name="customer_service_rep",
model=settings.llm_model,
Expand Down
Loading
Loading