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

@@ -0,0 +1,34 @@
class Captain::Tools::BaseService
attr_accessor :assistant
def initialize(assistant)
@assistant = assistant
end
def name
raise NotImplementedError, "#{self.class} must implement name"
end
def description
raise NotImplementedError, "#{self.class} must implement description"
end
def parameters
raise NotImplementedError, "#{self.class} must implement parameters"
end
def execute(arguments)
raise NotImplementedError, "#{self.class} must implement execute"
end
def to_registry_format
{
type: 'function',
function: {
name: name,
description: description,
parameters: parameters
}
}
end
end