diff --git a/libs/langchain/langchain/agents/json_chat/base.py b/libs/langchain/langchain/agents/json_chat/base.py index 3e34568a972..ffabf68921b 100644 --- a/libs/langchain/langchain/agents/json_chat/base.py +++ b/libs/langchain/langchain/agents/json_chat/base.py @@ -19,10 +19,7 @@ def create_json_chat_agent( Args: llm: LLM to use as the agent. tools: Tools this agent has access to. - prompt: The prompt to use, must have input keys: - `tools`: contains descriptions and arguments for each tool. - `tool_names`: contains all tool names. - `agent_scratchpad`: contains previous agent actions and tool outputs. + prompt: The prompt to use. See Prompt section below for more. Returns: A Runnable sequence representing an agent. It takes as input all the same input @@ -58,7 +55,14 @@ def create_json_chat_agent( } ) - Creating prompt example: + Prompt: + + The prompt must have input keys: + * `tools`: contains descriptions and arguments for each tool. + * `tool_names`: contains all tool names. + * `agent_scratchpad`: must be a MessagesPlaceholder. Contains previous agent actions and tool outputs as messages. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/openai_functions_agent/base.py b/libs/langchain/langchain/agents/openai_functions_agent/base.py index e0180693202..633d7a27cd6 100644 --- a/libs/langchain/langchain/agents/openai_functions_agent/base.py +++ b/libs/langchain/langchain/agents/openai_functions_agent/base.py @@ -239,8 +239,7 @@ def create_openai_functions_agent( so either be an OpenAI model that supports that or a wrapper of a different model that adds in equivalent support. tools: Tools this agent has access to. - prompt: The prompt to use, must have input key `agent_scratchpad`, which will - contain agent action and tool output messages. + prompt: The prompt to use. See Prompt section below for more. Returns: A Runnable sequence representing an agent. It takes as input all the same input @@ -278,7 +277,13 @@ def create_openai_functions_agent( } ) - Creating prompt example: + Prompt: + + The agent prompt must have an `agent_scratchpad` key that is a + ``MessagesPlaceholder``. Intermediate agent actions and tool output + messages will be passed in here. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/openai_tools/base.py b/libs/langchain/langchain/agents/openai_tools/base.py index 4395fb32bbd..e76ccd994ef 100644 --- a/libs/langchain/langchain/agents/openai_tools/base.py +++ b/libs/langchain/langchain/agents/openai_tools/base.py @@ -20,8 +20,8 @@ def create_openai_tools_agent( Args: llm: LLM to use as the agent. tools: Tools this agent has access to. - prompt: The prompt to use, must have input key `agent_scratchpad`, which will - contain agent action and tool output messages. + prompt: The prompt to use. See Prompt section below for more on the expected + input variables. Returns: A Runnable sequence representing an agent. It takes as input all the same input @@ -57,7 +57,13 @@ def create_openai_tools_agent( } ) - Creating prompt example: + Prompt: + + The agent prompt must have an `agent_scratchpad` key that is a + ``MessagesPlaceholder``. Intermediate agent actions and tool output + messages will be passed in here. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/react/agent.py b/libs/langchain/langchain/agents/react/agent.py index 23277c36540..93709fca65b 100644 --- a/libs/langchain/langchain/agents/react/agent.py +++ b/libs/langchain/langchain/agents/react/agent.py @@ -20,11 +20,7 @@ def create_react_agent( Args: llm: LLM to use as the agent. tools: Tools this agent has access to. - prompt: The prompt to use, must have input keys: - `tools`: contains descriptions and arguments for each tool. - `tool_names`: contains all tool names. - `agent_scratchpad`: contains previous agent actions and tool outputs. - + prompt: The prompt to use. See Prompt section below for more. Returns: A Runnable sequence representing an agent. It takes as input all the same input @@ -59,7 +55,14 @@ def create_react_agent( } ) - Creating prompt example: + Prompt: + + The prompt must have input keys: + * `tools`: contains descriptions and arguments for each tool. + * `tool_names`: contains all tool names. + * `agent_scratchpad`: contains previous agent actions and tool outputs as a string. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/self_ask_with_search/base.py b/libs/langchain/langchain/agents/self_ask_with_search/base.py index d7526f4c548..26447f0239a 100644 --- a/libs/langchain/langchain/agents/self_ask_with_search/base.py +++ b/libs/langchain/langchain/agents/self_ask_with_search/base.py @@ -121,7 +121,12 @@ def create_self_ask_with_search_agent( agent_executor.invoke({"input": "hi"}) - Create prompt example: + Prompt: + + The prompt must have input key `agent_scratchpad` which will + contain agent actions and tool outputs as a string. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/structured_chat/base.py b/libs/langchain/langchain/agents/structured_chat/base.py index ef037860d3c..3dc29b754bd 100644 --- a/libs/langchain/langchain/agents/structured_chat/base.py +++ b/libs/langchain/langchain/agents/structured_chat/base.py @@ -158,10 +158,7 @@ def create_structured_chat_agent( Args: llm: LLM to use as the agent. tools: Tools this agent has access to. - prompt: The prompt to use, must have input keys - `tools`: contains descriptions and arguments for each tool. - `tool_names`: contains all tool names. - `agent_scratchpad`: contains previous agent actions and tool outputs. + prompt: The prompt to use. See Prompt section below for more. Returns: A Runnable sequence representing an agent. It takes as input all the same input @@ -197,7 +194,14 @@ def create_structured_chat_agent( } ) - Creating prompt example: + Prompt: + + The prompt must have input keys: + * `tools`: contains descriptions and arguments for each tool. + * `tool_names`: contains all tool names. + * `agent_scratchpad`: contains previous agent actions and tool outputs as a string. + + Here's an example: .. code-block:: python diff --git a/libs/langchain/langchain/agents/xml/base.py b/libs/langchain/langchain/agents/xml/base.py index be85a7b9738..fe3f4883ece 100644 --- a/libs/langchain/langchain/agents/xml/base.py +++ b/libs/langchain/langchain/agents/xml/base.py @@ -152,7 +152,13 @@ def create_xml_agent( } ) - Creating prompt example: + Prompt: + + The prompt must have input keys: + * `tools`: contains descriptions for each tool. + * `agent_scratchpad`: contains previous agent actions and tool outputs as an XML string. + + Here's an example: .. code-block:: python