feat: Introduce the concept of tool registry within Captain (#11516)

This PR introduces the concept of a tool registry. The implementation is
straightforward: you can define a tool by creating a class with a
function name. The function name gets registered in the registry and can
be referenced during LLM calls. When the LLM invokes a tool using the
registered name, the registry locates and executes the appropriate tool.
If the LLM calls an unregistered tool, the registry returns an error
indicating that the tool is not defined.
This commit is contained in:
Pranav
2025-05-19 15:26:38 -07:00
committed by GitHub
parent ad41fd90f9
commit d657f35a76
8 changed files with 303 additions and 51 deletions

View File

@@ -10,6 +10,8 @@ class Captain::Copilot::ChatService < Llm::BaseOpenAiService
@conversation_history = config[:conversation_history]
@previous_messages = config[:previous_messages] || []
@language = config[:language] || 'english'
register_tools
@messages = [system_message, conversation_history_context] + @previous_messages
@response = ''
end
@@ -25,6 +27,11 @@ class Captain::Copilot::ChatService < Llm::BaseOpenAiService
private
def register_tools
@tool_registry = Captain::ToolRegistryService.new(@assistant)
@tool_registry.register_tool(Captain::Tools::SearchDocumentationService)
end
def system_message
{
role: 'system',