ollama - 💡(How to fix) Fix ollama cloud kimi-k2.5 cannot recognize the SystemMessage !!!! [3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15054Fetched 2026-04-08 01:26:31
View on GitHub
Comments
3
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×3closed ×1labeled ×1mentioned ×1

Code Example

from datetime import datetime

from deepagents import create_deep_agent
from langchain_core.messages import SystemMessage
from langchain_openai import ChatOpenAI


def get_local_ollama(model_name: str) -> ChatOpenAI:
    # 注意:此处ChatOllama不能放到开头去,因为会触发初始化,在非本地环境中运行的时候会报错
    from langchain_ollama import ChatOllama

    return ChatOllama(
        base_url="http://localhost:11434",  # deepseek 服务地址
        model=model_name,  # 模型名称(需提前下载)
        max_retries=3,
        api_key="",
        callbacks=[],
    )


def get_ollama_kimi() -> ChatOpenAI:
    model_name = "kimi-k2.5:cloud"
    local_ollama = get_local_ollama(model_name)
    return local_ollama


def get_kimi() -> ChatOpenAI:
    # TODO: put the right kimi api key
    api_key = "sk-xxxxx"
    return ChatOpenAI(
        model="kimi-k2.5",
        api_key=api_key,
        base_url="https://api.moonshot.cn/v1",
    )


def test_model_system_prompt(m: ChatOpenAI):
    agent = create_deep_agent(model=m)
    result = agent.invoke(
        {
            "messages": [
                # HumanMessage(content="不调用任何工具,告诉我当前时间"),
                {"role": "user", "content": "不调用任何工具,告诉我当前时间"},
                SystemMessage(content=f"当前时间为{datetime.now()}"),
            ]
        }
    )
    print(result["messages"][-1].content)


for f in [
    get_kimi,
    get_ollama_kimi,
]:
    print(f"正在测试模型{f.__name__}")
    test_model_system_prompt(f())

---

python ollama-kimi-issue/mine.py                                          
正在测试模型get_kimi
当前时间是 2026-03-25 16:19:40正在测试模型get_ollama_kimi
我无法直接获取当前时间。如果您需要查看当前时间,可以:

1. **在终端中运行**`date``date "+%Y-%m-%d %H:%M:%S"`
2. **使用 Python**`python3 -c "import datetime; print(datetime.datetime.now())"`

如果您允许我调用工具,我也可以帮您获取时间。
RAW_BUFFERClick to expand / collapse

What is the issue?

The official kimi-k2.5 can recognize the SystemMessage. But ollama cloud kimi k2.5 cannot. Here is the code:

from datetime import datetime

from deepagents import create_deep_agent
from langchain_core.messages import SystemMessage
from langchain_openai import ChatOpenAI


def get_local_ollama(model_name: str) -> ChatOpenAI:
    # 注意:此处ChatOllama不能放到开头去,因为会触发初始化,在非本地环境中运行的时候会报错
    from langchain_ollama import ChatOllama

    return ChatOllama(
        base_url="http://localhost:11434",  # deepseek 服务地址
        model=model_name,  # 模型名称(需提前下载)
        max_retries=3,
        api_key="",
        callbacks=[],
    )


def get_ollama_kimi() -> ChatOpenAI:
    model_name = "kimi-k2.5:cloud"
    local_ollama = get_local_ollama(model_name)
    return local_ollama


def get_kimi() -> ChatOpenAI:
    # TODO: put the right kimi api key
    api_key = "sk-xxxxx"
    return ChatOpenAI(
        model="kimi-k2.5",
        api_key=api_key,
        base_url="https://api.moonshot.cn/v1",
    )


def test_model_system_prompt(m: ChatOpenAI):
    agent = create_deep_agent(model=m)
    result = agent.invoke(
        {
            "messages": [
                # HumanMessage(content="不调用任何工具,告诉我当前时间"),
                {"role": "user", "content": "不调用任何工具,告诉我当前时间"},
                SystemMessage(content=f"当前时间为{datetime.now()}"),
            ]
        }
    )
    print(result["messages"][-1].content)


for f in [
    get_kimi,
    get_ollama_kimi,
]:
    print(f"正在测试模型{f.__name__}")
    test_model_system_prompt(f())

Relevant log output

python ollama-kimi-issue/mine.py                                          
正在测试模型get_kimi
当前时间是 2026-03-25 16:19:40。
正在测试模型get_ollama_kimi
我无法直接获取当前时间。如果您需要查看当前时间,可以:

1. **在终端中运行**:`date``date "+%Y-%m-%d %H:%M:%S"`
2. **使用 Python**:`python3 -c "import datetime; print(datetime.datetime.now())"`

如果您允许我调用工具,我也可以帮您获取时间。

OS

No response

GPU

No response

CPU

No response

Ollama version

No response

extent analysis

Fix Plan

To fix the issue, we need to modify the get_ollama_kimi function to correctly handle the SystemMessage.

  • Update the get_ollama_kimi function to use the kimi-k2.5 model directly instead of kimi-k2.5:cloud.
  • Modify the test_model_system_prompt function to handle the SystemMessage correctly.

Code Changes

def get_ollama_kimi() -> ChatOpenAI:
    model_name = "kimi-k2.5"
    local_ollama = get_local_ollama(model_name)
    return local_ollama

def test_model_system_prompt(m: ChatOpenAI):
    agent = create_deep_agent(model=m)
    system_message = SystemMessage(content=f"当前时间为{datetime.now()}")
    result = agent.invoke(
        {
            "messages": [
                {"role": "user", "content": "不调用任何工具,告诉我当前时间"},
                system_message,
            ]
        }
    )
    print(result["messages"][-1].content)

Verification

Run the updated code and verify that the get_ollama_kimi model correctly recognizes the SystemMessage and returns the current time.

Extra Tips

  • Make sure to update the ollama version to the latest one to ensure compatibility with the kimi-k2.5 model.
  • If the issue persists, try to check the langchain_ollama library version and update it if necessary.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING