2025-10-25 14:50:14 -03:00
|
|
|
# .gbdialog Dialogs
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
The [`.gbdialog`](../chapter-02/gbdialog.md) package contains BASIC scripts that define conversation flows, tool integrations, and bot behavior.
|
2025-10-25 14:50:14 -03:00
|
|
|
|
|
|
|
|
## What is .gbdialog?
|
|
|
|
|
|
|
|
|
|
`.gbdialog` files are written in a specialized BASIC dialect that controls:
|
2025-11-23 13:46:55 -03:00
|
|
|
- Tool execution and integrations
|
|
|
|
|
- LLM prompting and context
|
|
|
|
|
- Knowledge base activation
|
|
|
|
|
- Session and memory management
|
|
|
|
|
- External API calls
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
## Modern Approach: Let the LLM Work
|
|
|
|
|
### Minimal BASIC Philosophy
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
Instead of complex logic, use the LLM's natural understanding:
|
2025-10-25 14:50:14 -03:00
|
|
|
|
|
|
|
|
```basic
|
2025-11-23 13:46:55 -03:00
|
|
|
' Example from announcements.gbai/update-summary.bas
|
|
|
|
|
' Generate summaries from documents
|
|
|
|
|
let text = GET "announcements.gbkb/news/news.pdf"
|
|
|
|
|
let resume = LLM "In a few words, resume this: " + text
|
|
|
|
|
SET BOT MEMORY "resume", resume
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
' Example from law.gbai/case.bas
|
|
|
|
|
' Load context and let LLM answer questions
|
|
|
|
|
text = GET "case-" + cod + ".pdf"
|
|
|
|
|
text = "Based on this document, answer the person's questions:\n\n" + text
|
|
|
|
|
SET CONTEXT text
|
|
|
|
|
TALK "Case loaded. You can ask me anything about the case."
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Key Components
|
|
|
|
|
|
|
|
|
|
### 1. LLM Integration
|
|
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' LLM is for background processing only - generates content once for all users
|
|
|
|
|
' Example: Generate a summary that all users will see
|
|
|
|
|
text = GET "document.pdf"
|
|
|
|
|
summary = LLM "Summarize this document: " + text
|
|
|
|
|
SET BOT MEMORY "daily_summary", summary
|
2025-11-23 13:46:55 -03:00
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
' For interactive conversations, use SET CONTEXT and TALK
|
2025-11-23 13:46:55 -03:00
|
|
|
SET CONTEXT "user_type" AS "premium customer"
|
2025-11-23 20:12:09 -03:00
|
|
|
TALK "How can I help you today?"
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2. Tool Execution
|
|
|
|
|
```basic
|
|
|
|
|
' Define tools with parameters
|
|
|
|
|
PARAM name AS string LIKE "John Smith" DESCRIPTION "Customer name"
|
|
|
|
|
PARAM email AS string LIKE "john@example.com" DESCRIPTION "Email"
|
|
|
|
|
|
|
|
|
|
' LLM automatically knows when to call this
|
|
|
|
|
SAVE "customers.csv", name, email
|
|
|
|
|
TALK "Registration complete!"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3. Knowledge Base Usage
|
2025-11-23 20:12:09 -03:00
|
|
|
See [Knowledge Base documentation](../chapter-03/knowledge-base.md) for details.
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
|
|
|
|
' Activate knowledge base collections
|
|
|
|
|
USE KB "products"
|
|
|
|
|
USE KB "policies"
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
' The system AI searches these automatically during conversations
|
|
|
|
|
' No LLM command needed - just TALK to the user
|
|
|
|
|
TALK "What product information can I help you with?"
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Script Structure
|
|
|
|
|
|
|
|
|
|
### Entry Point: start.bas
|
2025-11-23 20:12:09 -03:00
|
|
|
Every bot needs a `start.bas` file in the [`.gbdialog`](../chapter-02/gbdialog.md) folder:
|
2025-11-23 13:46:55 -03:00
|
|
|
|
|
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' Minimal start script - let system AI handle conversations
|
2025-11-23 13:46:55 -03:00
|
|
|
USE KB "company_docs"
|
2025-11-23 20:12:09 -03:00
|
|
|
TALK "Welcome! How can I assist you today?"
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Tool Definitions
|
2025-11-23 20:12:09 -03:00
|
|
|
Create separate `.bas` files for each tool. See [KB and Tools](../chapter-03/kb-and-tools.md) for more information:
|
2025-11-23 13:46:55 -03:00
|
|
|
|
|
|
|
|
```basic
|
|
|
|
|
' enrollment.bas - The LLM knows when to use this
|
|
|
|
|
PARAM student_name AS string
|
|
|
|
|
PARAM course AS string
|
|
|
|
|
DESCRIPTION "Enrolls a student in a course"
|
|
|
|
|
|
|
|
|
|
SAVE "enrollments.csv", student_name, course, NOW()
|
|
|
|
|
TALK "Enrolled successfully!"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Best Practices
|
|
|
|
|
|
|
|
|
|
### 1. Minimal Logic
|
|
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' Good - Let system AI handle the conversation naturally
|
|
|
|
|
TALK "How can I help you?"
|
|
|
|
|
' System AI understands context and responds appropriately
|
2025-11-23 13:46:55 -03:00
|
|
|
|
|
|
|
|
' Avoid - Don't micromanage the flow
|
|
|
|
|
' IF user_says_this THEN do_that...
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2. Clear Tool Descriptions
|
|
|
|
|
```basic
|
|
|
|
|
DESCRIPTION "This tool books appointments for customers"
|
|
|
|
|
' The LLM uses this description to know when to call the tool
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3. Context Over Conditions
|
|
|
|
|
```basic
|
|
|
|
|
' Provide context, not rules
|
|
|
|
|
SET CONTEXT "business_hours" AS "9AM-5PM weekdays"
|
2025-11-23 20:12:09 -03:00
|
|
|
TALK "When would you like to schedule?"
|
|
|
|
|
' System AI naturally understands to mention hours when relevant
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
### 4. Trust the System AI
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' The system AI handles conversations naturally
|
|
|
|
|
TALK "Hello! I'm here to help."
|
|
|
|
|
' System handles greetings, questions, complaints naturally
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Common Patterns
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
### Document Summarization - Background Processing (from announcements.gbai)
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' Schedule automatic updates - runs in background
|
2025-11-23 13:46:55 -03:00
|
|
|
SET SCHEDULE "59 * * * *"
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
' Fetch and summarize documents ONCE for all users
|
2025-11-23 13:46:55 -03:00
|
|
|
let text = GET "announcements.gbkb/news/news.pdf"
|
|
|
|
|
let resume = LLM "In a few words, resume this: " + text
|
2025-11-23 20:12:09 -03:00
|
|
|
SET BOT MEMORY "resume", resume ' Stored for all users
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
### Interactive Case Analysis - User Conversations (from law.gbai)
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' Ask for case number - interactive with user
|
2025-11-23 13:46:55 -03:00
|
|
|
TALK "What is the case number?"
|
|
|
|
|
HEAR cod
|
|
|
|
|
|
|
|
|
|
' Load case document
|
|
|
|
|
text = GET "case-" + cod + ".pdf"
|
|
|
|
|
|
|
|
|
|
IF text THEN
|
2025-11-23 20:12:09 -03:00
|
|
|
' Set context for system AI to use in conversation
|
2025-11-23 13:46:55 -03:00
|
|
|
text = "Based on this document, answer the person's questions:\n\n" + text
|
|
|
|
|
SET CONTEXT text
|
|
|
|
|
TALK "Case loaded. Ask me anything about it."
|
2025-10-25 14:50:14 -03:00
|
|
|
ELSE
|
2025-11-23 13:46:55 -03:00
|
|
|
TALK "Case not found, please try again."
|
2025-10-25 14:50:14 -03:00
|
|
|
END IF
|
|
|
|
|
```
|
|
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
### Tool Definition Pattern
|
|
|
|
|
```basic
|
|
|
|
|
' Tool parameters (auto-discovered by LLM)
|
|
|
|
|
PARAM name AS string
|
|
|
|
|
PARAM email AS string
|
|
|
|
|
DESCRIPTION "Enrollment tool"
|
|
|
|
|
|
|
|
|
|
' Tool logic (called when LLM decides)
|
|
|
|
|
SAVE "enrollments.csv", name, email
|
|
|
|
|
TALK "Successfully enrolled " + name
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Multi-Collection Search
|
|
|
|
|
```basic
|
|
|
|
|
USE KB "products"
|
2025-11-23 20:12:09 -03:00
|
|
|
USE KB "reviews"
|
2025-11-23 13:46:55 -03:00
|
|
|
USE KB "specifications"
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
' System AI searches these collections automatically during conversation
|
|
|
|
|
TALK "What would you like to know about our products?"
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Advanced Features
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
### Memory Management
|
2025-11-23 20:12:09 -03:00
|
|
|
See [Storage documentation](../chapter-09/storage.md) for persistent data options.
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
|
|
|
|
SET BOT MEMORY "company_policy", policy_text
|
|
|
|
|
' Available across all sessions
|
|
|
|
|
|
|
|
|
|
retrieved = GET BOT MEMORY "company_policy"
|
|
|
|
|
```
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
### External APIs
|
2025-11-23 20:12:09 -03:00
|
|
|
See [External APIs chapter](../chapter-08/external-apis.md) for integration patterns.
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
|
|
|
|
result = GET "https://api.example.com/data"
|
2025-11-23 20:12:09 -03:00
|
|
|
' For background processing only
|
|
|
|
|
summary = LLM "Summarize this data: " + result
|
|
|
|
|
SET BOT MEMORY "api_summary", summary
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
### Suggestions
|
2025-11-23 20:12:09 -03:00
|
|
|
See [UI Interface](../chapter-04/ui-interface.md) for UI integration.
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
|
|
|
|
ADD SUGGESTION "Schedule Meeting" AS "schedule"
|
|
|
|
|
ADD SUGGESTION "View Products" AS "products"
|
|
|
|
|
' UI shows these as quick actions
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Error Handling
|
|
|
|
|
|
|
|
|
|
The system handles errors gracefully:
|
|
|
|
|
- Syntax errors caught at compile time
|
|
|
|
|
- Runtime errors logged but don't crash
|
|
|
|
|
- LLM provides fallback responses
|
|
|
|
|
- Timeouts prevent infinite operations
|
2025-10-25 14:50:14 -03:00
|
|
|
|
|
|
|
|
## Script Execution
|
|
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
Scripts run in a sandboxed environment with:
|
|
|
|
|
- Access to session state
|
2025-10-25 14:50:14 -03:00
|
|
|
- LLM generation capabilities
|
2025-11-23 13:46:55 -03:00
|
|
|
- Knowledge base search
|
|
|
|
|
- Tool execution rights
|
|
|
|
|
- External API access (configured)
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 13:46:55 -03:00
|
|
|
## Migration from Traditional Bots
|
|
|
|
|
|
|
|
|
|
### Old Way (Complex Logic)
|
|
|
|
|
```basic
|
|
|
|
|
' DON'T DO THIS - 1990s style
|
|
|
|
|
' IF INSTR(user_input, "order") > 0 THEN
|
|
|
|
|
' IF INSTR(user_input, "status") > 0 THEN
|
|
|
|
|
' TALK "Checking order status..."
|
|
|
|
|
' ELSE IF INSTR(user_input, "new") > 0 THEN
|
|
|
|
|
' TALK "Creating new order..."
|
|
|
|
|
' END IF
|
|
|
|
|
' END IF
|
|
|
|
|
```
|
|
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
### New Way (System AI Intelligence)
|
2025-11-23 13:46:55 -03:00
|
|
|
```basic
|
2025-11-23 20:12:09 -03:00
|
|
|
' DO THIS - Let system AI handle conversation naturally
|
|
|
|
|
TALK "How can I help you with your order?"
|
|
|
|
|
' System AI understands context and intent automatically
|
2025-11-23 13:46:55 -03:00
|
|
|
```
|
2025-10-25 14:50:14 -03:00
|
|
|
|
2025-11-23 20:12:09 -03:00
|
|
|
The key is to **trust the system AI** and write less code for more intelligent behavior.
|
|
|
|
|
|
|
|
|
|
## Important Distinction
|
|
|
|
|
|
|
|
|
|
- **[LLM Command](../chapter-09/ai-llm.md)**: For background/batch processing, generates content ONCE, stored in BOT MEMORY for all users
|
|
|
|
|
- **[Interactive Conversations](../chapter-09/conversation.md)**: Use HEAR/TALK/SET CONTEXT, system AI handles the natural conversation flow
|
|
|
|
|
|
|
|
|
|
## See Also
|
|
|
|
|
|
|
|
|
|
- [Chapter 1: Quick Start](../chapter-01/quick-start.md) - Getting started with your first bot
|
|
|
|
|
- [Chapter 2: Bot Architecture](../chapter-02/README.md) - Understanding all components
|
|
|
|
|
- [Chapter 3: Knowledge Base](../chapter-03/knowledge-base.md) - Working with KB collections
|
|
|
|
|
- [Chapter 5: Keywords Reference](../chapter-05/README.md) - Complete BASIC command reference
|
|
|
|
|
- [Chapter 9: Conversation Flow](../chapter-09/conversation.md) - Advanced dialog patterns
|