Examples¶
Complete working examples demonstrating dataknobs-bots features.
Available Examples¶
| Example | Description | Key Features |
|---|---|---|
| Simple Chatbot | Basic conversational bot | LLM integration, basic configuration |
| Memory Chatbot | Bot with conversation memory | Buffer memory, context management |
| RAG Chatbot | Knowledge base integration | Document loading, vector search, RAG |
| ReAct Agent | Tool-using agent | Custom tools, ReAct reasoning |
| Wizard Bot | Guided conversational wizard | FSM stages, validation, data collection |
| Multi-Tenant Bot | Multiple clients setup | Bot registry, client isolation |
| Config-Based Tools | Configuration-driven tools | Tool configuration, XRef system |
Running Examples¶
All examples use Ollama for local LLM inference. Follow these steps:
1. Install Ollama¶
Visit https://ollama.ai/ and install Ollama for your platform.
2. Pull Required Models¶
# For basic chatbot examples
ollama pull gemma3:1b
# For agent examples
ollama pull phi3:mini
# For RAG examples (embedding model)
ollama pull nomic-embed-text
3. Install Dependencies¶
# Basic installation
pip install dataknobs-bots
# With FAISS for RAG examples
pip install dataknobs-bots[faiss]
4. Run an Example¶
# Clone the repository
git clone https://github.com/kbs-labs/dataknobs.git
cd dataknobs/packages/bots
# Run an example
python examples/01_simple_chatbot.py
Example Categories¶
Getting Started¶
Perfect for beginners learning dataknobs-bots:
- Simple Chatbot - Your first bot
- Memory Chatbot - Adding memory
Advanced Features¶
For users building production bots:
- RAG Chatbot - Knowledge retrieval
- ReAct Agent - Tool integration
- Wizard Bot - Guided conversational flows
- Multi-Tenant Bot - Multi-tenancy
Configuration Patterns¶
Learn configuration best practices:
- Config-Based Tools - Tool configuration
Prerequisites¶
Required¶
- Python 3.12+
- dataknobs-bots package
- Ollama (for local LLM)
Optional¶
- FAISS (
pip install faiss-cpu) - For RAG examples - PostgreSQL - For production storage examples
Common Patterns¶
Basic Bot Setup¶
from dataknobs_bots import DynaBot, BotContext
config = {
"llm": {"provider": "ollama", "model": "gemma3:1b"},
"conversation_storage": {"backend": "memory"}
}
bot = await DynaBot.from_config(config)
context = BotContext(
conversation_id="example-001",
client_id="demo"
)
response = await bot.chat("Hello!", context)
Adding Memory¶
config = {
"llm": {"provider": "ollama", "model": "gemma3:1b"},
"conversation_storage": {"backend": "memory"},
"memory": {
"type": "buffer",
"max_messages": 10
}
}
Enabling RAG¶
config = {
"llm": {"provider": "ollama", "model": "gemma3:1b"},
"conversation_storage": {"backend": "memory"},
"knowledge_base": {
"enabled": True,
"documents_path": "./docs",
"vector_store": {"backend": "faiss", "dimension": 384}
}
}
Adding Tools¶
config = {
"llm": {"provider": "ollama", "model": "phi3:mini"},
"conversation_storage": {"backend": "memory"},
"reasoning": {"strategy": "react"},
"tools": [
{"class": "my_tools.CalculatorTool", "params": {}}
]
}
Tips¶
- Start with Simple Chatbot - Build foundation understanding
- Use Ollama - No API keys needed for development
- Enable Verbose Mode - Set
verbose: Truein reasoning config - Check Logs - Enable logging for debugging
- Read the Code - All examples are well-commented
Troubleshooting¶
Model Not Found¶
Solution: Pull the model first:
Connection Error¶
Solution: Ensure Ollama is running:
Import Error¶
Solution: Install the package:
Next Steps¶
After running the examples:
- Read the User Guide for in-depth tutorials
- Explore Configuration Reference for all options
- Learn Tool Development to create custom tools
- Check Architecture for system design
Source Code¶
All example source code is available in the GitHub repository:
https://github.com/kbs-labs/dataknobs/tree/main/packages/bots/examples