[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支持吧

相关推荐
前端李二牛30 分钟前
异步任务并发控制
前端·javascript
阿里云大数据AI技术34 分钟前
【跨国数仓迁移最佳实践6】MaxCompute SQL语法及函数功能增强,10万条SQL转写顺利迁移
python·sql
你也向往长安城吗1 小时前
推荐一个三维导航库:three-pathfinding-3d
javascript·算法
杜子不疼.1 小时前
《Python学习之文件操作:从入门到精通》
数据库·python·学习
微小的xx1 小时前
java + html 图片点击文字验证码
java·python·html
karrigan1 小时前
async/await 的优雅外衣下:Generator 的核心原理与 JavaScript 执行引擎的精细管理
javascript
金色旭光1 小时前
uv 现代化的虚拟环境管理工具
python·python进阶
wycode1 小时前
Vue2实践(3)之用component做一个动态表单(二)
前端·javascript·vue.js
赞哥哥s1 小时前
Python脚本开发-统计Rte中未连接的Port
python·autosar·rte
Franklin2 小时前
Python界面设计【QT-creator基础编程 - 01】如何让不同分辨率图像自动匹配graphicsView的窗口大小
开发语言·python·qt