[bug]langchain agent报错Invalid Format: Missing ‘Action Input:‘ after ‘Action:‘

在学习langchain的agent时候,采用ollama调用本地的deepseek-r1:32b来做一个agent,代码如下:

csharp 复制代码
def create_custom_agent():
    llm = ChatOllama(model="deepseek-r1:32b", temperature=0.5)

    memory = ConversationBufferWindowMemory(
        memory_key="chat_history",
        k=3,
        return_messages=True
    )

    react_template = """
    尽你所能回答以下问题:{input}
    你可以使用以下工具:{tools}
    工具名称列表:{tool_names}

    使用以下格式:
    Question: 您必须回答的输入问题
    Thought: 你应该思考如何解决这个问题
    Action: 要采取的操作,例如 "convert_image"
    Action Input:工具的输入参数
    Observation: 工具的输出结果
    Final Answer:最终答案

    开始!

    Thought:{agent_scratchpad}
    """

    react_prompt = PromptTemplate(
        input_variables=['input', 'tools', 'tool_names', 'agent_scratchpad', 'chat_history'],
        template=react_template
    )

    react_agent = create_react_agent(llm=llm, tools=tools, prompt=react_prompt)
    agent_executor = AgentExecutor(
        agent=react_agent,
        tools=tools,
        memory=memory,
        verbose=True,
        handle_parsing_errors=True,
    )
    return agent_executor

模版参考了官方的https://python.langchain.com/api_reference/_modules/langchain/agents/react/agent.html#create_react_agent ReAct风格链写的,但是在调用的时候一直报错,我寻思32b的模型也不小了,后来果断换了qwen2.5:7b 就行了,哎,deepseek的function calling实在是太差了,希望后续deepseek支持吧

相关推荐
max5006004 分钟前
基于多元线性回归、随机森林与神经网络的农作物元素含量预测及SHAP贡献量分析
人工智能·python·深度学习·神经网络·随机森林·线性回归·transformer
Pocker_Spades_A9 分钟前
Python快速入门专业版(二十九):函数返回值:多返回值、None与函数嵌套调用
服务器·开发语言·python
良木林12 分钟前
浅谈原型。
开发语言·javascript·原型模式
yunpeng.zhou12 分钟前
logging 模块升级版 loguru
python
kida_yuan1 小时前
【从零开始】14. 数据评分与筛选
python·数据分析·nlp
小李独爱秋1 小时前
特征值优化:机器学习中的数学基石
人工智能·python·线性代数·机器学习·数学建模
TwoAI1 小时前
Matplotlib:绘制你的第一张折线图与散点图
python·matplotlib
RainbowSea2 小时前
10. LangChain4j + 持久化实操详细说明
langchain·llm·ai编程
摸鱼仙人~2 小时前
一文详解 Python 密码哈希库 Passlib
开发语言·python·哈希算法
RainbowSea2 小时前
9. LangChain4j + 整合 Spring Boot
langchain·llm·ai编程