Skip to main content

Actions System

Actions are the universal unit of work in Open Genie. They are named, parameterized operations that can be triggered by the AI, cron jobs, webhooks, or direct API calls.

Architecture

┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ AI Tool Call │ │ Cron Job │ │ Webhook │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
└────────────────────┼────────────────────┘

┌─────────────────┐
│ Action Registry │
│ │
│ execute(name, │
│ params) │
└────────┬────────┘

┌─────────────────┐
│ Action Handler │
│ (function) │
└────────┬────────┘

┌─────────────────┐
│ ActionResult │
│ { output, err } │
└─────────────────┘

Action Registry (lib/actions/registry.ts)

The registry is a singleton that stores all registered actions and provides methods to execute them.

Registering an Action

import { actionRegistry } from "@/lib/actions/registry";

actionRegistry.register({
name: "my_action",
description: "Does something useful",
parameters: {
type: "object",
properties: {
input: { type: "string", description: "The input value" },
},
required: ["input"],
},
handler: async (params) => {
// Do work...
return { output: `Processed: ${params.input}` };
},
});

Executing an Action

const result = await actionRegistry.execute("my_action", { input: "hello" });
// result = { output: "Processed: hello" }
// or
// result = { error: "Something went wrong" }

Converting to Ollama Tools

const tools = actionRegistry.toOllamaTools();
// Returns OpenAI-compatible tool definitions for function calling

Listing Actions

const actions = actionRegistry.list();
// [{ name, description, parameters }, ...]

Built-in Actions

Open Genie ships with 8 built-in actions registered at boot:

send_notification

Send a push notification to connected devices.

ParameterTypeRequiredDescription
titlestringyesNotification title
bodystringyesNotification body
targetstringno"all", "phones", "tablets", or a specific device ID
levelstringno"info", "warning", "critical"

play_media

Send a media playback command to a device.

ParameterTypeRequiredDescription
mediaIdstringyesID of the media file
deviceIdstringyesTarget device

capture_camera

Trigger an immediate camera capture and vision analysis.

ParameterTypeRequiredDescription
cameraIdstringyesCamera to capture from

Returns the vision analysis result.

ollama_query

Send a direct query to Ollama outside of a conversation context.

ParameterTypeRequiredDescription
promptstringyesThe query to send
modelstringnoOverride the default model

read_memory

Query the memory system.

ParameterTypeRequiredDescription
categorystringnoFilter by category
searchstringnoFull-text search

update_memory

Create or update a memory entry.

ParameterTypeRequiredDescription
categorystringyesMemory category
keystringyesEntry key
valuestringyesEntry value

fetch_url

Make an HTTP request to an external URL.

ParameterTypeRequiredDescription
urlstringyesTarget URL
methodstringnoHTTP method (default: "GET")
bodyobjectnoRequest body (for POST/PUT)
headersobjectnoCustom headers

create_reminder

Create a reminder with optional recurrence.

ParameterTypeRequiredDescription
titlestringyesReminder text
dueAtstringyesISO 8601 datetime
repeatstringnoRepeat schedule (cron expression or keyword)

REST API

MethodPathDescription
GET/api/actionsList all registered actions
POST/api/actions/[name]/executeExecute an action by name

Execute via API

curl -X POST http://localhost:3000/api/actions/send_notification/execute \
-H "Content-Type: application/json" \
-d '{"title": "Test", "body": "Hello from API", "target": "all"}'

Key Files

FilePurpose
lib/actions/registry.tsActionRegistry class
lib/actions/index.tsRegisters all built-in actions
lib/actions/send-notification.tsNotification action
lib/actions/play-media.tsMedia playback action
lib/actions/capture-camera.tsCamera capture action
lib/actions/ollama-query.tsDirect Ollama query
lib/actions/read-memory.tsMemory read action
lib/actions/update-memory.tsMemory write action
lib/actions/fetch-url.tsHTTP fetch action
lib/actions/create-reminder.tsReminder creation action