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:
34
enterprise/app/services/captain/tools/base_service.rb
Normal file
34
enterprise/app/services/captain/tools/base_service.rb
Normal 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
|
||||
Reference in New Issue
Block a user