AI Integration & Agents
Relevant source files
The following files were used as context for generating this wiki page:
Budibase integrates Artificial Intelligence to enhance application capabilities, primarily through two features: AI Agents and AI-powered Automations. AI Agents are conversational bots that can interact with Budibase data and services using a defined set of tools. They are designed to understand user goals and execute tasks within the platform.
AI is also leveraged in automation workflows to perform complex tasks like extracting structured data from unstructured files. This system is built to be extensible, allowing for different AI providers and models to be configured and used across the platform, providing a powerful layer of intelligence for custom business applications.
AI Agents
AI Agents are configurable entities that can perform tasks and engage in conversations. Each agent is defined by its purpose, instructions, and a set of tools it can use to interact with the Budibase environment.
Agent Core Concepts
An agent's behavior is determined by its configuration. The core properties of an agent are defined in the CreateAgentRequest type.
| Property | Type | Description |
|---|---|---|
name | string | The display name of the agent. |
description | string | A brief description of what the agent does. |
aiconfig | string | The ID of the AI configuration (provider and model) to use. |
promptInstructions | string | Specific instructions for the AI model on how to behave. |
goal | string | The primary objective or goal of the agent. |
icon | string | An icon to represent the agent. |
iconColor | string | The color for the agent's icon. |
live | boolean | A flag to indicate if the agent is active. |
enabledTools | string[] | An array of tool names that the agent is permitted to use. |
createdBy | string | The ID of the user who created the agent. |
Sources: packages/types/src/api/web/ai.ts:101-120, packages/server/src/sdk/workspace/ai/agents/crud.ts:11-26
Agent Management (CRUD)
The packages/server/src/sdk/workspace/ai/agents/crud.ts file provides the core logic for creating, reading, updating, and deleting agents. These functions interact directly with the workspace database to manage agent documents.
The following diagram shows the lifecycle of an agent managed via API endpoints.
This diagram illustrates the CRUD operations for AI agents, flowing from the client request to the database.
Sources: packages/server/src/sdk/workspace/ai/agents/crud.ts, packages/server/src/api/controllers/ai/agents.ts:153-214
Agent Chat Interaction
Users can interact with agents through a streaming chat interface. The agentChatStream controller handles these interactions.
The process is as follows:
- A chat request is received at the
POST /api/ai/agents/:agentId/chatendpoint. - The server sets up a Server-Sent Events (SSE) connection for streaming the response.
- The agent's configuration, system prompt, and available tools are loaded.
- The AI model is invoked with the conversation history and tools using the
streamTextfunction from theailibrary. - The AI's response, including its thought process and tool usage, is streamed back to the client.
- Once the interaction is complete, the entire conversation is saved to the database as an
AgentChatdocument.
The following sequence diagram illustrates the chat flow:
This diagram shows the sequence of events during a streaming chat session with an AI agent.
Sources: packages/server/src/api/controllers/ai/agents.ts:20-100
Chat History
Chat history is stored in the database to provide context for future interactions.
| Property | Type | Description |
|---|---|---|
_id | string | The unique ID of the chat session. |
agentId | string | The ID of the agent involved in the chat. |
title | string | A title for the chat, generated by the AI if not provided. |
messages | CoreMessage[] | An array of messages in the conversation. |
createdAt | string (ISO Date) | Timestamp of when the chat was created. |
Sources: packages/types/src/api/web/ai.ts:88-99, packages/server/src/api/controllers/ai/agents.ts:88-97
Agent Tools
Tools are functions that an AI agent can invoke to interact with its environment, such as querying a database or fetching data. These tools are defined in the backend and passed to the AI model, which decides when to use them based on the user's request.
The buildPromptAndTools function is responsible for gathering the agent's enabled tools and preparing them for the AI model.
Sources: packages/server/src/sdk/workspace/ai/agents/crud.ts:74-95
Available Tools
The following tools are available for agents to use:
| Tool Name | Description | Source File |
|---|---|---|
createQuery | Creates a new query. | packages/server/src/ai/tools/index.ts:16-20 |
deleteRow | Deletes a row from a table. | packages/server/src/ai/tools/index.ts:21-25 |
executeQuery | Executes a query and returns the result. | packages/server/src/ai/tools/index.ts:26-30 |
getSchema | Retrieves the schema of all available tables. | packages/server/src/ai/tools/index.ts:31-35 |
updateRow | Updates a row in a table. | packages/server/src/ai/tools/index.ts:36-40 |
createRow | Creates a new row in a table. | packages/server/src/ai/tools/index.ts:41-45 |
AI in Automations
Budibase leverages AI within its automation engine to perform intelligent data processing tasks.
Extract File Data Step
The extractFileData automation step is designed to extract structured JSON data from a file (e.g., a PDF or text file) based on a provided schema.
Inputs:
| Name | Type | Description |
|---|---|---|
file | object or string | The file to process. Can be an attachment object from a Budibase DB or a URL string. |
source | string | The source of the file. Either ATTACHMENT or URL. |
schema | object | A JSON object describing the desired structure of the output data (e.g., { "name": "string", "age": "number" }). |
Outputs:
| Name | Type | Description |
|---|---|---|
data | object | The extracted data in JSON format. |
success | boolean | true if the extraction was successful. |
Sources: packages/server/src/automations/steps/ai/index.ts:17-43, packages/server/src/automations/tests/steps/extractFileData.spec.ts:50-62
The following diagram illustrates the workflow of the extractFileData step.
This flowchart shows the process of extracting structured data from a file using an AI automation step.
Sources: packages/server/src/automations/steps/ai/index.ts:45-121, packages/server/src/automations/tests/steps/extractFileData.spec.ts
AI Table Generation
Budibase includes an experimental feature to generate entire database tables, including schemas and sample data, from a single text prompt. This is exposed via the POST /api/ai/tables endpoint.
The process involves multiple calls to the AI model:
- Generate Structure: The AI first generates a
GenerationStructurewhich defines the tables, columns, types, and relationships. - Generate AI Columns: The AI suggests
AItype columns (e.g., for summarization or categorization) based on the initial schema. - Generate Data: The AI generates realistic sample data for the defined tables.
- Create Resources: The Budibase server then creates the tables, columns, and rows based on the AI-generated definitions and data.
Sources: packages/server/src/api/routes/tests/ai.spec.ts:404-688
Summary
The AI integration in Budibase provides a powerful toolkit for building intelligent applications. AI Agents offer a conversational interface for interacting with app data and services, leveraging a flexible system of tools. In parallel, AI-powered automation steps, like extractFileData, streamline complex data processing tasks by converting unstructured content into structured, usable data. Together, these features enable developers to create more dynamic, responsive, and intelligent solutions within the Budibase ecosystem.