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

相关推荐
灵感__idea5 小时前
Hello 算法:“走一步看一步”的智慧
前端·javascript·算法
清水白石0086 小时前
Python 编程实战全景:从基础语法到插件架构、异步性能与工程最佳实践
开发语言·python·架构
Mh6 小时前
我决定写一个 3D 地球仪来记录下我要去的地方
前端·javascript·动效
yaoxin5211237 小时前
390. Java IO API - WatchDir 示例
java·前端·python
武帝为此7 小时前
【数据清洗缺失值处理】
python·算法·数学建模
zhangchaoxies8 小时前
如何在 Go 中安全复制接口指针所指向的值
jvm·数据库·python
. . . . .8 小时前
ref、useRef 和 forwardRef
前端·javascript·react.js
曲幽8 小时前
FastAPI + Pydantic 模型终极实战手册:从能跑就行到固若金汤,这些技巧你一定用得上
python·fastapi·web·model·field·pydantic·validator·basemodel
柚子8169 小时前
break跳出语句块的神奇技巧
前端·javascript
计算机软件程序设计9 小时前
Python Flask工程目录解读
python·flask·工程目录解读