rentbot / tool_handler.py
mgbam's picture
Rename tool_handler.py import json to tool_handler.py
8fc1b10 verified
# rentbot/tool_handler.py
import json
def execute_tool_call(tool_call):
"""
Executes a tool call and returns a result message for the LLM.
"""
function_name = tool_call.function.name
try:
arguments = json.loads(tool_call.function.arguments)
if function_name == "create_event":
# In a real app, you'd hit Google Calendar's API here.
# For this example, we'll just simulate success.
print(f"--- TOOL CALL: create_event ---")
print(f" Summary: {arguments.get('summary')}")
print(f" Start: {arguments.get('start_time')}")
print(f" Duration: {arguments.get('duration_minutes', 30)} minutes")
print(f"-----------------------------")
result_message = f"Successfully booked the viewing for '{arguments.get('summary')}'."
return {
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": json.dumps({"status": "success", "message": result_message}),
}
else:
return {
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": json.dumps({"status": "error", "message": f"Unknown function: {function_name}"}),
}
except json.JSONDecodeError:
return {
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": json.dumps({"status": "error", "message": "Invalid arguments format."}),
}