langchain 当使用任何Gemini模型时,AgentExecutor没有选择工具(vanna_tool)(在使用OpenAI或Mistral时工作正常),

stszievb  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(58)

检查其他资源

  • 为这个问题添加了一个非常描述性的标题。
  • 使用集成搜索在LangChain文档中进行搜索。
  • 使用GitHub搜索查找类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。

示例代码

class MyVanna(ChromaDB_VectorStore, GoogleGeminiChat):
    def **init**(self, config=None):
        ChromaDB_VectorStore.**init**(self, config=config)
        GoogleGeminiChat.**init**(self, config=config)
vn = MyVanna(config={
 "path": "../....",
 "api_key": os.getenv("GOOGLE_API_KEY"),
 "model_name": "gemini-1.5-pro",
}
 )
@tool('vanna_tool')
def vanna_tool(qa: str):
 "....."
 ....
 return .....
class Response(BaseModel):
 """The format for your final response by the agent should be in a Json format agent_response and sql_query"""

agent_response: str = Field(description="""..... """)
sql_query: str = Field("", description="The full sql query returned by the vanna_tool agent and '' if no response.")


tools = [vanna_tool]
llm = ChatVertexAI(model="gemini-pro")
...
parser = PydanticOutputParser(pydantic_object=Response)
prompt.partial_variables = {"format_instructions": parser.get_format_instructions()}
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
 agent=agent,
 tools=tools,
 verbose=True,
 return_intermediate_steps=True
)

#### 错误信息和堆栈跟踪(如果适用)

如果是openai的情况:

Invoking: vanna_tool with {'qa': "Display the '...' column values for the week between 2 to 8 in 2024."}
...


in case of Gemini:

进入新的AgentExecutor链...

{"agent_response": "Here are the ... values for weeks 2 to 8 in 2024:\n\n```\n                   opec  \nweek  \n2       77680000     \n3       77900000     \n4       78110000     \n5       78310000     \n6       78500000     \n7       78680000     \n```\n\nI hope this is helpful!", "sql_query": "SELECT ...FROM ...WHERE week BETWEEN 2 AND 8 AND YEAR_ = 2024;"}
``` **(random output without invoking 'vanna_tool'**

### Description

asking question that should invoke vanna_tool
when using openai or mistral, it works.
when using any gemini model, it will create random response without entering 'vanna_tool' ..


### System Info

langchain==0.2.5
langchain-community==0.2.5
langchain-core==0.2.9
langchain-experimental==0.0.61
langchain-openai==0.1.9

langchain-google-genai==1.0.6
langchain-google-vertexai==1.0.5
google-generativeai==0.5.4
ecr0jaav

ecr0jaav1#

你正在使用的Python版本是什么?

axkjgtzd

axkjgtzd2#

你正在使用的Python版本是什么?
Python 3.12.2,Windows

相关问题