Class: Anthropic::Helpers::Tools::BaseTool
- Inherits:
-
Object
- Object
- Anthropic::Helpers::Tools::BaseTool
- Defined in:
- lib/anthropic/helpers/tools/base_tool.rb
Direct Known Subclasses
Constant Summary
Constants included from InputSchema::JsonSchemaConverter
InputSchema::JsonSchemaConverter::NO_REF, InputSchema::JsonSchemaConverter::POINTERS
Class Attribute Summary collapse
- .doc_string ⇒ String readonly
- .model ⇒ Class<Anthropic::Helpers::InputSchema::BaseModel> readonly
-
.tool_extra_props ⇒ Hash{Symbol=>Object}?
private
Extra tool-definition properties merged into the API payload (e.g. ‘cache_control`, `defer_loading`, `allowed_callers`, `eager_input_streaming`, `input_examples`, `strict`).
-
.tool_name ⇒ String?
private
When set, the runner uses this literal string as the API tool name instead of snake-casing the class name.
Class Method Summary collapse
- .description(description) ⇒ Object (also: doc)
- .input_schema(model) ⇒ Object
- .inspect(depth: 0) ⇒ Object private
Instance Method Summary collapse
- #call(parsed) ⇒ Object
- #coerce(value, state:) ⇒ Object private
- #dump(value, state:) ⇒ Object private
- #inspect ⇒ Object private
-
#parse(value) ⇒ Object
Override the ‘#parse` method to customize the pre-processing of the tool call argument.
- #to_json_schema ⇒ Object private
- #to_json_schema_inner(state:) ⇒ Object private
Methods included from InputSchema::JsonSchemaConverter
assoc_meta!, cache_def!, to_json_schema, to_json_schema_inner, to_nilable
Methods included from Internal::Type::Converter
coerce, dump, meta_info, new_coerce_state, type_info
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Class Attribute Details
.doc_string ⇒ String (readonly)
17 18 19 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 17 def doc_string @doc_string end |
.model ⇒ Class<Anthropic::Helpers::InputSchema::BaseModel> (readonly)
14 15 16 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 14 def model @model end |
.tool_extra_props ⇒ Hash{Symbol=>Object}?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extra tool-definition properties merged into the API payload (e.g. ‘cache_control`, `defer_loading`, `allowed_callers`, `eager_input_streaming`, `input_examples`, `strict`).
35 36 37 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 35 def tool_extra_props @tool_extra_props end |
.tool_name ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
When set, the runner uses this literal string as the API tool name instead of snake-casing the class name. Used by helpers (e.g. MCP) that build tools dynamically from an external definition.
26 27 28 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 26 def tool_name @tool_name end |
Class Method Details
.description(description) ⇒ Object Also known as: doc
40 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 40 def description(description) = (@doc_string = description) |
.input_schema(model) ⇒ Object
47 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 47 def input_schema(model) = (@model = model) |
.inspect(depth: 0) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 52 def inspect(depth: 0) = "#{name}[#{model.inspect(depth:)}]" |
Instance Method Details
#call(parsed) ⇒ Object
90 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 90 def call(parsed) = raise NotImplementedError.new |
#coerce(value, state:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 74 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 71 def coerce(value, state:) parsed = parse(value) Anthropic::Internal::Type::Converter.coerce(self.class.model, parsed, state:) end |
#dump(value, state:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 65 def dump(value, state:) Anthropic::Internal::Type::Converter.dump(self.class.model, value, state:) end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 96 def inspect = "#<#{self.class.inspect(depth: 1)}:0x#{object_id.to_s(16)}>" |
#parse(value) ⇒ Object
Override the ‘#parse` method to customize the pre-processing of the tool call argument
85 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 85 def parse(value) = value |
#to_json_schema ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 61 def to_json_schema = self.class.model&.to_json_schema |
#to_json_schema_inner(state:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 |
# File 'lib/anthropic/helpers/tools/base_tool.rb', line 57 def to_json_schema_inner(state:) = self.class.model&.to_json_schema_inner(state:) |