BotSharp Documentation

repository·master·Indexed 25 days ago

https://github.com/scisharp/botsharp

An 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.

Tokens
18.3K
Snippets
47
Records
107
Agent score
84%

What's inside BotSharp

  1. Overview of BotSharp Framework

    master
    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.
  2. Overview of BotSharp AI Framework

    master

    BotSharp 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.
  3. Understand the Agent Utility concept in BotSharp

    master

    An 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
  4. Core Components of the BotSharp Platform

    master

    A BotSharp-based chatbot platform consists of three primary modular components:

    1. Storage module: Supports memory and Redis DB methods for data persistence.
    2. Corpus extractor: Formats data into templates to feed into the BotSharp trainer.
    3. NLU engine: An exclusive Natural Language Understanding engine that is open to user customization/extension.
  5. Use the Web Browser agent

    master

    The Web Driver plugin provides a Web Browser agent 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.

  6. Understand Agent types in BotSharp

    master

    In 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.
  7. Specify LLM Provider and Model in Dialogues

    master

    To control which LLM is used during a specific round of dialogue, include the provider and model keys 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"
    }
  8. Use fastText for text embedding

    master

    To use fastText for semantic search and text representations, you must install the BotSharp.Plugin.MetaAI NuGet 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:

    1. Install BotSharp.Plugin.MetaAI.
    2. Add BotSharp.Plugin.MetaAI to PluginLoader.Assemblies.
    3. Add MetaAiPlugin to PluginLoader.Plugins.
    4. Set KnowledgeBase.TextEmbedding to fastTextEmbeddingProvider.
    5. Configure the MetaAi.fastText.ModelPath with the path to your downloaded .bin model file.
    {
      "PluginLoader": {
        "Assemblies": [
          "BotSharp.Plugin.MetaAI"
        ],
        "Plugins": [
          "KnowledgeBasePlugin",
          "MemVecDbPlugin",
          "MetaAiPlugin"
        ]
      },
      "KnowledgeBase": {
        "TextEmbedding": "fastTextEmbeddingProvider"
      },
      "MetaAi": {
        "fastText": {
          "ModelPath": "crawl-300d-2M-subword.bin"
        }
      }
    }
  9. Build a Rule Flow Graph

    master

    A 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 (root or start): 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 is true.
  10. Configure Facebook Messenger Webhooks

    master

    After setting up the integration in BotSharp, you must link it to Facebook by configuring webhooks in the Facebook Developer Console:

    1. Under the Webhooks section, click Setup Webhooks.
    2. 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.
    3. Under Subscription Fields, check the following options:
      • messages
      • messaging_postbacks
    4. Click Verify and Save.
  11. Install LLamaSharp Backend for BotSharp

    master

    To use the BotSharp.Plugin.LLamaSharp plugin 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 LLamaSharp used in the BotSharp.Plugin.LLamaSharp.csproj project.

    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