Home / Function/ create_prompt() — langchain Function Reference

create_prompt() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  dd42c06c_77f0_b662_e83b_319540fa0e7e["create_prompt()"]
  e7474b7d_7c6f_343d_99cb_0f111d536a66["ChatAgent"]
  dd42c06c_77f0_b662_e83b_319540fa0e7e -->|defined in| e7474b7d_7c6f_343d_99cb_0f111d536a66
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4["from_llm_and_tools()"]
  b33ef912_f36b_c48c_f62d_fdb8762ff5d4 -->|calls| dd42c06c_77f0_b662_e83b_319540fa0e7e
  style dd42c06c_77f0_b662_e83b_319540fa0e7e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/chat/base.py lines 83–120

    def create_prompt(
        cls,
        tools: Sequence[BaseTool],
        system_message_prefix: str = SYSTEM_MESSAGE_PREFIX,
        system_message_suffix: str = SYSTEM_MESSAGE_SUFFIX,
        human_message: str = HUMAN_MESSAGE,
        format_instructions: str = FORMAT_INSTRUCTIONS,
        input_variables: list[str] | None = None,
    ) -> BasePromptTemplate:
        """Create a prompt from a list of tools.

        Args:
            tools: A list of tools.
            system_message_prefix: The system message prefix.
            system_message_suffix: The system message suffix.
            human_message: The `HumanMessage`.
            format_instructions: The format instructions.
            input_variables: The input variables.

        Returns:
            A prompt template.
        """
        tool_strings = "\n".join([f"{tool.name}: {tool.description}" for tool in tools])
        tool_names = ", ".join([tool.name for tool in tools])
        format_instructions = format_instructions.format(tool_names=tool_names)
        template = (
            f"{system_message_prefix}\n\n"
            f"{tool_strings}\n\n"
            f"{format_instructions}\n\n"
            f"{system_message_suffix}"
        )
        messages = [
            SystemMessagePromptTemplate.from_template(template),
            HumanMessagePromptTemplate.from_template(human_message),
        ]
        if input_variables is None:
            input_variables = ["input", "agent_scratchpad"]
        return ChatPromptTemplate(input_variables=input_variables, messages=messages)

Subdomains

Frequently Asked Questions

What does create_prompt() do?
create_prompt() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/chat/base.py.
Where is create_prompt() defined?
create_prompt() is defined in libs/langchain/langchain_classic/agents/chat/base.py at line 83.
What calls create_prompt()?
create_prompt() is called by 1 function(s): from_llm_and_tools.

Analyze Your Own Codebase

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

Try Supermodel Free