Home / Class/ LLMSingleActionAgent Class — langchain Architecture

LLMSingleActionAgent Class — langchain Architecture

Architecture documentation for the LLMSingleActionAgent class in agent.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  0d209def_9564_c52d_db1c_fc156804d62d["LLMSingleActionAgent"]
  2066c331_3189_1880_ba09_f5a3c375c553["BaseSingleActionAgent"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|extends| 2066c331_3189_1880_ba09_f5a3c375c553
  0faae8c7_2812_be15_1073_b6537539cea8["agent.py"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|defined in| 0faae8c7_2812_be15_1073_b6537539cea8
  83e4fb9b_394f_22f8_533a_1d7a129c6d1e["input_keys()"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|method| 83e4fb9b_394f_22f8_533a_1d7a129c6d1e
  f53d8b5e_d30a_de4d_2e3d_9cc35a4960ef["dict()"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|method| f53d8b5e_d30a_de4d_2e3d_9cc35a4960ef
  da414754_46c8_b43f_35f5_b0bbed5b0c7e["plan()"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|method| da414754_46c8_b43f_35f5_b0bbed5b0c7e
  5abe9fa6_dd3a_d566_d506_61ece1034db8["aplan()"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|method| 5abe9fa6_dd3a_d566_d506_61ece1034db8
  8d6ec710_c308_189e_7dfc_86cb758394e4["tool_run_logging_kwargs()"]
  0d209def_9564_c52d_db1c_fc156804d62d -->|method| 8d6ec710_c308_189e_7dfc_86cb758394e4

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/agent.py lines 615–696

class LLMSingleActionAgent(BaseSingleActionAgent):
    """Base class for single action agents."""

    llm_chain: LLMChain
    """LLMChain to use for agent."""
    output_parser: AgentOutputParser
    """Output parser to use for agent."""
    stop: list[str]
    """List of strings to stop on."""

    @property
    def input_keys(self) -> list[str]:
        """Return the input keys.

        Returns:
            List of input keys.
        """
        return list(set(self.llm_chain.input_keys) - {"intermediate_steps"})

    @override
    def dict(self, **kwargs: Any) -> builtins.dict:
        """Return dictionary representation of agent."""
        _dict = super().dict()
        del _dict["output_parser"]
        return _dict

    def plan(
        self,
        intermediate_steps: list[tuple[AgentAction, str]],
        callbacks: Callbacks = None,
        **kwargs: Any,
    ) -> AgentAction | AgentFinish:
        """Given input, decided what to do.

        Args:
            intermediate_steps: Steps the LLM has taken to date,
                along with the observations.
            callbacks: Callbacks to run.
            **kwargs: User inputs.

        Returns:
            Action specifying what tool to use.
        """
        output = self.llm_chain.run(
            intermediate_steps=intermediate_steps,
            stop=self.stop,
            callbacks=callbacks,
            **kwargs,
        )
        return self.output_parser.parse(output)

    async def aplan(
        self,
        intermediate_steps: list[tuple[AgentAction, str]],
        callbacks: Callbacks = None,
        **kwargs: Any,
    ) -> AgentAction | AgentFinish:
        """Async given input, decided what to do.

        Args:
            intermediate_steps: Steps the LLM has taken to date,
                along with observations.
            callbacks: Callbacks to run.
            **kwargs: User inputs.

        Returns:
            Action specifying what tool to use.
        """
        output = await self.llm_chain.arun(
            intermediate_steps=intermediate_steps,
            stop=self.stop,
            callbacks=callbacks,
            **kwargs,
        )
        return self.output_parser.parse(output)

    def tool_run_logging_kwargs(self) -> builtins.dict:
        """Return logging kwargs for tool run."""
        return {
            "llm_prefix": "",
            "observation_prefix": "" if len(self.stop) == 0 else self.stop[0],

Frequently Asked Questions

What is the LLMSingleActionAgent class?
LLMSingleActionAgent is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is LLMSingleActionAgent defined?
LLMSingleActionAgent is defined in libs/langchain/langchain_classic/agents/agent.py at line 615.
What does LLMSingleActionAgent extend?
LLMSingleActionAgent extends BaseSingleActionAgent.

Analyze Your Own Codebase

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

Try Supermodel Free