TavilyAnswerTool class final
Tool that queries the Tavily Search API and gets an answer to the search query.
The Tavily API uses API keys for authentication. Visit the Tavily console to retrieve the API key you'll use in your requests.
If you want to get a list of search results instead, use the TavilySearchResultsTool instead.
Example:
final tool = TavilyAnswerTool(
apiKey: Platform.environment['TAVILY_API_KEY']!,
);
final res = await tool.invoke('What is the weather like in New York?');
print(res);
// The current weather in New York is clear with a temperature of 22.8°C (73.0°F)...
Constructors
-
TavilyAnswerTool.new({String? apiKey, String? baseUrl, Map<
String, String> headers = const {}, Map<String, dynamic> queryParams = const {}, Client? client, TavilyAnswerToolOptions? defaultOptions = const TavilyAnswerToolOptions()}) - Creates a TavilyAnswerTool instance.
Properties
- apiKey ↔ String?
-
Your Tavily API key.
getter/setter pair
- defaultOptions → TavilyAnswerToolOptions
-
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<TavilyAnswerToolOptions> ? options}) → Future<List< String> > -
Batches the invocation of the
Runnable
on the giveninputs
.inherited -
bind(
TavilyAnswerToolOptions options) → RunnableBinding< String, TavilyAnswerToolOptions, String> -
Binds the
Runnable
to the givenoptions
.inherited -
close(
) → void -
Cleans up any resources associated with it the
Runnable
. -
getCompatibleOptions(
RunnableOptions? options) → TavilyAnswerToolOptions? -
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, {TavilyAnswerToolOptions? options}) → Future< String> -
Runs the tool.
inherited
-
invokeInternal(
String toolInput, {TavilyAnswerToolOptions? 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, {TavilyAnswerToolOptions? options}) → Stream< String> -
Streams the output of invoking the
Runnable
on the giveninput
.inherited -
streamFromInputStream(
Stream< String> inputStream, {TavilyAnswerToolOptions? 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