Agent that is using tools.
| 1049 | |
| 1050 | |
| 1051 | class AgentExecutor(Chain): |
| 1052 | """Agent that is using tools.""" |
| 1053 | |
| 1054 | agent: Union[BaseSingleActionAgent, BaseMultiActionAgent] |
| 1055 | """The agent to run for creating a plan and determining actions |
| 1056 | to take at each step of the execution loop.""" |
| 1057 | tools: Sequence[BaseTool] |
| 1058 | """The valid tools the agent can call.""" |
| 1059 | return_intermediate_steps: bool = False |
| 1060 | """Whether to return the agent's trajectory of intermediate steps |
| 1061 | at the end in addition to the final output.""" |
| 1062 | max_iterations: Optional[int] = 15 |
| 1063 | """The maximum number of steps to take before ending the execution |
| 1064 | loop. |
| 1065 | |
| 1066 | Setting to 'None' could lead to an infinite loop.""" |
| 1067 | max_execution_time: Optional[float] = None |
| 1068 | """The maximum amount of wall clock time to spend in the execution |
| 1069 | loop. |
| 1070 | """ |
| 1071 | early_stopping_method: str = "force" |
| 1072 | """The method to use for early stopping if the agent never |
| 1073 | returns `AgentFinish`. Either 'force' or 'generate'. |
| 1074 | |
| 1075 | `"force"` returns a string saying that it stopped because it met a |
| 1076 | time or iteration limit. |
| 1077 | |
| 1078 | `"generate"` calls the agent's LLM Chain one final time to generate |
| 1079 | a final answer based on the previous steps. |
| 1080 | """ |
| 1081 | handle_parsing_errors: Union[ |
| 1082 | bool, str, Callable[[OutputParserException], str] |
| 1083 | ] = False |
| 1084 | """How to handle errors raised by the agent's output parser. |
| 1085 | Defaults to `False`, which raises the error. |
| 1086 | If `true`, the error will be sent back to the LLM as an observation. |
| 1087 | If a string, the string itself will be sent to the LLM as an observation. |
| 1088 | If a callable function, the function will be called with the exception |
| 1089 | as an argument, and the result of that function will be passed to the agent |
| 1090 | as an observation. |
| 1091 | """ |
| 1092 | trim_intermediate_steps: Union[ |
| 1093 | int, Callable[[List[Tuple[AgentAction, str]]], List[Tuple[AgentAction, str]]] |
| 1094 | ] = -1 |
| 1095 | """How to trim the intermediate steps before returning them. |
| 1096 | Defaults to -1, which means no trimming. |
| 1097 | """ |
| 1098 | |
| 1099 | @classmethod |
| 1100 | def from_agent_and_tools( |
| 1101 | cls, |
| 1102 | agent: Union[BaseSingleActionAgent, BaseMultiActionAgent], |
| 1103 | tools: Sequence[BaseTool], |
| 1104 | callbacks: Callbacks = None, |
| 1105 | **kwargs: Any, |
| 1106 | ) -> AgentExecutor: |
| 1107 | """Create from agent and tools. |
| 1108 |
no outgoing calls