3.3 KiB
Component Architecture
This document describes the component architecture of LangBot, which is designed to be modular and extensible.
Overview
LangBot is built around a component-based architecture that allows for easy extension and customization. The main components are:
- Bots: Interface with messaging platforms
- Pipelines: Process messages and generate responses
- Models: Connect to LLM providers
- Plugins: Extend functionality
Bots
Bots are responsible for connecting to messaging platforms and handling message events. Each bot implements a specific platform adapter that translates between the platform's API and LangBot's internal event system.
Key classes:
MessageSourceAdapter: Base class for all platform adaptersEventConverter: Converts platform-specific events to LangBot eventsMessageConverter: Converts platform-specific messages to LangBot messages
Pipelines
Pipelines process messages through a series of components:
- Trigger: Determines whether to process a message
- Moderation: Filters and processes messages before sending to the model
- AI: Sends the message to the LLM and receives a response
- Output: Processes the model's response before sending it back to the user
Each component in the pipeline can be configured and customized.
Models
The Models component manages connections to various LLM providers, such as OpenAI, Anthropic, and others. It provides a unified interface for sending requests to these providers and handling their responses.
Key classes:
ModelProvider: Base class for all model providersModelRequest: Represents a request to a modelModelResponse: Represents a response from a model
Plugins
The plugin system allows for extending LangBot's functionality without modifying the core code. Plugins can:
- Register event handlers
- Add new commands
- Provide functions that can be called by the LLM
- Extend core components
Key concepts:
@handler: Decorator for registering event handlers@llm_func: Decorator for registering functions that can be called by the LLMAPIHost: Provides access to LangBot's API from pluginsmanifest.yaml: Configuration file for plugins
Event System
LangBot uses an event-driven architecture where different components communicate through events. Events include:
- Message events (received, sent)
- Group events (joined, left, invited)
- System events (startup, shutdown)
- Custom events defined by plugins
Configuration System
The configuration system uses a YAML-based approach with the main configuration file at data/config.yaml. The configuration is structured around the component architecture:
bots:
# Bot configurations
pipelines:
# Pipeline configurations
providers:
# Model provider configurations
plugins:
# Plugin configurations
system:
# System configurations
Development Workflow
When developing for LangBot, follow these steps:
- Understand the component you want to modify or extend
- Create a plugin if you're adding new functionality
- Implement the necessary classes and methods
- Test your changes
- Submit a pull request
For more detailed information on development, see the Development Configuration page.
