mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-03 19:57:51 +00:00
langchain[patch]: agents check prompt partial vars (#20303)
This commit is contained in:
parent
cb25fa0d55
commit
e936fba428
@ -155,7 +155,7 @@ def create_json_chat_agent(
|
|||||||
)
|
)
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
||||||
prompt.input_variables
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
)
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
@ -298,7 +298,9 @@ def create_openai_functions_agent(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
if "agent_scratchpad" not in prompt.input_variables:
|
if "agent_scratchpad" not in (
|
||||||
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
|
):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Prompt must have input variable `agent_scratchpad`, but wasn't found. "
|
"Prompt must have input variable `agent_scratchpad`, but wasn't found. "
|
||||||
f"Found {prompt.input_variables} instead."
|
f"Found {prompt.input_variables} instead."
|
||||||
|
@ -78,7 +78,9 @@ def create_openai_tools_agent(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
missing_vars = {"agent_scratchpad"}.difference(prompt.input_variables)
|
missing_vars = {"agent_scratchpad"}.difference(
|
||||||
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ def create_react_agent(
|
|||||||
prompt = PromptTemplate.from_template(template)
|
prompt = PromptTemplate.from_template(template)
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
||||||
prompt.input_variables
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
)
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
@ -173,7 +173,9 @@ def create_self_ask_with_search_agent(
|
|||||||
|
|
||||||
prompt = PromptTemplate.from_template(template)
|
prompt = PromptTemplate.from_template(template)
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
missing_vars = {"agent_scratchpad"}.difference(prompt.input_variables)
|
missing_vars = {"agent_scratchpad"}.difference(
|
||||||
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ def create_structured_chat_agent(
|
|||||||
)
|
)
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
missing_vars = {"tools", "tool_names", "agent_scratchpad"}.difference(
|
||||||
prompt.input_variables
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
)
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
@ -33,14 +33,14 @@ def create_tool_calling_agent(
|
|||||||
|
|
||||||
from langchain.agents import AgentExecutor, create_tool_calling_agent, tool
|
from langchain.agents import AgentExecutor, create_tool_calling_agent, tool
|
||||||
from langchain_anthropic import ChatAnthropic
|
from langchain_anthropic import ChatAnthropic
|
||||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
from langchain_core.prompts import ChatPromptTemplate
|
||||||
|
|
||||||
prompt = ChatPromptTemplate.from_messages(
|
prompt = ChatPromptTemplate.from_messages(
|
||||||
[
|
[
|
||||||
("system", "You are a helpful assistant"),
|
("system", "You are a helpful assistant"),
|
||||||
MessagesPlaceholder("chat_history", optional=True),
|
("placeholder", "{chat_history}",
|
||||||
("human", "{input}"),
|
("human", "{input}"),
|
||||||
MessagesPlaceholder("agent_scratchpad"),
|
("placeholder", "{agent_scratchpad}"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
model = ChatAnthropic(model="claude-3-opus-20240229")
|
model = ChatAnthropic(model="claude-3-opus-20240229")
|
||||||
@ -75,7 +75,9 @@ def create_tool_calling_agent(
|
|||||||
``MessagesPlaceholder``. Intermediate agent actions and tool output
|
``MessagesPlaceholder``. Intermediate agent actions and tool output
|
||||||
messages will be passed in here.
|
messages will be passed in here.
|
||||||
"""
|
"""
|
||||||
missing_vars = {"agent_scratchpad"}.difference(prompt.input_variables)
|
missing_vars = {"agent_scratchpad"}.difference(
|
||||||
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
|
||||||
|
@ -203,7 +203,9 @@ def create_xml_agent(
|
|||||||
{agent_scratchpad}'''
|
{agent_scratchpad}'''
|
||||||
prompt = PromptTemplate.from_template(template)
|
prompt = PromptTemplate.from_template(template)
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
missing_vars = {"tools", "agent_scratchpad"}.difference(prompt.input_variables)
|
missing_vars = {"tools", "agent_scratchpad"}.difference(
|
||||||
|
prompt.input_variables + list(prompt.partial_variables)
|
||||||
|
)
|
||||||
if missing_vars:
|
if missing_vars:
|
||||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user