The agent_action decorator marks a Python function as an agent action. Place the decorated function in the appropriate actions folder, and the Playground discovers and loads it when the function has useful documentation. section 6.2.2
Use the decorator in three practical steps:
- Write a function with a clear name and documented parameters. section 6.2.2
- Place the file in the Playground assistant_actions folder. section 6.2.2
- Add @agent_action so the function can be inspected and represented as an OpenAI-standard tool specification. section 7.5
A file-saving action
@agent_action\ndef save_file(filename, content):\n """Save content to a file."""\n ...\n\nThe Playground can discover this action and make it available to an assistant.
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
Inspect the complete file_actions.py listing, including imports, output-path construction, file writing, and the decorator annotation. section 6.2.2
