Bỏ qua, đến nội dung

@digiforce-nc/plugin-ai

Plugin tích hợp AI vào hệ thống — kết nối LLM providers, tạo AI bots, quản lý tools/skills, hỗ trợ MCP clients, và tích hợp workflow.

Plugin này làm gì?

Plugin cung cấp nền tảng AI toàn diện: đăng ký nhiều LLM provider (OpenAI, Anthropic, Google, Ollama), tạo AI bots với personality và tools tùy chỉnh, kết nối MCP servers, và tích hợp vào workflow engine.

Bắt đầu nhanh (3 bước)

Mục tiêu của Digiforce là biến AI thành một năng lực có thể bật/tắt, phân quyền, và mở rộng giống như plugin.

  1. Bật AI: vào Settings → Plugin Manager và bật plugin-ai.
  2. Cấu hình LLM: vào Settings → AI → LLM Services và thêm ít nhất 1 provider/model.
  3. Tạo bot + gán năng lực: vào Settings → AI → Bots:
    • Tạo bot (system prompt + model)
    • Gán ít nhất 1 năng lực:
      • Tools: làm việc có cấu trúc (tạo báo cáo, gọi API, tự động hoá)
      • Skills (RAG): trả lời dựa trên tài liệu nội bộ (knowledge base)
      • MCP: gọi tool từ hệ thống ngoài (nếu cần)

Bạn nên chọn “năng lực” nào?

  • Cần câu trả lời dựa trên tài liệu nội bộ: dùng Knowledge base / RAG → xem plugin-ai-knowledge-base.
  • Cần số liệu, thống kê theo collection: dùng Data Query (tool/skill truy vấn dữ liệu) → xem plugin-data-source-manager.
  • Cần báo cáo có biểu đồ + markdown: dùng tool Business report (nếu bot được gán tool này).

AI trong Digiforce gồm những gì?

AI trong Digiforce không chỉ là “chat với LLM”, mà là một hệ gồm:

  • Chat UI + Bots: trải nghiệm trò chuyện và vận hành bot theo role.
  • Tools: các thao tác có schema/permission (AI “làm” được việc).
  • Skills / Knowledge base (RAG): AI “biết” dựa trên dữ liệu/tài liệu thật.
  • MCP: chuẩn kết nối tool từ hệ thống khác.
  • Workflow: AI tham gia luồng tự động hoá (trigger + instruction).

Năm nhiệm vụ chính

#Nhiệm vụChi tiết
1LLM Provider RegistryĐăng ký, cấu hình nhiều LLM provider (API key, model, params)
2AI Bots & ChatTạo bots với system prompt, gán tools/skills, chat conversations
3MCP & ToolsKết nối MCP servers, quản lý AI tools mở rộng
4Web SearchTìm kiếm web realtime qua sub-agent (hỗ trợ provider có khả năng web search)
5WorkflowAI bot trigger + LLM instruction node trong workflow

Kiến trúc

Luồng chat với AI bot

LLM Provider Registry & AIManager

AIManager class quản lý registry và khởi tạo provider instances:

typescript
class AIManager {
  registerLLMProvider(name: string, meta: LLMProviderMeta): void;
  listLLMProviders(): Array<{ name, title, supportedModel, supportWebSearch }>;
  getSupportedProvider(model: SupportedModel): string[];
  getLLMService(options: LLMModelOptions): Promise<{ provider, model, service }>;
}
ProviderModelsSDKWeb Search
OpenAIGPT-4o, GPT-4, GPT-3.5@langchain/openai-
AnthropicClaude 3.5, Claude 3@langchain/anthropic-
GoogleGemini Pro, Gemini Flash@langchain/google-genai-
DashScopeQwen series@langchain/community
OllamaLlama, Mistral, CodeLlama...@langchain/ollama-

Mỗi provider khai báo supportWebSearch: boolean — cho phép AIManager chọn provider phù hợp khi bot cần tìm kiếm web.

Database - 12+ collections

CollectionChứa gì
llmServicesCấu hình LLM provider (API key, base URL, model)
aiBotsĐịnh nghĩa bot (system prompt, model, tools)
aiConversations / aiMessagesPhiên chat và tin nhắn
aiSettingsCấu hình AI toàn cục
aiSkills / aiContextDatasourceRAG skills, datasource connectors
aiMcpClients / aiToolsMCP connections và tool definitions
aiFilesFiles đính kèm trong chat
lc-checkpointsLangChain checkpoints (agent state)
users-ai-botsLiên kết user - bot (M2M)

Vòng đời plugin

Web Search Tool

Plugin tích hợp sẵn tool subAgentWebSearch — cho phép AI bot tìm kiếm thông tin realtime từ internet:

Tool hỗ trợ tìm nhiều query song song, trả về kết quả có cấu trúc kèm nguồn tham chiếu. Yêu cầu provider đã đăng ký với supportWebSearch: true.

Workflow Integration

Thành phầnVai trò
AI Bot TriggerWorkflow kích hoạt khi user gửi message cho bot
LLM Instruction NodeNode gọi LLM với prompt tùy chỉnh, nhận kết quả

Ví dụ sử dụng API

Cấu hình LLM provider

typescript
await agent.resource('llmServices').create({
  values: {
    name: 'openai-main',
    provider: 'openai',
    apiKey: 'sk-...',
    defaultModel: 'gpt-4o',
  },
});

Tạo AI bot

typescript
await agent.resource('aiBots').create({
  values: {
    name: 'Support Bot',
    systemPrompt: 'Bạn là trợ lý hỗ trợ khách hàng...',
    llmServiceId: 1,
    model: 'gpt-4o',
  },
});

Chat với bot

typescript
const conv = await agent.resource('aiConversations').create({
  values: { botId: 1 },
});
await agent.resource('aiMessages').create({
  values: {
    conversationId: conv.body.data.id,
    content: 'Làm sao để đặt hàng?',
    role: 'user',
  },
});

Thành phần client

Thành phầnMô tả
AIBotsProviderContext provider cho AI bots state
ChatInterfaceGiao diện chat với AI bot
LLMSettingsTrang cấu hình LLM providers
MCPSettingsTrang cấu hình MCP clients
BotManagerTrang quản lý AI bots
WorkflowLLMNodeUI cho LLM node trong workflow editor
ui-core/widgets/AI bot widgets tích hợp vào UiCore widget system (AIBotActionWidget, AIBotShortcutWidget...)

Dependencies

PackageVai trò
langchain, @langchain/openai, @langchain/anthropic, @langchain/google-genai, @langchain/ollamaLLM orchestration + providers
zustandState management cho chat UI
react-markdownRender markdown trong responses

Mục lục chi tiết