--- sidebar_position: 3 title: "Action Function" --- Action functions allow you to write custom buttons that appear in the message toolbar for end users to interact with. This feature enables more interactive messaging, allowing users to grant permission before a task is performed, generate visualizations of structured data, download an audio snippet of chats, and many other use cases. Actions are admin-managed functions that extend the chat interface with custom interactive capabilities. When a message is generated by a model that has actions configured, these actions appear as clickable buttons beneath the message. A scaffold of Action code can be found [in the community section](https://openwebui.com/f/hub/custom_action/). For more Action Function examples built by the community, visit [https://openwebui.com/functions](https://openwebui.com/functions). An example of a graph visualization Action can be seen in the video below.
## Action Function Architecture Actions are Python-based functions that integrate directly into the chat message toolbar. They execute server-side and can interact with users through real-time events, modify message content, and access the full Open WebUI context. ### Function Structure Actions follow a specific class structure with an `action` method as the main entry point: ```python class Action: def __init__(self): self.valves = self.Valves() class Valves(BaseModel): # Configuration parameters parameter_name: str = "default_value" async def action(self, body: dict, __user__=None, __event_emitter__=None, __event_call__=None): # Action implementation return {"content": "Modified message content"} ``` ### Action Method Parameters The `action` method receives several parameters that provide access to the execution context: - **`body`** - Dictionary containing the message data and context - **`__user__`** - Current user object with permissions and settings - **`__event_emitter__`** - Function to send real-time updates to the frontend - **`__event_call__`** - Function for bidirectional communication (confirmations, inputs) - **`__model__`** - Model information that triggered the action - **`__request__`** - FastAPI request object for accessing headers, etc. - **`__id__`** - Action ID (useful for multi-action functions) ## Event System Integration Actions can utilize Open WebUI's real-time event system for interactive experiences: ### Event Emitter (`__event_emitter__`) **For more information about Events and Event emitters, see [Events and Event Emitters](https://docs.openwebui.com/features/plugin/events/).** Send real-time updates to the frontend during action execution: ```python async def action(self, body: dict, __event_emitter__=None): # Send status updates await __event_emitter__({ "type": "status", "data": {"description": "Processing request..."} }) # Send notifications await __event_emitter__({ "type": "notification", "data": {"type": "info", "content": "Action completed successfully"} }) ``` ### Event Call (`__event_call__`) Request user input or confirmation during execution: ```python async def action(self, body: dict, __event_call__=None): # Request user confirmation response = await __event_call__({ "type": "confirmation", "data": { "title": "Confirm Action", "message": "Are you sure you want to proceed?" } }) # Request user input user_input = await __event_call__({ "type": "input", "data": { "title": "Enter Value", "message": "Please provide additional information:", "placeholder": "Type your input here..." } }) ``` ## Action Types and Configurations ### Single Actions Standard actions with one `action` method: ```python async def action(self, body: dict, **kwargs): # Single action implementation return {"content": "Action result"} ``` ### Multi-Actions Functions can define multiple sub-actions through an `actions` array: ```python actions = [ { "id": "summarize", "name": "Summarize", "icon_url": "data:image/svg+xml;base64,..." }, { "id": "translate", "name": "Translate", "icon_url": "data:image/svg+xml;base64,..." } ] async def action(self, body: dict, __id__=None, **kwargs): if __id__ == "summarize": # Summarization logic return {"content": "Summary: ..."} elif __id__ == "translate": # Translation logic return {"content": "Translation: ..."} ``` ### Global vs Model-Specific Actions - **Global Actions** - Turn on the toggle in the Action's settings, to globally enable it for all users and all models. - **Model-Specific Actions** - Configure enabled actions for specific models in the model settings. ## Advanced Capabilities ### Background Task Execution For long-running operations, actions can integrate with the task system: ```python async def action(self, body: dict, __event_emitter__=None): # Start long-running process await __event_emitter__({ "type": "status", "data": {"description": "Starting background processing..."} }) # Perform time-consuming operation result = await some_long_running_function() return {"content": f"Processing completed: {result}"} ``` ### File and Media Handling Actions can work with uploaded files and generate new media: ```python async def action(self, body: dict): message = body # Access uploaded files if message.get("files"): for file in message["files"]: # Process file based on type if file["type"] == "image": # Image processing logic pass # Return new files return { "content": "Analysis complete", "files": [ { "type": "image", "url": "generated_chart.png", "name": "Analysis Chart" } ] } ``` ### User Context and Permissions Actions can access user information and respect permissions: ```python async def action(self, body: dict, __user__=None): if __user__["role"] != "admin": return {"content": "This action requires admin privileges"} user_name = __user__["name"] return {"content": f"Hello {user_name}, admin action completed"} ``` ## Example - Specifying Action Frontmatter Each Action function can include a docstring at the top to define metadata for the button. This helps customize the display and behavior of your Action in Open WebUI. Example of supported frontmatter fields: - `title`: Display name of the Action. - `author`: Name of the creator. - `version`: Version number of the Action. - `required_open_webui_version`: Minimum compatible version of Open WebUI. - `icon_url (optional)`: URL or Base64 string for a custom icon. **Base64-Encoded Example:**