# AI bot - Aangepaste tools

**URL:** https://meta.discourse.org/t/ai-bot-custom-tools/314103
**Category:** Site Management
**Tags:** how-to, ai, ai-bot
**Created:** [28 juni 2024 om 01:20 UTC](https://meta.discourse.org/t/ai-bot-custom-tools/314103 "2024-06-28T01:20:38Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [28 juni 2024 om 01:20 UTC](https://meta.discourse.org/t/ai-bot-custom-tools/314103/1 "2024-06-28T01:20:39Z")

</div>

> 🔖 This guide explains how to create, configure, and integrate custom AI tools within the Discourse AI plugin, enabling administrators to extend the bot’s capabilities with user-defined JavaScript functions.
> 
> 🙋 Required user level: Administrator

Tools are programmable functionalities that can be used by the AI bot to perform specific tasks or retrieve information beyond just text-based responses. These tools are scripts or integrations that allow the bot to interact with external APIs, manipulate data, or execute additional functions to extend its capabilities.

## Summary

This documentation covers:

- Creating a new custom AI tool
- Configuring tool parameters and scripts
- Available APIs for tool scripts
- Integrating custom tools with AI personas
- Testing and troubleshooting custom tools

## Creating a new custom AI tool

To create a new AI tool:

1. Navigate to Admin Panel \> Plugins \> Discourse AI \> Tools
2. Click “New Tool” (you can use existing presets to learn about options)
3. Fill in the following fields:
  - Name: The name of the tool as presented to the LLM
  - Description: The description of the tool as presented to the LLM
  - Summary: Summary of what tool does to assist users (displayed in details)
  - Parameters: Define the inputs your tool needs as presented to LLM
  - Script: The JavaScript code that powers your tool

4. Click “Save”

 ![New AI Tool Interface](https://global.discourse-cdn.com/meta/original/4X/6/6/3/66324f9574cb850670c1c907c04d8b0825fd2338.png)

 ![This image shows a user interface window with various options, including a selected preset titled "Stock quote (AlphaVantage)" and other tools like browsing the web using jina.ai, exchange rate, and starting from a blank state. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/1/b/d/1bdfe356c643e9e6c802eaf5f4fb5cbeb6f32eaa.png)

 ![The image shows a script interface titled "stock_quote" that retrieves real-time stock quote information using the AlphaVantage API, with parameters for entering a stock symbol and displaying the code for making the API call and handling the response data. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/3/d/9/3d90f767edc63ba9700a8dba2b40c318ee65fd51.png)

## Configuring tool scripts

### Available APIs

Your tool scripts have access to the following APIs:

1. **HTTP Requests:**

2. **LLM (Language Model) Integration:**

3. **Custom upload integration (RAG)**

4. **Upload support**

5. **Execution chain control**

6. **Secrets management**

7. **Discourse integration**

8. **Context object**

### Required functions

Your script must implement:

- `invoke(params)`: The main function that executes when the tool is called

It may optionally implement:

- `details()`: Returns a string (can include basic HTML) describing the tool’s execution, displayed in the chat interface
- `customSystemMessage()`: Called during prompt assembly (not during tool invocation). Returns a string appended to the system prompt, or `null`/`undefined` to skip. Has access to `context`, `discourse`, and `index` objects.

Example script:

```javascript
function invoke(params) {
  let result = http.get("https://api.example.com/data?query=" + params.query);
  return JSON.parse(result.body);
}

function details() {
  return "Fetched data from Example API";
}

```

## Limitations and security

- **Execution Timeout:** Default timeout of 2000ms of script processing time. The timer pauses during external HTTP requests (`http.*`) and LLM calls (`llm.generate`), so only the script’s own processing time counts.
- **Memory:** Maximum 10MB V8 heap limit
- **HTTP Requests:** Maximum of 20 requests per tool execution
- **Sandboxed Environment:** Scripts run in a restricted V8 JavaScript environment (via MiniRacer). No access to browser globals, the host file system, or server-side libraries. Network requests are proxied through the Discourse backend.

## Testing your tool

You should test any tool you build to ensure the results the LLM will be provided with match your expectations.

 ![Testing Interface](https://global.discourse-cdn.com/meta/original/4X/a/8/c/a8c115668a6c7297795cd10a694c6f064b02a8f7.png)

## Integrating tools with AI personas

To add your custom tool to an AI Persona:

1. Go to Admin Panel \> Plugins \> Discourse AI \> Personas
2. Edit an existing persona or create a new one
3. In the “Tools” section, you’ll see your custom tools listed alongside built-in tools
4. Select your custom tool to add it to the persona

 ![This image shows a list of enabled tools or plugins in an interface, including options like JavaScript Evaluator, GitHub Search Code, Tags, Image, Dall-E, Google, and a custom tool named "Stock_quote". (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/b/2/a/b2a5db3b395f5e40f402dab41e958094468d83af.png)

## Custom tools in action

Once you provide the custom tool to your LLM it can use it to enhance the conversation.

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/6/0/a60dda461c76a0ccb7f8b7747d4ede7d3531e68e.png)

## Troubleshooting

If your tool isn’t working as expected:

1. Use the Test interface to ensure it behaves as expected for your inputs.
2. Ensure your group is in `ai_bot_debugging_allowed_groups`. Members of this group have full access to the bot transcripts; you can view the AI logs there.
3. If anything unexpected is happening, visit `https://SITENAME/logs` to check for errors.

## Additional resources

> [@Discourse AI - AI bot](https://meta.discourse.org/t/discourse-ai-ai-bot/266012):
>
> bookmark This guide explains how to enable and configure the AI bot feature of the [Discourse AI](https://meta.discourse.org/t/discourse-ai/259214) plugin. person_raising_hand Required user level: Administrator The smart chatbot can answer all questions about your Discourse community and more. The AI Bot has the power to search through your current Discourse instance and beyond with agent support to answer any type of questions you might have. Features Ability to pick the specific AI Bot agent you want to interact with Flexibili…

> [@AI bot - Agents](https://meta.discourse.org/t/discourse-ai-persona-guide/306099):
>
> bookmark This guide explains how to set up and manage Agents for [Discourse AI - AI bot](https://meta.discourse.org/t/discourse-ai-ai-bot/266012). person_raising_hand Required user level: Administrator The Discourse AI bot includes a flexible system for managing Agents. This guide covers: Interaction methods for AI Agents Configuration options Advanced settings Supported tools Customization possibilitieslink Learn about the AI bot and how to enable it [in this guide](https://meta.discourse.org/t/discourse-ai-ai-bot/266012?silent=true). What are agents? Agents are a powerful feature that allows you to cust…

> Last edited by @Saif 2025-03-17T19:29:43Z
> 
> Last checked by @hugh 2024-08-06T02:00:12Z
> 
> > **Check document**
> >
> > Perform check on document:

---

_[View the full topic](https://meta.discourse.org/t/ai-bot-custom-tools/314103)._
