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
