Home / Function/ _perform_agent_action() — langchain Function Reference

_perform_agent_action() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  eda0641b_0f0e_a635_b675_0446cbdc0636["_perform_agent_action()"]
  493d4ce4_2303_08e0_2337_2bee34fe2662["AgentExecutor"]
  eda0641b_0f0e_a635_b675_0446cbdc0636 -->|defined in| 493d4ce4_2303_08e0_2337_2bee34fe2662
  3ad3236e_1a51_9e04_5055_95c7d2147238["_iter_next_step()"]
  3ad3236e_1a51_9e04_5055_95c7d2147238 -->|calls| eda0641b_0f0e_a635_b675_0446cbdc0636
  c88bc836_f328_3f17_0fd2_8dcc7203a6ca["tool_run_logging_kwargs()"]
  eda0641b_0f0e_a635_b675_0446cbdc0636 -->|calls| c88bc836_f328_3f17_0fd2_8dcc7203a6ca
  style eda0641b_0f0e_a635_b675_0446cbdc0636 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/agent.py lines 1380–1417

    def _perform_agent_action(
        self,
        name_to_tool_map: dict[str, BaseTool],
        color_mapping: dict[str, str],
        agent_action: AgentAction,
        run_manager: CallbackManagerForChainRun | None = None,
    ) -> AgentStep:
        if run_manager:
            run_manager.on_agent_action(agent_action, color="green")
        # Otherwise we lookup the tool
        if agent_action.tool in name_to_tool_map:
            tool = name_to_tool_map[agent_action.tool]
            return_direct = tool.return_direct
            color = color_mapping[agent_action.tool]
            tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
            if return_direct:
                tool_run_kwargs["llm_prefix"] = ""
            # We then call the tool on the tool input to get an observation
            observation = tool.run(
                agent_action.tool_input,
                verbose=self.verbose,
                color=color,
                callbacks=run_manager.get_child() if run_manager else None,
                **tool_run_kwargs,
            )
        else:
            tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
            observation = InvalidTool().run(
                {
                    "requested_tool_name": agent_action.tool,
                    "available_tool_names": list(name_to_tool_map.keys()),
                },
                verbose=self.verbose,
                color=None,
                callbacks=run_manager.get_child() if run_manager else None,
                **tool_run_kwargs,
            )
        return AgentStep(action=agent_action, observation=observation)

Subdomains

Called By

Frequently Asked Questions

What does _perform_agent_action() do?
_perform_agent_action() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is _perform_agent_action() defined?
_perform_agent_action() is defined in libs/langchain/langchain_classic/agents/agent.py at line 1380.
What does _perform_agent_action() call?
_perform_agent_action() calls 1 function(s): tool_run_logging_kwargs.
What calls _perform_agent_action()?
_perform_agent_action() is called by 1 function(s): _iter_next_step.

Analyze Your Own Codebase

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

Try Supermodel Free