Home / Function/ plan() — langchain Function Reference

plan() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e61b97a0_a30f_f26b_a40c_5a19997cbc7a["plan()"]
  b444f628_93a3_fafc_0827_7b9ca1eef67c["OpenAIFunctionsAgent"]
  e61b97a0_a30f_f26b_a40c_5a19997cbc7a -->|defined in| b444f628_93a3_fafc_0827_7b9ca1eef67c
  733cd46d_9603_479f_3b46_461bc1275a5f["return_stopped_response()"]
  733cd46d_9603_479f_3b46_461bc1275a5f -->|calls| e61b97a0_a30f_f26b_a40c_5a19997cbc7a
  style e61b97a0_a30f_f26b_a40c_5a19997cbc7a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/openai_functions_agent/base.py lines 96–135

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

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

        Returns:
            Action specifying what tool to use.
            If the agent is finished, returns an `AgentFinish`.
            If the agent is not finished, returns an `AgentAction`.
        """
        agent_scratchpad = format_to_openai_function_messages(intermediate_steps)
        selected_inputs = {
            k: kwargs[k] for k in self.prompt.input_variables if k != "agent_scratchpad"
        }
        full_inputs = dict(**selected_inputs, agent_scratchpad=agent_scratchpad)
        prompt = self.prompt.format_prompt(**full_inputs)
        messages = prompt.to_messages()
        if with_functions:
            predicted_message = self.llm.invoke(
                messages,
                functions=self.functions,
                callbacks=callbacks,
            )
        else:
            predicted_message = self.llm.invoke(
                messages,
                callbacks=callbacks,
            )
        return self.output_parser.parse_ai_message(predicted_message)

Subdomains

Frequently Asked Questions

What does plan() do?
plan() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/openai_functions_agent/base.py.
Where is plan() defined?
plan() is defined in libs/langchain/langchain_classic/agents/openai_functions_agent/base.py at line 96.
What calls plan()?
plan() is called by 1 function(s): return_stopped_response.

Analyze Your Own Codebase

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

Try Supermodel Free