State scopes
| Scope | Persists across | Defined in | Accessed via |
|---|---|---|---|
| Bot | All users and conversations | agent.config.ts | import { bot } from "@botpress/runtime" |
| User | All conversations for a given user | agent.config.ts | import { user } from "@botpress/runtime" |
| Conversation | A single conversation | Conversation state prop | Handler’s state parameter |
Defining state schemas
Bot and user state
Define bot and user state inagent.config.ts:
.default() to set initial values and .describe() to document what each field is for.
Conversation state
Define conversation state on aConversation using the state prop:
Reading and writing state
State objects are mutable and can be modified directly. Your changes are saved automatically—you don’t need to call a save method.Bot state
You can access bot state anywhere in your agent (conversations, actions, tools, workflows):User state
You can access user state anywhere the current user context exists:Conversation state
You can access conversation state via thestate parameter in the conversation handler:
Loading by ID
You can load any user or conversation by ID to read and write their state and tags from anywhere in your agent:State references
You can store workflow instances in state. They are saved automatically and loaded back as full instances when read:Tags
Tags are string key-value pairs you can attach to bots, users, conversations, messages, and workflows. They’re useful for categorization, filtering, and querying.Defining tags
Declare tags inagent.config.ts:
Reading and writing tags
conversation instance:
:) are read-only:
Bot and user identity
Thebot and user objects also expose an id property: