CalculatorTool class final
A tool that can be used to calculate the result of a math expression.
Example:
final openaiApiKey = Platform.environment['OPENAI_API_KEY'];
final llm = ChatOpenAI(
apiKey: openaiApiKey,
temperature: 0,
);
final tool = CalculatorTool();
final agent = ToolsAgent.fromLLMAndTools(llm: llm, tools: [tool]);
final executor = AgentExecutor(agent: agent);
final res = await executor.run('What is 40 raised to the 0.43 power? ');
print(res); // -> '40 raised to the power of 0.43 is approximately 4.8852'
Constructors
- CalculatorTool()
- A tool that can be used to calculate the result of a math expression.
Properties
- defaultOptions → ToolOptions
-
The default options to use when invoking the
Runnable
.finalinherited - description → String
-
Used to tell the model how/when/why to use the tool.
You can provide few-shot examples as a part of the description.
finalinherited
- handleToolError → String Function(ToolException)?
-
Handle the content of the
ToolException
thrown by the tool.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
-
inputJsonSchema
→ Map<
String, dynamic> -
Schema to parse and validate tool's input arguments.
Following the JSON Schema specification.
finalinherited
- name → String
-
The unique name of the tool that clearly communicates its purpose.
finalinherited
- returnDirect → bool
-
Whether to return the tool's output directly.
Setting this to true means that after the tool is called,
the AgentExecutor will stop looping.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strict → bool
-
Whether to enable strict schema adherence when generating the tool call.
If set to true, the model will follow the exact schema defined in the
inputJsonSchema field.
finalinherited
Methods
-
batch(
List< String> inputs, {List<ToolOptions> ? options}) → Future<List< String> > -
Batches the invocation of the
Runnable
on the giveninputs
.inherited -
bind(
ToolOptions options) → RunnableBinding< String, ToolOptions, String> -
Binds the
Runnable
to the givenoptions
.inherited -
close(
) → void -
Cleans up any resources associated with it the
Runnable
.inherited -
getCompatibleOptions(
RunnableOptions? options) → ToolOptions? -
Returns the given
options
if they are compatible with theRunnable
, otherwise returnsnull
.inherited -
getInputFromJson(
Map< String, dynamic> json) → String -
Parses the input JSON to the tool's input type.
inherited
-
invoke(
String input, {ToolOptions? options}) → Future< String> -
Runs the tool.
inherited
-
invokeInternal(
String toolInput, {ToolOptions? options}) → Future< String> - Actual implementation of invoke method logic with string input.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< String, NewCallOptions, NewRunOutput> next) → RunnableSequence<String, NewRunOutput> -
Pipes the output of this
Runnable
into anotherRunnable
using aRunnableSequence
.inherited -
stream(
String input, {ToolOptions? options}) → Stream< String> -
Streams the output of invoking the
Runnable
on the giveninput
.inherited -
streamFromInputStream(
Stream< String> inputStream, {ToolOptions? options}) → Stream<String> -
Streams the tool's output for the input resulting from
reducing the input stream.
inherited
-
toJson(
) → Map< String, dynamic> -
Converts the tool spec to a JSON-serializable map.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<String, RunnableOptions, String> >String, String> -
Adds fallback runnables to be invoked if the primary runnable fails.
inherited
-
withRetry(
{int maxRetries = 3, FutureOr< bool> retryIf(Object e)?, List<Duration?> ? delayDurations, bool addJitter = false}) → RunnableRetry<String, String> -
Adds retry logic to an existing runnable.
inherited
Operators
-
operator ==(
covariant ToolSpec other) → bool -
The equality operator.
inherited