@ -659,6 +659,9 @@ s
as an argument , and the result of that function will be passed to the agent
as an argument , and the result of that function will be passed to the agent
as an observation .
as an observation .
"""
"""
trim_intermediate_steps : Union [
int , Callable [ [ List [ Tuple [ AgentAction , str ] ] ] , List [ Tuple [ AgentAction , str ] ] ]
] = - 1
@classmethod
@classmethod
def from_agent_and_tools (
def from_agent_and_tools (
@ -788,6 +791,8 @@ s
Override this to take control of how the agent makes and acts on choices .
Override this to take control of how the agent makes and acts on choices .
"""
"""
try :
try :
intermediate_steps = self . _prepare_intermediate_steps ( intermediate_steps )
# Call the LLM to see what to do.
# Call the LLM to see what to do.
output = self . agent . plan (
output = self . agent . plan (
intermediate_steps ,
intermediate_steps ,
@ -879,6 +884,8 @@ s
Override this to take control of how the agent makes and acts on choices .
Override this to take control of how the agent makes and acts on choices .
"""
"""
try :
try :
intermediate_steps = self . _prepare_intermediate_steps ( intermediate_steps )
# Call the LLM to see what to do.
# Call the LLM to see what to do.
output = await self . agent . aplan (
output = await self . agent . aplan (
intermediate_steps ,
intermediate_steps ,
@ -1088,3 +1095,16 @@ s
" " ,
" " ,
)
)
return None
return None
def _prepare_intermediate_steps (
self , intermediate_steps : List [ Tuple [ AgentAction , str ] ]
) - > List [ Tuple [ AgentAction , str ] ] :
if (
isinstance ( self . trim_intermediate_steps , int )
and self . trim_intermediate_steps > 0
) :
return intermediate_steps [ - self . trim_intermediate_steps : ]
elif callable ( self . trim_intermediate_steps ) :
return self . trim_intermediate_steps ( intermediate_steps )
else :
return intermediate_steps