Based Language Fundamentals
Welcome to the Based Language Fundamentals guide. This reference document provides a comprehensive explanation of Based’s core language constructs, their declaration syntax, arguments, and practical usage examples. Understanding these fundamentals will enable you to build sophisticated conversational agents with precision and confidence.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: Outputs exactly what’s provided in the message parameter, verbatimFalse(default): Allows the AI to rephrase the message while maintaining its meaning
model(string, optional): Specifies which AI model to use for processing the message (when exact=False)
- 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
The .summarize Method
The .summarize method creates a concise summary of the information contained in any data object. This is particularly useful for large text blocks or complex data structures.
Syntax:
prompt(string, optional): Specific instruction for creating the summarymodel(string, optional): AI model to use for summarization
- Returns a string containing the summary
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.
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:
SMS Deployment Functions
For SMS deployments, Based provides specialized functions for text messaging:send_image(url): Sends an image in the conversation.
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.