Final Answer: foo
> Finished chain.
'foo'
Now let’s try it again with the max_execution_time=1 keyword argument. It now stops nicely after 1 second (only one iteration usually)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_execution_time=1)
agent.run(adversarial_prompt)
> Entering new AgentExecutor chain...
 What can I do to answer this question?
Action: Jester
Action Input: foo
Observation: foo
Thought:
> Finished chain.
'Agent stopped due to iteration limit or time limit.'
By default, the early stopping uses method force which just returns that constant string. Alternatively, you could specify method generate which then does one FINAL pass through the LLM to generate an output.
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_execution_time=1, early_stopping_method="generate")
agent.run(adversarial_prompt)
> Entering new AgentExecutor chain...
 What can I do to answer this question?
Action: Jester
Action Input: foo
Observation: foo
Thought: Is there more I can do?
Action: Jester
Action Input: foo
Observation: foo
Thought:
Final Answer: foo
> Finished chain.
'foo'
previous
How to cap the max number of iterations
next
How to add SharedMemory to an Agent and its Tools
By Harrison Chase
    
      © Copyright 2023, Harrison Chase.
      
  Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/agent_executors/examples/max_time_limit.html