Files
ai-agent-book/chapter2/prompt-engineering/tau_bench/envs/airline/tools/send_certificate.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

53 lines
1.7 KiB
Python

# Copyright Sierra
from typing import Any, Dict
from tau_bench.envs.tool import Tool
class SendCertificate(Tool):
@staticmethod
def invoke(
data: Dict[str, Any],
user_id: str,
amount: int,
) -> str:
users = data["users"]
if user_id not in users:
return "Error: user not found"
user = users[user_id]
# add a certificate, assume at most 3 cases per task
for id in [3221322, 3221323, 3221324]:
payment_id = f"certificate_{id}"
if payment_id not in user["payment_methods"]:
user["payment_methods"][payment_id] = {
"source": "certificate",
"amount": amount,
"id": payment_id,
}
return f"Certificate {payment_id} added to user {user_id} with amount {amount}."
@staticmethod
def get_info() -> Dict[str, Any]:
return {
"type": "function",
"function": {
"name": "send_certificate",
"description": "Send a certificate to a user. Be careful!",
"parameters": {
"type": "object",
"properties": {
"user_id": {
"type": "string",
"description": "The ID of the user to book the reservation, such as 'sara_doe_496'.",
},
"amount": {
"type": "number",
"description": "Certificate amount to send.",
},
},
"required": ["user_id", "amount"],
},
},
}