From 5ade0187d070ec88d0d6c3ffb028c294161b4fb5 Mon Sep 17 00:00:00 2001 From: Mohammad Mohtashim <45242107+keenborder786@users.noreply.github.com> Date: Mon, 22 Jul 2024 19:04:20 +0500 Subject: [PATCH] [Commutiy]: Prompts Fixed for ZERO_SHOT_REACT React Agent Type in `create_sql_agent` function (#23693) - **Description:** The correct Prompts for ZERO_SHOT_REACT were not being used in the `create_sql_agent` function. They were not using the specific `SQL_PREFIX` and `SQL_SUFFIX` prompts if client does not provide any prompts. This is fixed. - **Issue:** #23585 --------- Co-authored-by: ccurme --- .../langchain_community/agent_toolkits/sql/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/agent_toolkits/sql/base.py b/libs/community/langchain_community/agent_toolkits/sql/base.py index 12a1200ee9d..a738b0b9482 100644 --- a/libs/community/langchain_community/agent_toolkits/sql/base.py +++ b/libs/community/langchain_community/agent_toolkits/sql/base.py @@ -25,6 +25,7 @@ from langchain_core.prompts.chat import ( from langchain_community.agent_toolkits.sql.prompt import ( SQL_FUNCTIONS_SUFFIX, SQL_PREFIX, + SQL_SUFFIX, ) from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit from langchain_community.tools.sql_database.tool import ( @@ -140,8 +141,9 @@ def create_sql_agent( toolkit = toolkit or SQLDatabaseToolkit(llm=llm, db=db) # type: ignore[arg-type] agent_type = agent_type or AgentType.ZERO_SHOT_REACT_DESCRIPTION tools = toolkit.get_tools() + list(extra_tools) + if prefix is None: + prefix = SQL_PREFIX if prompt is None: - prefix = prefix or SQL_PREFIX prefix = prefix.format(dialect=toolkit.dialect, top_k=top_k) else: if "top_k" in prompt.input_variables: @@ -170,10 +172,10 @@ def create_sql_agent( ) template = "\n\n".join( [ - react_prompt.PREFIX, + prefix, "{tools}", format_instructions, - react_prompt.SUFFIX, + suffix or SQL_SUFFIX, ] ) prompt = PromptTemplate.from_template(template)