Home / Function/ plan() — langchain Function Reference

plan() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f3744a6a_d6e6_3de9_26d0_166fe46f3862["plan()"]
  d4aecf89_003b_4fb4_2c03_b614dbd33066["RunnableAgent"]
  f3744a6a_d6e6_3de9_26d0_166fe46f3862 -->|defined in| d4aecf89_003b_4fb4_2c03_b614dbd33066
  ff3ae374_f735_73ee_26e0_538ba433911c["plan()"]
  ff3ae374_f735_73ee_26e0_538ba433911c -->|calls| f3744a6a_d6e6_3de9_26d0_166fe46f3862
  fff15887_2a1c_dee2_d5a0_3a5aa4536868["stream()"]
  f3744a6a_d6e6_3de9_26d0_166fe46f3862 -->|calls| fff15887_2a1c_dee2_d5a0_3a5aa4536868
  ff3ae374_f735_73ee_26e0_538ba433911c["plan()"]
  f3744a6a_d6e6_3de9_26d0_166fe46f3862 -->|calls| ff3ae374_f735_73ee_26e0_538ba433911c
  style f3744a6a_d6e6_3de9_26d0_166fe46f3862 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/agent.py lines 419–453

    def plan(
        self,
        intermediate_steps: list[tuple[AgentAction, str]],
        callbacks: Callbacks = None,
        **kwargs: Any,
    ) -> AgentAction | AgentFinish:
        """Based on past history and current inputs, decide 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.
        """
        inputs = {**kwargs, "intermediate_steps": intermediate_steps}
        final_output: Any = None
        if self.stream_runnable:
            # Use streaming to make sure that the underlying LLM is invoked in a
            # streaming
            # fashion to make it possible to get access to the individual LLM tokens
            # when using stream_log with the AgentExecutor.
            # Because the response from the plan is not a generator, we need to
            # accumulate the output into final output and return that.
            for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}):
                if final_output is None:
                    final_output = chunk
                else:
                    final_output += chunk
        else:
            final_output = self.runnable.invoke(inputs, config={"callbacks": callbacks})

        return final_output

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free