Custom functions

A custom function is short TypeScript code that your agent uses as a tool. You define what data it receives, what it does and what it returns. Platic checks the code, runs it in isolation, and the agent sees it as fn_<name>.

Open Integraciones → Funciones → Funciones personalizadas (Integrations → Functions → Custom functions).

This screen is currently shown in Spanish. Button and tab names below appear as they do in the app, with their meaning in parentheses the first time.

When to use a function

Use a function for tasks that need your rules or combine several operations:

  • Calculations with your own rules: quotes, commissions, delivery dates or taxes, always with the same formula.
  • Availability and orders: query your systems and combine stock, order status or a delivery date in one response.
  • Actions in your systems: create a request or record a booking with the validations you define.
  • Special integrations: prepare a signature, request a token or adapt a SOAP or XML service response.

If it is a single call to a JSON endpoint and the agent can use the response as is, use a REST API: it is configured without code.

Review the list

The screen shows how many functions you have and how many calls you have made today and this month against your limits. Filter by Todas (All), Activas (Active), Borradores (Drafts) or Pausadas (Paused), or search by name. Each function shows its status, its published version and its last run.

Cómo funcionan (How they work) opens a help panel with the code format, the allowed packages, what cannot be used and the limits.

Create the function

  1. Click Crear función (Create function), or the + button if you already have functions.
  2. In Nombre (Name), enter how you will see it in Platic, for example "Calculate shipping cost".
  3. In Nombre de la herramienta (Tool name), enter the technical name using lowercase letters, numbers and underscores. The agent will see it as fn_<name>. It cannot be changed later.
  4. In Qué hace (What it does), describe what it does and when to use it. The agent reads this description to decide when to call it.
  5. Optional: add the Dominios permitidos (Allowed domains), the only domains the function will be able to call.
  6. Click Crear función.

The function is created as a draft and its editor opens. No agent sees it yet.

Write the code

In the Código (Code) tab, the editor starts with a template. This is a complete function:

import { z } from 'zod';
import { defineFunction } from '@platica/functions';

export default defineFunction({
  input: z.object({
    rfc: z.string().describe('Customer tax ID (RFC), 12 or 13 characters')
  }),
  async run(input, { http, secrets, log }) {
    const res = await http.fetch('https://api.example.com/v1/rfc', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${secrets.API_KEY}` },
      body: JSON.stringify({ rfc: input.rfc })
    });
    if (res.status !== 200) return { found: false };
    log.info('response', { status: res.status });
    return { found: true, name: res.json().razon_social };
  }
});
  • input says what data the agent sends. The description of each field tells it what to put.
  • run does the work and returns an object. That is what the agent receives.
  • http.fetch is the only way to call another service.
  • secrets.API_KEY stands for a credential stored in Secrets. The function never sees the real value.
  • log.info leaves notes that you will see in the runs.

Click Verificar (Verify) to check the code without running it. If there are errors, the list shows them with their line; click one to jump to that line. Click Guardar (Save), or press ⌘S, to save the draft. Saving does not change what agents use: they only use what is published.

What the code can and cannot do

It can:

  • call the allowed domains over HTTPS, up to 20 times per run;
  • use the allowed packages: zod, date-fns, decimal.js, papaparse, lodash-es and fast-xml-parser;
  • read the secrets you connected, always through secrets;
  • calculate, transform data and return a result.

It cannot:

  • call domains that are not on the list, or use fetch, XMLHttpRequest or sockets: use http.fetch;
  • read or write files, or start processes;
  • read environment variables: secrets are read with secrets.NAME;
  • generate code on the fly with eval, new Function or import();
  • keep running: the function ends when it returns its result;
  • import packages that are not on the list.

Verificar rejects code that uses anything forbidden, before anything is deployed.

Connect the secrets

If the function uses a credential, such as an API key:

  1. Open Configuración (Settings) and add the service's domain under Dominios permitidos.
  2. Under Secretos (Secrets), click Agregar secreto (Add secret).
  3. In Nombre del secreto (Secret name), enter the name the code uses, in uppercase: if the code reads secrets.API_KEY, enter API_KEY.
  4. In Dominio al que se manda (Domain it is sent to), choose the service's domain. It is the only destination the value will travel to.
  5. Click Guardar configuración (Save settings).
  6. In Secreto conectado (Connected secret), choose a stored secret or create one. When the slot says Listo (Ready), the secret is connected.

The value never reaches the function: Platic adds it as the call goes out, and only toward the domain you chose. If the code tried to send it elsewhere, a placeholder with no value would go instead. Logs and runs do not store it either.

While a secret is missing, the editor shows a notice with Conectar en Configuración (Connect in Settings). If you change the domains or the secrets, you may need to choose it again.

Test the function

  1. Open Prueba (Test).
  2. Choose Borrador (Draft) to test the code in the editor, even if you have not saved it. Publicada (Published) runs the version agents use.
  3. Fill in the input fields. If you prefer, click Escribir JSON (Write JSON).
  4. Click Probar borrador (Test draft) or Correr versión publicada (Run published version).
  5. Review the Salida (Output), Registros (Logs) and Llamadas HTTP (HTTP calls).

The test makes real calls to the allowed domains: if the function creates or changes something in another system, the test does too. Testing the draft does not affect agents.

If the test fails, the result says why. For example, that a secret is not connected, that the function called a domain that is not allowed, or that it took longer than its time limit.

Publish and connect to an agent

  1. Click Publicar (Publish).
  2. Optional: write the Notas de la versión (Version notes), to remember what changed.
  3. Click Publicar in the confirmation.

Platic saves your code, verifies it and publishes it as a new version. Agents that already use the function switch to this version immediately. If the last verification had errors, fix them before publishing.

Publishing does not give the function to any agent. To connect it:

  • open the agent's Tools, filter by function type and check the function; or
  • ask the Agent Creator.

Configuración → Agentes que la usan (Agents that use it) shows which agents have it.

Use the Agent Creator

The Agent Creator also writes functions. Describe what you need, for example "calculate shipping cost from the postal code, package weight and my store’s rates", and it writes the code, verifies it, tests it, publishes it and connects it to the agent you have open.

The Creator never asks for a secret's value in the chat. When one is missing, it shows a card where you choose or create the secret.

Versions and going back

Each publication creates a version that no longer changes. Versiones (Versions) lists each one with its date and notes; the one agents use says En uso (In use).

  • Ver código (View code) shows that version's code.
  • Regresar a esta (Go back to this one) makes that version live, with its code, domains, time limit and secrets. Your draft does not change.

Use it if a new version causes problems: agents go back to the previous one immediately.

Review the runs

Ejecuciones (Runs) shows every time an agent, you or a test ran the function. Filter by Origen (Source: Agente, Manual or Prueba) and by Resultado (Result). Open one to see the agent and the conversation, the input, the output, the logs and the HTTP calls.

A successful run confirms that case; it does not guarantee that every future call will succeed.

Adjust the settings

In Configuración you can change the name, the description, the Tiempo máximo (Time limit, from 1 to 60 seconds), the allowed domains and the secrets. Click Guardar configuración.

These changes stay in the draft. If the function is already published, publish again so agents use them.

Pause or delete

  • Pausar función (Pause function) makes agents stop using it. The code, the versions and the agent connections are kept. Activar función (Enable function) brings it back with the published version.
  • Eliminar función (Delete function) removes it from agents and deletes its versions. It cannot be undone. Secrets stay in Secrets.

Pausing does not undo what the function already did in other systems. Both actions are in Configuración → Estado y eliminación (Status and deletion) and in each function's menu in the list.

Limits

WhatLimit
Functions per workspace20
Calls60 per minute per function; 5,000 per day and 50,000 per month per workspace
Time limit per run1 to 60 seconds (20 by default)
Memory256 MB
Input and output256 KB each. The agent reads up to 16,000 characters of the output
HTTP calls per run20
Allowed domains10 per function
Secrets10 per function
Publications and tests50 per day

When a limit is reached, the function returns an error and the agent does not retry until it resets.

From the API, the SDK or MCP

Functions can also be managed from the REST API, the SDK (platic.tools.functions) and the MCP server, for example to keep the code in your repository and publish it from your CI. Secret values never go through those channels: they are connected in Platic.

You need access to Integrations. Connecting a secret also requires permission to use Secrets.