Overview
Agents module for managing AI agent conversations. This module provides methods to create and manage conversations with AI agents, send messages, and subscribe to realtime updates. Conversations can be used for chat interfaces, support systems, or any interactive AI app.Key Features
The agents module enables you to:- Create conversations with agents defined in the app.
- Send messages from users to agents and receive AI-generated responses.
- Retrieve conversations individually or as filtered lists with sorting and pagination.
- Subscribe to realtime updates using WebSocket connections to receive instant notifications when new messages arrive.
- Attach metadata to conversations for tracking context, categories, priorities, or linking to external systems.
- Generate WhatsApp connection URLs for users to interact with agents through WhatsApp.
Conversation Structure
The agents module operates with a two-level hierarchy:- Conversations: Top-level containers that represent a dialogue with a specific agent. Each conversation has a unique ID, is associated with an agent by name, and belongs to the user who created it. Conversations can include optional metadata for tracking app-specific context like ticket IDs, categories, or custom fields.
- Messages: Individual exchanges within a conversation. Each message has a role, content, and optional metadata like token usage, tool calls, file attachments, and reasoning information. Messages are stored as an array within their parent conversation.
Authentication Modes
This module is available to use with a client in all authentication modes:- Anonymous or User authentication (
base44.agents): Access is scoped to the current user’s permissions. Users must be authenticated to create and access conversations. - Service role authentication (
base44.asServiceRole.agents): Operations have elevated admin-level permissions. Can access all conversations that the app’s admin role has access to.
Generated Types
If you’re working in a TypeScript project, you can generate types from your agents to get autocomplete on agent names when creating conversations or subscribing to updates. See the Dynamic Types guide to get started.Methods
getConversations()
getConversations():Gets all conversations from all agents in the app. Retrieves all conversations. UsePromise<AgentConversation[]>
listConversations() to filter which conversations are returned, apply sorting, or paginate results. Use getConversation() to retrieve a specific conversation by ID.
Returns
AgentConversation
An agent conversation containing messages exchanged with an AI agent.
Properties
Properties
Unique identifier for the conversation.
App ID.
Name of the agent in this conversation.
ID of the user who created the conversation.
When the conversation was created.
When the conversation was last updated.
Array of messages in the conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Optional metadata associated with the conversation.
Example
See
listConversations()for filtering, sorting, and paginationgetConversation()for retrieving a specific conversation by ID
getConversation()
getConversation(Gets a specific conversation by ID. Retrieves a single conversation using its unique identifier. To retrieve all conversations, useconversationId):Promise<AgentConversation|undefined>
getConversations(). To filter, sort, or paginate conversations, use listConversations().
This function returns the complete stored conversation including full tool call results, even for large responses.
Parameters
The unique identifier of the conversation.
Returns
AgentConversation
An agent conversation containing messages exchanged with an AI agent.
Properties
Properties
Unique identifier for the conversation.
App ID.
Name of the agent in this conversation.
ID of the user who created the conversation.
When the conversation was created.
When the conversation was last updated.
Array of messages in the conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Optional metadata associated with the conversation.
Example
See
getConversations()for retrieving all conversationslistConversations()for filtering and sorting conversations
listConversations()
listConversations(Lists conversations with filtering, sorting, and pagination. Provides querying capabilities including filtering by fields, sorting, pagination, and field selection. For cases where you need all conversations without filtering, usefilterParams):Promise<AgentConversation[]>
getConversations(). To retrieve a specific conversation by ID, use getConversation().
Parameters
Filter parameters for querying conversations.
Properties
Properties
Query object with field-value pairs for filtering.
Sort parameter. For example, “-created_date” for descending order.
Alternative sort parameter. Use either
sort or sort_by.Maximum number of results to return.
Number of results to skip. Used for pagination.
Array of field names to include in the response.
Returns
AgentConversation
An agent conversation containing messages exchanged with an AI agent.
Properties
Properties
Unique identifier for the conversation.
App ID.
Name of the agent in this conversation.
ID of the user who created the conversation.
When the conversation was created.
When the conversation was last updated.
Array of messages in the conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Optional metadata associated with the conversation.
Examples
See
getConversations()for retrieving all conversations without filteringgetConversation()for retrieving a specific conversation by ID
createConversation()
createConversation(Creates a new conversation with an agent.conversation):Promise<AgentConversation>
Parameters
Conversation details including agent name and optional metadata.
Properties
Properties
Returns
AgentConversation
An agent conversation containing messages exchanged with an AI agent.
Properties
Properties
Unique identifier for the conversation.
App ID.
Name of the agent in this conversation.
ID of the user who created the conversation.
When the conversation was created.
When the conversation was last updated.
Array of messages in the conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Optional metadata associated with the conversation.
Example
addMessage()
addMessage(Adds a message to a conversation. Sends a message to the agent and updates the conversation. This method also updates the realtime socket to notify any subscribers.conversation,message):Promise<AgentMessage>
Parameters
Properties
Properties
The conversation to add the message to.
Properties
Properties
Unique identifier for the conversation.
App ID.
Name of the agent in this conversation.
ID of the user who created the conversation.
When the conversation was created.
When the conversation was last updated.
Array of messages in the conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Optional metadata associated with the conversation.
The message to add.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Returns
AgentMessage
A message in an agent conversation.
Properties
Properties
Unique identifier for the message.
Role of the message sender.
When the message was created.
When the message was last updated.
Message content.
URLs to files attached to the message.
Tool calls made by the agent.
Whether the message is hidden from the user.
Model used to generate the message.
Checkpoint ID for the message.
Additional custom parameters for the message.
Example
subscribeToConversation()
subscribeToConversation(Subscribes to realtime updates for a conversation. Establishes a WebSocket connection to receive instant updates when new messages are added to the conversation. Returns an unsubscribe function to clean up the connection.conversationId,onUpdate?): () =>void
When receiving messages through this function, tool call data is truncated for efficiency. The
arguments_string is limited to 500 characters and results to 50 characters. The complete tool call data is always saved in storage and can be retrieved by calling getConversation() after the message completes.Parameters
Properties
Properties
The conversation ID to subscribe to.
Callback function called when the conversation is updated. The callback receives a conversation object with the following properties:
id: Unique identifier for the conversation.agent_name: Name of the agent in this conversation.created_date: ISO 8601 timestamp of when the conversation was created.updated_date: ISO 8601 timestamp of when the conversation was last updated.messages: Array of messages in the conversation. Each message includesid,role('user','assistant', or'system'),content,created_date, and optionallytool_calls,reasoning,file_urls, andusage.metadata: Optional metadata associated with the conversation.
Returns
Unsubscribe function to stop receiving updates.Example
getWhatsAppConnectURL()
getWhatsAppConnectURL(Gets WhatsApp connection URL for an agent. Generates a URL that users can use to connect with the agent through WhatsApp. The URL includes authentication if a token is available.agentName):string
Parameters
The name of the agent.
Returns
string
WhatsApp connection URL.
Example
Type Definitions
AgentName
AgentName = keyofUnion of all agent names from theAgentNameRegistryextendsnever?string: keyofAgentNameRegistry
AgentNameRegistry. Defaults to string when no types have been generated.
Example
AgentNameRegistry
Registry of agent names. The
types generate command fills this registry, then AgentName resolves to a union of the keys.
