Home / Function/ _call() — langchain Function Reference

_call() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  edf0069e_99f2_31ed_6ba2_2ed571e40c37["_call()"]
  493d4ce4_2303_08e0_2337_2bee34fe2662["AgentExecutor"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|defined in| 493d4ce4_2303_08e0_2337_2bee34fe2662
  3ae56802_4473_30c3_edb2_2b4283afafdf["_should_continue()"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|calls| 3ae56802_4473_30c3_edb2_2b4283afafdf
  6bfe2643_2a71_0c79_faed_e4c7639bab34["_take_next_step()"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|calls| 6bfe2643_2a71_0c79_faed_e4c7639bab34
  edb6329e_28b7_5b52_d3e5_499df4131105["_return()"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|calls| edb6329e_28b7_5b52_d3e5_499df4131105
  6318fe2c_c718_cc8e_b66f_30bc2f54d1dc["_get_tool_return()"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|calls| 6318fe2c_c718_cc8e_b66f_30bc2f54d1dc
  31847858_1e19_c0bf_132c_30d6dcde5937["return_stopped_response()"]
  edf0069e_99f2_31ed_6ba2_2ed571e40c37 -->|calls| 31847858_1e19_c0bf_132c_30d6dcde5937
  style edf0069e_99f2_31ed_6ba2_2ed571e40c37 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/agent.py lines 1570–1622

    def _call(
        self,
        inputs: dict[str, str],
        run_manager: CallbackManagerForChainRun | None = None,
    ) -> dict[str, Any]:
        """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", "red"],
        )
        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).
        while self._should_continue(iterations, time_elapsed):
            next_step_output = self._take_next_step(
                name_to_tool_map,
                color_mapping,
                inputs,
                intermediate_steps,
                run_manager=run_manager,
            )
            if isinstance(next_step_output, AgentFinish):
                return self._return(
                    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 self._return(
                        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 self._return(output, intermediate_steps, run_manager=run_manager)

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free