审查这段为多租户支持服务生成的退款智能体代码。
构建可复用的支持智能体,接收用户消息,并且只能执行已授权、可安全重试的退款。
Python
from langchain.agents import create_agent
from langchain.tools import tool
@tool
def refund_order(order_id: str, amount: float) -> str:
"""Refund an order and return the transaction id."""
result = payment_api.refund(order_id, amount)
return result.transaction_id
def answer(request):
try:
agent = create_agent(
model="openai:gpt-5.5",
tools=[refund_order],
system_prompt=request["instructions"],
)
return agent.invoke({"messages": request["messages"]})
except Exception:
return {"messages": []}
生成代码仅作示例,不代表任何特定模型