Implementing a Custom Function with OpenAI Assistant Manager

Implementing a Custom Function with OpenAI Assistant Manager

In this tutorial, we will walk you through how to implement a custom function for your OpenAI Assistant in just a few steps.

Whether you want your assistant to interact with plugins, retrieve custom data, or automate tasks, custom functions give you the power to define exactly how your assistant behaves.

Step 1 – Register Your Function

To get started:

  1. Go to the Assistants > Functions tab in your WordPress dashboard.
  2. Click Add New Function.
  3. Provide:
    • A title for your function.
    • A clear description (what it does, when to use it).
    • Define your assistant function parameters using a JSON schema in the “JSON Object” field.

Example JSON

{
  "name": "find_courses",
  "description": "Search courses based on user preferences",
  "parameters": {
    "type": "object",
    "properties": {
      "level": {
        "type": "integer",
	"minimum": 7,
        "maximum": 8,
        "description": "Course level"
      },
      "region": {
        "type": "string",
        "description": "Region in France (e.g., Paris, Bordeaux)"
      },
      "location": {
        "type": "string",
        "description": "Specific location or city"
      },
      "title": {
        "type": "string",
        "description": "Search for course title (e.g., Business, Engineering)"
      }
    },
    "required": []
  },
  "strict": false
}

Step 2 – Assign the Function to an Assistant

Now that your function is registered:

  1. Go to Assistants
  2. Select your desired assistant.
  3. Use the checkboxes to assign your newly created function.

This step assigns the function(s) to your assistant, granting it permission to call them whenever they are relevant to the user’s request.

Step 3 – Setup Assistant Instructions

Navigate to the assistant’s System Instructions and modify the prompt to tell the assistant when and how to use the function.

For example:

“If the user asks to retrieve a course, use the find_courses function and pass the parameters.”

Providing these instructions helps guide the assistant’s decision-making process.

Step 4 – Add the Function’s Source Code

Now it’s time to wire up the function on the backend.

Use the following WordPress action hook:

add_action('oaiam_do_' . 'find_courses', function($output, $args) {

    // Custom logic using $args

    return $output;

}, 0, 2);

Replace find_courses with the actual name of your function.

Step 5 – Test and Monitor

To test your new setup:

  1. Start a new conversation with your assistant.
  2. Ask something that should trigger the function.

All function requests are logged under Assistants > Tool Calls, so you can verify arguments and responses.

This is useful for debugging and refining your function behavior.

Step 6 – Advanced Development

Need something more complex? Want to integrate external APIs or run background tasks? Our developers are available on a per-hour basis to help build custom solutions tailored to your needs.

Feel free to reach out with your project ideas, we’d love to help bring them to life.

Wrap Up

Custom functions in OpenAI Assistant Manager give you deep control over your assistant’s capabilities, all from inside WordPress.

Whether you are building a support bot, e-commerce assistant, or internal tool, functions are the key to intelligent, actionable AI.

Leave a Reply

About Rafasashi

Currently managing RECUWEB an IT Company providing cloud hosting and SaaS delivery model.

Related posts