A custom action is an assistant-configured capability that invokes an external service through a defined interface. It connects an assistant to APIs, local code, or hosted services so the assistant can retrieve data or perform tasks. section 3.3.1 section 6.2.2
Build and connect a custom action by following these steps:
- Define the action, endpoint, HTTP method, inputs, and response structure. section 3.3.1
- Generate and run a FastAPI service, then inspect its Swagger documentation and OpenAPI specification. section 3.3.1
- Expose a local service through an ngrok tunnel when the assistant requires external access. section 3.3.1
- Paste the OpenAPI specification and server URL into the assistant’s custom-action configuration, test it, and update it whenever the API changes. section 3.3.2
Daily task organizer
A FastAPI GET endpoint at /tasks returns daily tasks as JSON. A task-organizing assistant calls the endpoint, prioritizes the results, and produces a schedule plot. Public assistants can activate exposed actions, so services handling private information or paid resources require care. section 3.3.1 section 3.3.2
Listing 6.4 playground/assistant_actions/file_actions.py
import os
from playground.actions_manager import agent_action
OUTPUT_FOLDER = "assistant_outputs"
@agent_action #1
def save_file(filename, content): #2
"""
Save content to a file. #3
:param filename: The name of the file including extension.
:param content: The content to save in the file.
"""
file_path = os.path.join(OUTPUT_FOLDER, filename)
with open(file_path, "w", encoding="utf-8") as file:
file.write(content)
print(f"File '{filename}' saved successfully.") #4
Shows a local Playground action defined with an agent_action decorator, function parameters, documentation, and file-writing behavior. section 6.2.2
