Core Language Constructs
Based is built around a set of specialized constructs designed specifically for conversational AI workflows. These constructs provide a high-level abstraction that makes it easy to build complex interactions without getting lost in implementation details.The say Function
The say function generates a response from the AI to the user without expecting a reply. It’s typically used to provide information, instructions, or acknowledgments.
Syntax:
message(string): The content to be processed and presented to the userexact(boolean, optional): Controls how the message is processedTrue(default): Outputs exactly what’s provided in the message parameter, verbatimFalse: Allows the AI to rephrase the message while maintaining its meaning
- Returns the response text, which can be stored in a variable for later use or simply executed for its side effect
The loop, talk, and until Pattern
In Based, the loop, talk, and until constructs form an essential pattern that must be used together. This pattern creates interactive conversation flows that can repeat until specific conditions are met. The talk function is not meant to be used in isolation.
Syntax:
talk:
system_prompt(string): Instruction or prompt that guides the conversationfirst_prompt(boolean, optional): Controls conversation initiationTrue(default): AI starts by sending the prompt message to the userFalse: AI waits for the user to send a message first
default_values(dict, optional): Example values to structure expected responsesinfo(dict, optional): Additional context for the conversation
- The
loopkeyword begins a repeatable conversation block - The
talkfunction within the loop handles the conversation exchange - The
untilclause specifies a condition (in natural language) under which the loop should end - The code block after
untilvalidates whether the condition has been met- If the condition is met (the code executes successfully), the loop exits
- If the condition is not met, the loop repeats from the beginning
Data Processing Methods
Based provides powerful methods to transform and extract information from data objects. These methods can be applied to any data object, not just conversation responses.The .ask Method
The .ask method extracts structured data from any data object, transforming unstructured content into well-formed data that can be used programmatically. This method can be used with API responses, conversation results, or any other data.
Syntax:
question(string): Instruction for extracting specific information from the dataexample(dict, optional): Example object showing the expected output formatschema(dict, optional): JSON schema defining the expected structuremodel(string, optional): AI model to use for extraction
- Returns structured data according to the example or schema provided
State Management and Persistence
Based automatically persists variables across conversation turns, allowing you to maintain context throughout a multi-turn conversation. Understanding how state works is essential for building stateful agents.The state Dictionary
The state dictionary is the primary way to store and retrieve data that should persist across conversation turns. It’s automatically saved and restored between interactions.
Usage:
Variable Persistence Example
Here’s a complete example showing how variables persist across conversation turns:Variables defined at the top level of your Based code (like
state = {}) are automatically persisted across conversation turns. The session maintains the complete execution state, so your agent can pick up right where it left off.Advanced Patterns
Multiple until Statements
Based allows for sophisticated conversation flows by supporting multiple until statements. Each until block represents a different condition and can trigger different handling paths.
Tool Schema Until Conditions
Beyond simple string conditions, Based supports tool schema until conditions that allow you to define structured data extraction directly in theuntil clause. This enables the LLM to extract typed parameters when a condition matches, providing structured data for your flow logic.
Defining Tool Schemas
Tool schemas can be defined using either a simplified format or the full OpenAI tool format: Simplified Format:Using Tool Schemas in Until Conditions
Once you’ve defined a tool schema, you can use it in anuntil clause. The AI will match user intent to the tool’s description and extract the specified parameters.
Basic Syntax (without binding):
as):
Complete Example: Mixed Conditions
You can mix string conditions with tool schema conditions in the same loop. The first matching condition is triggered:Tool schema conditions provide type-safe parameter extraction. The LLM will attempt to extract all specified parameters based on the conversation context. Required parameters should be marked in the schema’s
required array.Conditional Flow Control
Based scripts can implement conditional flow control using standard Python syntax, allowing for dynamic conversation paths based on user responses.Platform-Specific Functions
Based supports different deployment platforms (chat, voice, email, SMS) and provides specialized functions for each platform. These functions allow you to take advantage of platform-specific capabilities.Voice Deployment Functions
When your Based agent is deployed for voice conversations, you can use these special functions to control call flow:transfer(phone_number, options?)
Transfers the current call to another phone number. Optionally supports dialing extensions after the call connects.
Syntax:
phone_number(string): The destination phone number to transfer toextension(string, optional): Simple extension digits to dial after the call connectsoptions(dict, optional): Advanced transfer options with the following keys:extension(string): DTMF digits to send after the call connectspauseSeconds(number): Seconds to wait before sending digits (default: 1 second)
When transferring to extensions, the
pauseSeconds parameter controls how long to wait after the call connects before dialing the extension digits. The default of 1 second works for most phone systems, but you may need to increase this for systems that have longer greeting messages or slower IVR responses.end_call()
Ends the current call immediately. Use this to gracefully terminate a voice conversation after completing the interaction.
Syntax:
Built-in Utility Functions
Based provides built-in utility functions that are available in all deployments for common operations like debugging, notifications, and more.Print Line Debugging
Theprint function works like Python’s standard print, but outputs are captured and made available in the session trace for debugging purposes. This is invaluable for understanding flow execution and troubleshooting issues.
Syntax:
All print outputs appear in the session trace view, making it easy to debug conversation flows without interrupting the user experience. Print statements do not send messages to the user—they’re purely for developer debugging.
Sending SMS Messages with send_sms
The send_sms function allows you to send SMS messages programmatically from within your Based flow. This is useful for sending confirmations, notifications, or follow-up messages.
Syntax:
to(string, required): The recipient’s phone number in E.164 format (e.g.,"+12025551234")content(string, required): The SMS message content to sendfrom_number(string, required): Your phone number from your Brainbase phone number library
SMSResult object with the following properties:
Example:
send_sms function is designed to never interrupt your flow. All errors are captured in the result object, allowing you to handle failures gracefully:
The
from_number must be a phone number registered in your Brainbase phone number library with proper A2P (Application-to-Person) verification for SMS delivery compliance.Runtime Extractions with extract
The extract function allows you to save structured data directly from your Based flow as a runtime extraction. This is useful when the value you need is already available as a variable — there’s no need to wait for an AI-powered extraction from the transcript when you already have the data.
Runtime extractions are saved to the deployment log and work alongside AI-powered extractions configured in your deployment settings. Runtime extractions always take precedence over AI extractions for the same key.
Syntax:
key(string, required): A name for the extraction. Must not start with_(reserved for internal use).value(any JSON-serializable type, required): The data to save. Can be a string, number, boolean, list, or dictionary.
- Returns
None. The extraction is saved asynchronously in the background without blocking your flow.
Runtime extractions are only saved when your Based flow is running inside a deployment (i.e., there is a deployment log for the session). If no deployment log exists,
extract() calls are silently ignored. Extraction keys cannot start with _ as this prefix is reserved for internal metadata.Making HTTP Requests
Based provides the standard Pythonrequests module for making HTTP requests to external APIs. This gives you full compatibility with the widely-used requests library.
Examples:
.ask() with API Responses:
You can use the .ask() method on response data to extract structured information:
All HTTP requests are automatically logged in the session trace for debugging and observability. You can see request/response details, timing, and any errors in the trace view.
Legacy API Utility (Deprecated)
The legacyapi.get_req() and api.post_req() methods are still supported for backwards compatibility:
Third-Party Integrations
Based provides anintegrations client for connecting to third-party services configured in your Brainbase workspace.
Usage:
Integrations must be connected in your Brainbase workspace before they can be used in Based flows. See the Integrations documentation for setup instructions.
Full Example: Book Recommendation Agent
Here’s a complete example that demonstrates the various language constructs working together, including multipleuntil statements:
Conclusion
The Based language provides a powerful yet intuitive framework for building conversational agents. By mastering the core constructs—particularly the essentialloop-talk-until pattern—you can create sophisticated conversation flows that handle complex interactions while maintaining readability and maintainability.
Remember that Based is designed to be declarative, allowing you to focus on the “what” rather than the “how” of conversational AI. This approach dramatically reduces the amount of code needed to create powerful agents while increasing reliability and ease of maintenance.
The combination of the core language constructs with platform-specific functions allows you to build agents that take full advantage of each deployment platform’s unique capabilities while maintaining a consistent codebase and user experience.