Home / Function/ _acall() — langchain Function Reference

_acall() — langchain Function Reference

Architecture documentation for the _acall() function in agent.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85["_acall()"]
  ec1d7866_e6a8_7cbe_b150_f82463cf2c7f["AgentExecutor"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|defined in| ec1d7866_e6a8_7cbe_b150_f82463cf2c7f
  8ea977d6_e68d_c098_5604_d49cfeca3283["_should_continue()"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|calls| 8ea977d6_e68d_c098_5604_d49cfeca3283
  6d8fc449_aee7_2cd6_c1e9_4b5f0ccb1751["_atake_next_step()"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|calls| 6d8fc449_aee7_2cd6_c1e9_4b5f0ccb1751
  e6e70442_6c0c_5b5e_500a_c4a9f0ae4a61["_areturn()"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|calls| e6e70442_6c0c_5b5e_500a_c4a9f0ae4a61
  a149a21d_3335_2c5e_ba3e_c9aa008afbf7["_get_tool_return()"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|calls| a149a21d_3335_2c5e_ba3e_c9aa008afbf7
  91ad3c4b_7d4d_167d_7a4e_117cb9d64e89["return_stopped_response()"]
  3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 -->|calls| 91ad3c4b_7d4d_167d_7a4e_117cb9d64e89
  style 3a34a1ff_e9ef_cf10_6260_9d4fa1b12d85 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/agent.py lines 1624–1695

    async def _acall(
        self,
        inputs: dict[str, str],
        run_manager: AsyncCallbackManagerForChainRun | None = None,
    ) -> dict[str, str]:
        """Async run text through and get agent response."""
        # Construct a mapping of tool name to tool for easy lookup
        name_to_tool_map = {tool.name: tool for tool in self.tools}
        # We construct a mapping from each tool to a color, used for logging.
        color_mapping = get_color_mapping(
            [tool.name for tool in self.tools],
            excluded_colors=["green"],
        )
        intermediate_steps: list[tuple[AgentAction, str]] = []
        # Let's start tracking the number of iterations and time elapsed
        iterations = 0
        time_elapsed = 0.0
        start_time = time.time()
        # We now enter the agent loop (until it returns something).
        try:
            async with asyncio_timeout(self.max_execution_time):
                while self._should_continue(iterations, time_elapsed):
                    next_step_output = await self._atake_next_step(
                        name_to_tool_map,
                        color_mapping,
                        inputs,
                        intermediate_steps,
                        run_manager=run_manager,
                    )
                    if isinstance(next_step_output, AgentFinish):
                        return await self._areturn(
                            next_step_output,
                            intermediate_steps,
                            run_manager=run_manager,
                        )

                    intermediate_steps.extend(next_step_output)
                    if len(next_step_output) == 1:
                        next_step_action = next_step_output[0]
                        # See if tool should return directly
                        tool_return = self._get_tool_return(next_step_action)
                        if tool_return is not None:
                            return await self._areturn(
                                tool_return,
                                intermediate_steps,
                                run_manager=run_manager,
                            )

                    iterations += 1
                    time_elapsed = time.time() - start_time
                output = self._action_agent.return_stopped_response(
                    self.early_stopping_method,
                    intermediate_steps,
                    **inputs,
                )
                return await self._areturn(
                    output,
                    intermediate_steps,
                    run_manager=run_manager,
                )
        except (TimeoutError, asyncio.TimeoutError):
            # stop early when interrupted by the async timeout
            output = self._action_agent.return_stopped_response(
                self.early_stopping_method,
                intermediate_steps,
                **inputs,
            )
            return await self._areturn(
                output,
                intermediate_steps,
                run_manager=run_manager,
            )

Subdomains

Frequently Asked Questions

What does _acall() do?
_acall() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is _acall() defined?
_acall() is defined in libs/langchain/langchain_classic/agents/agent.py at line 1624.
What does _acall() call?
_acall() calls 5 function(s): _areturn, _atake_next_step, _get_tool_return, _should_continue, return_stopped_response.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free