Module: Langchain::ToolDefinition
- Included in:
- Langchain::Tool::Calculator, Langchain::Tool::Database, Langchain::Tool::FileSystem, Langchain::Tool::GoogleSearch, Langchain::Tool::NewsRetriever, Langchain::Tool::RubyCodeInterpreter, Langchain::Tool::Tavily, Langchain::Tool::Vectorsearch, Langchain::Tool::Weather, Langchain::Tool::Wikipedia
- Defined in:
- lib/langchain/tool_definition.rb
Overview
Extends a class to be used as a tool in the assistant. A tool is a collection of functions (methods) used to perform specific tasks.
Usage
-
Extend your class with ToolDefinition
-
Use #define_function to define each function of the tool
Key Concepts
-
#define_function: Defines a new function (method) for the tool
-
ParameterBuilder#property: Defines properties for the function parameters
-
ParameterBuilder#item: Alias for ParameterBuilder#property, used for array items
These methods support various data types and nested structures, allowing for flexible and expressive tool definitions.
Defined Under Namespace
Classes: FunctionSchemas, ParameterBuilder
Instance Method Summary collapse
-
#define_function(method_name, description:) { ... } ⇒ Object
Defines a function for the tool.
-
#function_schemas ⇒ FunctionSchemas
Returns the FunctionSchemas instance for this tool.
-
#tool_name ⇒ String
Returns the snake_case version of the class name as the tool’s name.
Instance Method Details
#define_function(method_name, description:) { ... } ⇒ Object
Defines a function for the tool
43 44 45 |
# File 'lib/langchain/tool_definition.rb', line 43 def define_function(method_name, description:, &block) function_schemas.add_function(method_name:, description:, &block) end |
#function_schemas ⇒ FunctionSchemas
Returns the FunctionSchemas instance for this tool
50 51 52 |
# File 'lib/langchain/tool_definition.rb', line 50 def function_schemas @function_schemas ||= FunctionSchemas.new(tool_name) end |
#tool_name ⇒ String
Returns the snake_case version of the class name as the tool’s name
57 58 59 60 61 62 |
# File 'lib/langchain/tool_definition.rb', line 57 def tool_name @tool_name ||= name .gsub("::", "_") .gsub(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_") .downcase end |