Tables define data storage schemas for your agent. They provide structured storage that’s automatically synced with Botpress Cloud and accessible throughout your agent.
Creating a table
Create a table definition in src/tables/:
import { Table , z } from "@botpress/runtime" ;
export default new Table ({
name: "PricingTable" ,
columns: {
itemName: z . string (),
price: z . string (),
},
});
Naming a table
To properly deploy your agent, make sure your table name follows the correct convention:
Cannot start with a number
Must be 30 characters or less
Can contain only letters, numbers, and underscores
Must end with Table
Table schema
Simple definition
Define your table using Zod schemas:
export default new Table ({
name: "OrderTable" ,
columns: {
userId: z . string (),
items: z . array ( z . string ()),
total: z . number (),
status: z . string (),
createdAt: z . string (). datetime (),
updatedAt: z . string (). datetime (),
},
});
Extended definition
You can also define table columns with additional options for each column:
import { Table , z } from "@botpress/runtime" ;
export default new Table ({
name: "OrderTable" ,
columns: {
itemName: {
schema: z . string (),
searchable: true
},
price: {
schema: z . string (),
searchable: true
}
},
});
Check out the column options in the Table props reference for a full overview of the available options.
Using tables
Tables are automatically created and synced when you deploy. Access them using the Botpress client:
export default new Workflow ({
name: "createOrder" ,
handler : async ({ client }) => {
await client . upsertTableRows ({
table: "OrderTable" ,
rows: [{
// Order data
}]
})
},
});
Reference
Unique name for the table. Must be 30 characters or less, cannot start with a number, can contain only letters, numbers, and underscores, and must end with ‘Table’.
Optional description of what the table stores.
Optional factor for table operations. Defaults to 1.
Object mapping column names to their definitions. Each key is a column name. Values can be either a simple Zod schema or an object with advanced column configuration options. Show simple column definition
Zod schema defining the column’s data type and validation rules.
Show advanced column definition
Zod schema defining the column’s data type and validation rules.
Whether this column is computed from other columns. Defaults to false.
Whether this column should be searchable. Defaults to false.
Array of column names this computed column depends on. Required for computed columns.
value
(row: any) => Promise<any>
Async function that computes the column value from the row data. Required for computed columns.
Tables are automatically synced with Botpress Cloud. When you deploy your agent, table schemas are created or updated to match your definitions.