mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 21:33:31 -04:00
13d1df2140
`AgentExecutor` already has support for limiting the number of iterations. But the amount of time taken for each iteration can vary quite a bit, so it is difficult to place limits on the execution time. This PR adds a new field `max_execution_time` to the `AgentExecutor` model. When called asynchronously, the agent loop is wrapped in an `asyncio.timeout()` context which triggers the early stopping response if the time limit is reached. When called synchronously, the agent loop checks for both the max_iteration limit and the time limit after each iteration. When used asynchronously `max_execution_time` gives really tight control over the max time for an execution chain. When used synchronously, the chain can unfortunately exceed max_execution_time, but it still gives more control than trying to estimate the number of max_iterations needed to cap the execution time. --------- Co-authored-by: Zachary Jones <zjones@zetaglobal.com>
12 lines
274 B
Python
12 lines
274 B
Python
"""Shims for asyncio features that may be missing from older python versions"""
|
|
|
|
import sys
|
|
|
|
if sys.version_info[:2] < (3, 11):
|
|
from async_timeout import timeout as asyncio_timeout
|
|
else:
|
|
from asyncio import timeout as asyncio_timeout
|
|
|
|
|
|
__all__ = ["asyncio_timeout"]
|