AgentExecutor class
A chain responsible for executing the actions of an agent using tools. It receives user input and passes it to the agent, which then decides which tool/s to use and what action/s to take.
The AgentExecutor calls the specified tool with the generated input, retrieves the output, and passes it back to the agent to determine the next action. This process continues until the agent determines it can directly respond to the user or completes its task.
If you add memory to the AgentExecutor, it will save the AgentExecutor's inputs and outputs. It won't save the agent's intermediate inputs and outputs. If you want to save the agent's intermediate inputs and outputs, you should add memory to the agent instead.
- Inheritance
-
- Object
- Runnable<
ChainValues, ChainOptions, ChainValues> - BaseLangChain<
ChainValues, ChainOptions, ChainValues> - BaseChain<
BaseMemory> - AgentExecutor
Constructors
-
AgentExecutor.new({required BaseActionAgent agent, BaseMemory? memory, bool returnIntermediateSteps = false, int? maxIterations = 15, Duration? maxExecutionTime, AgentEarlyStoppingMethod earlyStoppingMethod = AgentEarlyStoppingMethod.force, Map<
String, dynamic> handleParsingErrors(OutputParserException)?}) - A chain responsible for executing the actions of an agent using tools. It receives user input and passes it to the agent, which then decides which tool/s to use and what action/s to take.
Properties
- agent → BaseActionAgent
-
The agent to run for creating a plan and determining actions to take at
each step of the execution loop.
final
- chainType → String
-
Return the string type key uniquely identifying this class of chain.
no setteroverride
- defaultOptions → ChainOptions
-
The default options to use when invoking the Runnable.
finalinherited
- earlyStoppingMethod → AgentEarlyStoppingMethod
-
The method to use for early stopping if the agent never returns
AgentFinish.
final
-
handleParsingErrors
→ Map<
String, dynamic> Function(OutputParserException)? -
Handles errors raised by the agent's output parser.
The response from this handler will be used as the tool input.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
inputKeys
→ Set<
String> -
Input keys for this chain.
no setteroverride
- maxExecutionTime → Duration?
-
The maximum amount of wall clock time to spend in the execution loop.
final
- maxIterations → int?
-
The maximum number of steps to take before ending the execution loop.
Setting to null could lead to an infinite loop.
final
- memory → BaseMemory?
-
Memory to use for this chain.
finalinherited
-
outputKeys
→ Set<
String> -
Output keys for this chain.
no setteroverride
- returnIntermediateSteps → bool
-
Whether to return the agent's trajectory of intermediate steps at the
end in addition to the final output.
final
- runOutputKey → String
-
Output key from where the run method needs to take the return value.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
apply(
List< ChainValues> inputs) → Future<List< ChainValues> > -
Call the chain on all inputs in the list.
inherited
-
batch(
List< ChainValues> inputs, {List<ChainOptions> ? options}) → Future<List< ChainValues> > -
Batches the invocation of the Runnable on the given
inputs
.inherited -
bind(
ChainOptions options) → RunnableBinding< ChainValues, ChainOptions, ChainValues> -
Binds the Runnable to the given
options
.inherited -
call(
dynamic input, {bool returnOnlyOutputs = false}) → Future< ChainValues> -
Runs the core logic of this chain with the given values.
If memory is not null, it will be used to load and save values.
inherited
-
callInternal(
ChainValues inputs) → Future< ChainValues> -
Call method to be implemented by subclasses (called by call).
This is where the core logic of the chain should be implemented.
override
-
close(
) → void -
Cleans up any resources associated with it the Runnable.
inherited
-
getCompatibleOptions(
RunnableOptions? options) → ChainOptions? -
Returns the given
options
if they are compatible with the Runnable, otherwise returnsnull
.inherited -
invoke(
ChainValues input, {ChainOptions? options}) → Future< ChainValues> -
Runs the core logic of this chain with the given input.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< ChainValues, NewCallOptions, NewRunOutput> next) → RunnableSequence<ChainValues, NewRunOutput> -
Pipes the output of this Runnable into another Runnable using a
RunnableSequence.
inherited
-
run(
dynamic input) → Future< String> -
Convenience method for executing chain when there's a single string
output.
inherited
-
stream(
ChainValues input, {ChainOptions? options}) → Stream< ChainValues> -
Streams the output of invoking the Runnable on the given
input
.inherited -
streamFromInputStream(
Stream< ChainValues> inputStream, {ChainOptions? options}) → Stream<ChainValues> -
Streams the output of invoking the Runnable on the given
inputStream
.inherited -
takeNextStep(
Map< String, Tool< nameToToolMap, ChainValues inputs, List<Object, ToolOptions, Object> >AgentStep> intermediateSteps) → Future<(AgentFinish?, List< AgentStep> ?)> - Take a single step in the thought-action-observation loop. Override this to take control of how the agent makes and acts on choices.
-
toString(
) → String -
A string representation of this object.
inherited
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<ChainValues, RunnableOptions, ChainValues> >ChainValues, ChainValues> -
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<ChainValues, ChainValues> -
Adds retry logic to an existing runnable.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- intermediateStepsOutputKey → const String
- Output key for the agent's intermediate steps output.