MCPcopy
hub / github.com/SqueezeAILab/LLMCompiler / _acall

Method _acall

src/executors/agent_executor.py:487–546  ·  view source on GitHub ↗

Run text through and get agent response.

(
        self,
        inputs: Dict[str, str],
        run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
    )

Source from the content-addressed store, hash-verified

485 return self._return(output, intermediate_steps, run_manager=run_manager)
486
487 async def _acall(
488 self,
489 inputs: Dict[str, str],
490 run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
491 ) -> Dict[str, str]:
492 """Run text through and get agent response."""
493 # Construct a mapping of tool name to tool for easy lookup
494 name_to_tool_map = {tool.name: tool for tool in self.tools}
495 # We construct a mapping from each tool to a color, used for logging.
496 color_mapping = get_color_mapping(
497 [tool.name for tool in self.tools], excluded_colors=["green"]
498 )
499 intermediate_steps: List[Tuple[AgentAction, str]] = []
500 # Let's start tracking the number of iterations and time elapsed
501 iterations = 0
502 time_elapsed = 0.0
503 start_time = time.time()
504 # We now enter the agent loop (until it returns something).
505 async with asyncio_timeout(self.max_execution_time):
506 try:
507 while self._should_continue(iterations, time_elapsed):
508 next_step_output = await self._atake_next_step(
509 name_to_tool_map,
510 color_mapping,
511 inputs,
512 intermediate_steps,
513 run_manager=run_manager,
514 )
515 if isinstance(next_step_output, AgentFinish):
516 return await self._areturn(
517 next_step_output,
518 intermediate_steps,
519 run_manager=run_manager,
520 )
521 intermediate_steps.extend(next_step_output)
522 if len(next_step_output) == 1:
523 next_step_action = next_step_output[0]
524 # See if tool should return directly
525 tool_return = self._get_tool_return(next_step_action)
526 if tool_return is not None:
527 return await self._areturn(
528 tool_return, intermediate_steps, run_manager=run_manager
529 )
530
531 iterations += 1
532 time_elapsed = time.time() - start_time
533 output = self.agent.return_stopped_response(
534 self.early_stopping_method, intermediate_steps, **inputs
535 )
536 return await self._areturn(
537 output, intermediate_steps, run_manager=run_manager
538 )
539 except TimeoutError:
540 # stop early when interrupted by the async timeout
541 output = self.agent.return_stopped_response(
542 self.early_stopping_method, intermediate_steps, **inputs
543 )
544 return await self._areturn(

Callers

nothing calls this directly

Calls 5

_should_continueMethod · 0.95
_atake_next_stepMethod · 0.95
_areturnMethod · 0.95
_get_tool_returnMethod · 0.95

Tested by

no test coverage detected