Enhance trading bot functionality and LLM system message clarity
- Added BotTradingBalance property to UserStrategyDetailsViewModel for better tracking of bot allocations. - Updated DataController to include BotTradingBalance in the response model. - Improved LlmController by refining the system message to ensure LLM understands its response capabilities and tool usage. - Introduced new MCP tools for running and analyzing bundle backtests, enhancing backtesting capabilities for users. - Implemented security measures in BotTools to ensure users can only access their own bots, improving data privacy.
This commit is contained in:
@@ -632,7 +632,8 @@ public class DataController : ControllerBase
|
||||
Identifier = strategy.Identifier,
|
||||
WalletBalances = walletBalances,
|
||||
Ticker = strategy.Ticker,
|
||||
MasterAgentName = strategy.MasterBotUser?.AgentName
|
||||
MasterAgentName = strategy.MasterBotUser?.AgentName,
|
||||
BotTradingBalance = strategy.BotTradingBalance
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -57,23 +57,28 @@ public class LlmController : BaseController
|
||||
var availableTools = await _mcpService.GetAvailableToolsAsync();
|
||||
request.Tools = availableTools.ToList();
|
||||
|
||||
// Add system message to clarify that tools are optional and the LLM can respond directly
|
||||
// Check if a system message already exists
|
||||
var hasSystemMessage = request.Messages.Any(m => m.Role == "system");
|
||||
if (!hasSystemMessage)
|
||||
// Add or prepend system message to ensure LLM knows it can respond directly
|
||||
// Remove any existing system messages first to ensure our directive is clear
|
||||
var existingSystemMessages = request.Messages.Where(m => m.Role == "system").ToList();
|
||||
foreach (var msg in existingSystemMessages)
|
||||
{
|
||||
var systemMessage = new LlmMessage
|
||||
{
|
||||
Role = "system",
|
||||
Content = "You are a helpful AI assistant with expertise in quantitative finance, algorithmic trading, and financial mathematics. " +
|
||||
"You can answer questions directly using your knowledge. " +
|
||||
"Tools are available for specific operations (backtesting, agent management, market data retrieval, etc.) but are optional. " +
|
||||
"Use tools only when they are needed for the specific task. " +
|
||||
"For general questions, explanations, calculations, or discussions, respond directly without using tools."
|
||||
};
|
||||
request.Messages.Insert(0, systemMessage);
|
||||
request.Messages.Remove(msg);
|
||||
}
|
||||
|
||||
// Add explicit system message at the beginning
|
||||
var systemMessage = new LlmMessage
|
||||
{
|
||||
Role = "system",
|
||||
Content = "You are an expert AI assistant specializing in quantitative finance, algorithmic trading, and financial mathematics. " +
|
||||
"You have full knowledge and can answer ANY question directly using your training data and expertise. " +
|
||||
"IMPORTANT: You MUST answer general questions, explanations, calculations, and discussions directly without using tools. " +
|
||||
"Tools are ONLY for specific system operations like backtesting, agent management, or retrieving real-time market data. " +
|
||||
"For questions about financial concepts, mathematical formulas (like Black-Scholes), trading strategies, or any theoretical knowledge, " +
|
||||
"you MUST provide a direct answer using your knowledge. Do NOT refuse to answer or claim you can only use tools. " +
|
||||
"Only use tools when the user explicitly needs to perform a system operation (e.g., 'run a backtest', 'get market data', 'manage agents')."
|
||||
};
|
||||
request.Messages.Insert(0, systemMessage);
|
||||
|
||||
// Send chat request to LLM
|
||||
var response = await _llmService.ChatAsync(user, request);
|
||||
|
||||
|
||||
@@ -112,5 +112,11 @@ namespace Managing.Api.Models.Responses
|
||||
/// The agent name of the master bot's owner (for copy trading bots)
|
||||
/// </summary>
|
||||
public string MasterAgentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The trading balance allocated to this bot
|
||||
/// </summary>
|
||||
[Required]
|
||||
public decimal BotTradingBalance { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user