[Backend] Chat Interface + CrewAI Integration #17

Merged
shoko merged 1 commits from fix/issue-6 into main 2026-04-08 08:37:59 +02:00
Owner

Summary

Implement chat interface with CrewAI for natural language to strategy config parsing as described in issue #6.

Changes Made

Modified files:

  • src/backend/app/services/ai_agent/llm_connector.py - MiniMax LLM connector:

    • MiniMaxLLM class extending CrewAI LLM base class
    • MiniMaxConnector class with chat() and parse_strategy() methods
    • System prompt for strategy parsing with supported conditions
  • src/backend/app/services/ai_agent/crew.py - CrewAI crew implementation:

    • StrategyValidator class validating conditions and actions
    • StrategyExplainer class generating user-friendly explanations
    • TradingCrew class orchestrating the agents
    • Helper functions create_trading_designer_agent(), create_strategy_validator_agent(), create_strategy_explainer_agent()
    • get_trading_crew() factory function
  • src/backend/app/api/bots.py - Chat endpoint update:

    • Updated POST /api/bots/{id}/chat with CrewAI integration
    • Added conversation context management (last 10 messages)
    • Auto-updates bot strategy_config on successful parsing
    • Returns BotChatResponse with response, strategy_config, and success flag
  • src/backend/app/db/schemas.py - New schemas:

    • BotChatRequest - Request schema for chat endpoint
    • BotChatResponse - Response schema with response, strategy_config, success

Features Implemented

  1. MiniMax LLM Connector - Direct integration with MiniMax API for CrewAI
  2. Strategy Parser - Converts natural language to strategy_config JSON
  3. CrewAI Agents - Trading designer, validator, and explainer agents
  4. Strategy Validation - Validates feasibility and identifies issues
  5. Explanation Generation - User-friendly strategy explanations
  6. Conversation Context - Maintains context across chat messages

Supported Conditions (MVP)

  • price_drop - Token price drops by X%
  • price_rise - Token price rises by X%
  • volume_spike - Trading volume increases X%
  • price_level - Price crosses above/below X

Dependencies

  • Depends on issue #5 (Bot CRUD) which was already merged in PR #16

Fixes #6

## Summary Implement chat interface with CrewAI for natural language to strategy config parsing as described in issue #6. ### Changes Made **Modified files:** - `src/backend/app/services/ai_agent/llm_connector.py` - MiniMax LLM connector: - `MiniMaxLLM` class extending CrewAI LLM base class - `MiniMaxConnector` class with `chat()` and `parse_strategy()` methods - System prompt for strategy parsing with supported conditions - `src/backend/app/services/ai_agent/crew.py` - CrewAI crew implementation: - `StrategyValidator` class validating conditions and actions - `StrategyExplainer` class generating user-friendly explanations - `TradingCrew` class orchestrating the agents - Helper functions `create_trading_designer_agent()`, `create_strategy_validator_agent()`, `create_strategy_explainer_agent()` - `get_trading_crew()` factory function - `src/backend/app/api/bots.py` - Chat endpoint update: - Updated `POST /api/bots/{id}/chat` with CrewAI integration - Added conversation context management (last 10 messages) - Auto-updates bot strategy_config on successful parsing - Returns `BotChatResponse` with response, strategy_config, and success flag - `src/backend/app/db/schemas.py` - New schemas: - `BotChatRequest` - Request schema for chat endpoint - `BotChatResponse` - Response schema with response, strategy_config, success ### Features Implemented 1. **MiniMax LLM Connector** - Direct integration with MiniMax API for CrewAI 2. **Strategy Parser** - Converts natural language to `strategy_config` JSON 3. **CrewAI Agents** - Trading designer, validator, and explainer agents 4. **Strategy Validation** - Validates feasibility and identifies issues 5. **Explanation Generation** - User-friendly strategy explanations 6. **Conversation Context** - Maintains context across chat messages ### Supported Conditions (MVP) - `price_drop` - Token price drops by X% - `price_rise` - Token price rises by X% - `volume_spike` - Trading volume increases X% - `price_level` - Price crosses above/below X ### Dependencies - Depends on issue #5 (Bot CRUD) which was already merged in PR #16 ## Related Issue Fixes #6
shoko added 1 commit 2026-04-08 08:29:26 +02:00
- Create MiniMax LLM connector for CrewAI integration
- Implement TradingCrew with trading_designer, strategy_validator, strategy_explainer
- Add strategy parsing from natural language to strategy_config JSON
- Update chat endpoint with CrewAI integration and conversation context
- Add strategy validation logic
- Add explanation generation for user-friendly responses
- Add BotChatRequest/BotChatResponse schemas

Fixes #6
han approved these changes 2026-04-08 08:37:26 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit b0311bc96f into main 2026-04-08 08:37:59 +02:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/randebu#17