step0_plain_function.py 782 B

1234567891011121314151617181920212223242526
  1. """
  2. 第 0 步:先写一个普通 Python 函数。
  3. 这一文件不涉及 MCP、不涉及 Agent,只是为了让你先理解:
  4. 工具的本质 = 一个有输入、有输出的函数。
  5. 运行:
  6. python step0_plain_function.py
  7. """
  8. def search_hotels(city: str, nights: int = 2, budget_per_night: int = 400) -> str:
  9. """
  10. 查询目的地住宿区域建议。
  11. Args:
  12. city: 目的地城市,比如 重庆、杭州、西安。
  13. nights: 入住晚数,默认 2 晚。
  14. budget_per_night: 每晚住宿预算,单位元,默认 400 元。
  15. """
  16. return f"{city} 住 {nights} 晚,建议预算 {budget_per_night} 元/晚。"
  17. if __name__ == "__main__":
  18. result = search_hotels(city="重庆", nights=2, budget_per_night=400)
  19. print(result)