3.3 KiB
3.3 KiB
Implementation Plan - Captain V2 Multi-LLM & Documentation
This plan addresses three key objectives:
- Correcting the Context: Updating
.context/docsto reflect our specific WuzAPI/Jasmine/Captain architecture. - Multi-LLM Architecture: Implementing a flexible LLM provider system (OpenAI/Gemini) for Captain.
- Unification: Integrating Jasmine's brain (Intent/SDR logic) into Captain's body (AgentRunner).
User Review Required
[!IMPORTANT] > Database Schema Change: We will add
llm_providerandllm_modelcolumns tocaptain_inbox_configs. Configuration Strategy: This allows per-inbox configuration. One inbox can use GPT-4o (Sales), another Gemini 1.5 Flash (Support).
Proposed Changes
1. Correcting the Context (Documentation)
We will create a specific architecture addendum file to avoid overwriting the generic generic Chatwoot docs every time.
[NEW] .context/docs/custom-architecture.md
- Content:
- WuzAPI Integration Module: Explains the V1 Contract (Encrypted Tokens, Webhook Handlers, Sync Logic).
- Jasmine Brain: Explains Intent Detection, Strategy Decider, and Playbooks.
- Captain V2 (The Body): Explains
AgentRunnerServiceand how it delegates to the Brain.
2. Multi-LLM Backend Infrastructure
[MODIFY] db/migrate/timestamp_add_llm_config_to_captain.rb
- Add columns to
captain_inbox_configs(orchat_assistantstable, checking existing schema first):llm_provider(string, default: 'openai')llm_model(string, default: 'gpt-3.5-turbo')api_key(text, encrypted)
[MODIFY] enterprise/app/services/captain/llm/provider_factory.rb
- New Service: A factory pattern to instantiate the correct client.
def self.get_client(provider, config)- Case
openai: ReturnsOpenAI::Client - Case
gemini: ReturnsGemini::QuickClient(from our definition)
- Case
[MODIFY] enterprise/app/services/captain/assistant/agent_runner_service.rb
- Update
generate_responseto useProviderFactoryinstead of hardcoded OpenAI logic.
3. Jasmine Logic Injection
[MODIFY] enterprise/app/services/captain/llm/jasmine_brain.rb
- Ensure this class implements the "Thinking" step:
- Detect Intent (Sales/Support/Spam).
- Select Strategy.
- Assemble Prompt.
Verification Plan
Automated Tests
- Migration: Run
rails db:migrateand verify schema. - Provider Factory: Create a Rails Console script to request a completion from Gemini and OpenAI via the factory.
Manual Verification
- Configure: Set Inbox 1 to use Gemini 1.5 Flash.
- Chat: Send a message "Quero comprar um carro".
- Verify:
- Logs should show
[Captain] Using provider: gemini - Response should come from Gemini.
- Intent should be logged as
sales.
- Logs should show