BotSharp Documentation
repository·master·Indexed 25 days ago
https://github.com/scisharp/botsharpAn open-source AI Agent Application Framework built on .NET Core. BotSharp features a modular, plugin-based architecture supporting multi-agent orchestration, RAG, and various LLM providers including OpenAI, Anthropic, Gemini, LLaMA 3, and DeepSeek. It includes a suite of built-in plugins for data storage, messaging channels (Microsoft Teams, WeChat, Telegram), and tools like a Web Browser agent via WebDriver.
What's inside BotSharp
- BotSharp is an open-source AI agent application framework designed to integrate Large Language Models (LLMs) into existing business systems. It uses a component-based architecture to decouple different parts of the platform, allowing developers to swap UI/UX, NLP Taggers, or NER (Named Entity Recognition) algorithms using unified interfaces. This modularity enables high compatibility and scalability.
Overview of BotSharp AI Framework
masterBotSharp is an open-source AI framework designed for building enterprise-grade LLM (Large Language Model) applications using .NET and C#. It is built on a modular, component-based architecture that allows developers to decouple and swap various parts of the AI pipeline, such as UI/UX, Vector Storage, and NLU (Natural Language Understanding) algorithms, through unified interfaces.
Key capabilities include:
- Natural language understanding
- Computer vision
- Audio processing
- Integration with machine learning algorithms via C/C++ interfaces (bypassing Python interfaces for better performance and type safety in C#)
- Support for 'Conversation as a Platform' (CaaP) patterns.
Understand the Agent Utility concept in BotSharp
masterAn Agent Utility is a feature used to enhance an agent's capabilities by dynamically adding extra prompts and task-oriented functions (tools) during a conversation. Utilities allow an agent to perform specialized tasks based on the conversation context without disrupting its primary purpose.
Common use cases include:
- Reading images or PDFs
- Generating images
- Sending HTTP requests
Core Components of the BotSharp Platform
masterA BotSharp-based chatbot platform consists of three primary modular components:
- Storage module: Supports memory and Redis DB methods for data persistence.
- Corpus extractor: Formats data into templates to feed into the BotSharp trainer.
- NLU engine: An exclusive Natural Language Understanding engine that is open to user customization/extension.
Use the Web Browser agent
masterThe Web Driver plugin provides a
Web Browseragent that integrates with BotSharp's Routing mechanism.When the Router determines that a user's intention involves web page operations, it automatically routes the request to this agent. The agent analyzes conversation records to generate and execute functions that call the browser's API to perform the requested operations.
Use Form templates to collect user information
masterForm templates allow you to present a structured form to the user, enabling them to fill in specific information directly within the chat interface.Understand Agent types in BotSharp
masterIn BotSharp, an Agent is a collection of prompt words, function JSON Schema definitions, few-shot examples, and knowledge base data used to transform unstructured user input into structured data. Agents are categorized into four types:
- Task Agents: Business domain agents designed to perform specific operations.
- Routing (non-task) Agents: Agents used to route requests to other agents.
- Evaluating Agents: Agents used for assessment/evaluation.
- Static Agents: Agents that lack the capability to interact with external environments.
Specify LLM Provider and Model in Dialogues
masterTo control which LLM is used during a specific round of dialogue, include the
providerandmodelkeys in your dialogue request. Alternatively, you can specify the LLM once during dialogue initialization to apply it to all subsequent dialogues in that session.{ "text": "Good morning!", "provider": "google-ai", "model": "palm2" }Use fastText for text embedding
masterTo use fastText for semantic search and text representations, you must install the
BotSharp.Plugin.MetaAINuGet package and enable it in your settings. You also need to download a pre-trained fastText model (e.g., from the fastText website) and provide the path to that model in your configuration.Steps:
- Install
BotSharp.Plugin.MetaAI. - Add
BotSharp.Plugin.MetaAItoPluginLoader.Assemblies. - Add
MetaAiPlugintoPluginLoader.Plugins. - Set
KnowledgeBase.TextEmbeddingtofastTextEmbeddingProvider. - Configure the
MetaAi.fastText.ModelPathwith the path to your downloaded.binmodel file.
{ "PluginLoader": { "Assemblies": [ "BotSharp.Plugin.MetaAI" ], "Plugins": [ "KnowledgeBasePlugin", "MemVecDbPlugin", "MetaAiPlugin" ] }, "KnowledgeBase": { "TextEmbedding": "fastTextEmbeddingProvider" }, "MetaAi": { "fastText": { "ModelPath": "crawl-300d-2M-subword.bin" } } }- Install
Build a Rule Flow Graph
masterA rule flow graph is a directed graph consisting of Nodes (units of work) and Edges (directed links). To be valid, every graph must have exactly one root node and exactly one end node.
Node Types
- Root (
rootorstart): The entry point. It has no input schema but must have an output schema to pass parameters downstream. - End (
end): The exit point. It can have both input and output schemas to collect final context parameters. - Action (
action): Performs work (e.g., HTTP requests, tool calls). Requires both an input and an output schema. - Condition (
condition): Evaluates a boolean expression. Children are only traversed if the result istrue.
- Root (
Configure Facebook Messenger Webhooks
masterAfter setting up the integration in BotSharp, you must link it to Facebook by configuring webhooks in the Facebook Developer Console:
- Under the Webhooks section, click Setup Webhooks.
- Enter the following details:
- Callback URL: Use the URL provided on the BotSharp Facebook Messenger integration page.
- Verify Token: The same string you defined in the BotSharp configuration.
- Under Subscription Fields, check the following options:
messagesmessaging_postbacks
- Click Verify and Save.
Install LLamaSharp Backend for BotSharp
masterTo use the
BotSharp.Plugin.LLamaSharpplugin for running local LLM models, you must install a compatible LLamaSharp backend service.Important: You must install a backend version that matches the version of
LLamaSharpused in theBotSharp.Plugin.LLamaSharp.csprojproject.Available backends:
LLamaSharp.Backend.Cpu: Pure CPU for Windows & Linux. (Note: Use Metal for Mac).LLamaSharp.Backend.Cuda11: CUDA 11 for Windows and Linux.LLamaSharp.Backend.Cuda12: CUDA 12 for Windows and Linux.
# move to the LLamaSharp Plugin Project $ cd src/Plugins/BotSharp.Plugin.LLamaSharp # Install the LLamaSharp Backend (example using CPU version 0.9.1) $ dotnet add package LLamaSharp.Backend.Cpu --version 0.9.1