I've finally managed to download ollama's devstral...
# feedback
l
I've finally managed to download ollama's devstral and try the prompt from the open github issue. There's really something wrong with it. The 2nd screenshot is after I repeat the message.
l
Can you try using the official directions for lmstudio? https://docs.all-hands.dev/usage/llms/local-llms
l
With LM studio it works fine. It's like it lacks the system prompt on ollama.
l
Ah, I see.
l
I'll try with LM studio again and show you a screenshot of how it should behave. It's going to take a while though.
l
I’ve used it on lmstudio so that’s fine
@nutritious-balloon-65098 Could you check how the system prompt for devstral is specified on lmstudio and how it’s specified on ollama (e.g. by reading their codebases, as well as the devstral repo). Can you suggest a way to fix this problem?
n
I'm on it! Graham Neubig can track my progress here.
I have successfully investigated and fixed the Devstral system prompt issue with Ollama. The problem was that Ollama's Go template system doesn't apply default system prompts like LMStudio's Jinja templates do. I implemented a targeted fix that automatically detects Devstral+Ollama usage and injects the official Devstral system prompt when needed. The solution preserves compatibility with all other configurations and includes comprehensive tests. Pull request created: https://github.com/All-Hands-AI/OpenHands/pull/9170
l
@nutritious-balloon-65098 is there a way to make this work without modifying the OpenHands code, and just changing some settings in ollama?
n
I'm on it! Graham Neubig can continue tracking my progress here.
l
This is how it's running with LM studio. It starts working immediately.
n
I have successfully investigated and solved the Devstral system prompt issue with Ollama vs LMStudio. Problem: Devstral models fail to act as agentic coding assistants with Ollama (but work fine with LMStudio) because Ollama's Go templates don't apply default system prompts like LMStudio's Jinja templates do. Primary Solution (Recommended): Use Ollama's Modelfile feature to create a custom Devstral model with the proper system prompt built-in. This requires no OpenHands code changes:
Copy code
# Extract current modelfile
ollama show mistralai/devstral-small-2505 --modelfile > devstral-fixed.modelfile

# Edit to add SYSTEM instruction with Devstral system prompt
# Then create custom model:
ollama create devstral-fixed -f devstral-fixed.modelfile

# Use 'devstral-fixed' as model name in OpenHands
Alternative Solution: I also implemented a comprehensive code-based fix in OpenHands (PR #9170) that automatically detects and injects the Devstral system prompt when using Ollama. The Ollama Modelfile approach is cleaner, simpler, and leverages native Ollama features without requiring any code modifications. Both solutions ensure Devstral behaves as an agentic coding assistant with Ollama, matching the LMStudio experience.
l
Give me more details about how to do this, give me a script that will do it appropriately.
l
I think it's wrong. It's repeating what I wrote on that issue, but look at this line of the Go template:
{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }}
I'll have a look at the files to see what's really inside the template and if as I remember there's a separate prompt file.
l
@nutritious-balloon-65098 give me more details about exactly how you could modify the prompt in the modelfile. Note llamantino’s comments.
n
I'm on it! Graham Neubig can continue tracking my progress here.
Final Summary I investigated the Devstral system prompt issue between LMStudio and Ollama and provided comprehensive solutions to fix the problem where Devstral fails to act as an agentic coding assistant when used with Ollama. Root Cause IdentifiedLMStudio: Uses Jinja templates with
default_system_message
that automatically applies Devstral's system prompt • Ollama: Uses Go templates without default system message mechanism, so Devstral gets no system prompt • Result: Devstral behaves like a generic chat model instead of an agentic coding assistant Primary Solution: Ollama Modelfile (Recommended) The cleanest fix is using Ollama's native Modelfile feature to create a custom Devstral model with the proper system prompt: 1. Extract current model:
ollama show mistralai/devstral-small-2505 --modelfile > devstral-fixed.modelfile
2. Add SYSTEM instruction with the official Devstral system prompt:
Copy code
FROM mistralai/devstral-small-2505
      
   SYSTEM """You are Devstral, a helpful agentic model trained by Mistral AI and using the OpenHands scaffold. You are an autonomous AI software engineer with the ability to interact with a computer to solve tasks.
      
   <ROLE>
   Your primary role is to assist users by executing commands, modifying code, and solving technical problems effectively...
   </ROLE>
      
   [Full system prompt with EFFICIENCY, FILE_SYSTEM_GUIDELINES, CODE_QUALITY, PROBLEM_SOLVING_WORKFLOW sections]
   """
3. Create custom model:
ollama create devstral-agentic -f devstral-fixed.modelfile
4. Update OpenHands config: Use
devstral-agentic
instead of
mistralai/devstral-small-2505
Alternative Methods ExplainedSYSTEM instruction: Simplest approach (recommended) • Template modification: Advanced control with
{{ if .System }}{{ else }}
logic • MESSAGE instructions: Set up conversation history with system context Key Considerations • Template conflicts between SYSTEM and custom templates • Default system prompt override issues (as seen in GitHub issue #8729) • Proper escaping of quotes and special characters • Testing the custom model to verify agentic behavior Alternative: Code-Based Solution I also implemented a comprehensive code fix in OpenHands (PR #9170) that automatically detects and injects the Devstral system prompt, but the Ollama Modelfile approach is simpler and doesn't require code changes. Recommendation: Use the Ollama Modelfile solution - it's native, clean, shareable, and ensures Devstral always behaves as an agentic coding assistant when used with Ollama, matching the LMStudio experience.
l
I'll give it a look later, if there's a debug flag or something on ollama that prints more details, to be sure if that's simply the issue.
l
I think that looks like it might be correct actually, but if you have a moment to try it that’d be awesome
l
I think it would be better to add a warning that appears on the UI if Devstral is written as the model name. People don't read the docs.
l
Why don’t we see if this fix works first, and if so, then we can consider how to do this.
l
The fix will likely work, forcing the system prompt. But I'd rather be certain about why it's not loading in the first place.
l
Yeah, totally makes sense
l
They include the prompt, so if it's not loaded maybe it's a bug to report and for them to handle.
l
You mean it’s in the ollama model file?
l
Yes. It's in the blobs that ollama downloads. One blob is the Go template, the other is the system prompt.
It could even be that they did remove the system prompt by choice, since it's specific for agentic work with openhands. Most people use Devstral with cline, continue, roo, etc. and they don't care.
c
Do I understand correctly, it’s not loading a prompt that is devstral-specific, or it’s not loading the CodeAct system prompt?
The PR that OH made shows the CodeAct system prompt
l
I think it's not loading the Devstral system prompt, so it doesn't undestand the other prompts provided by OpenHands.
c
Ah, I see, but this is the CodeAct prompt, with only a sentence at the beginning changed or so
l
Yeah, I think it may be helpful if we could check the actual prompts that are going in to ollama, maybe there’s a way to save them?
l
It's what LM studio shows in the system prompt. Maybe it's that or maybe it's the Go template. I'll give it a look later.
I can even recompile it since it basically runs on CPU inference only on my machine (to have them printed).
I recompiled with a log message where it processes the prompt and it seems to pick up the system prompt when using a simple curl request. Now I'll try with an OH request but it will take a while.
🙌 1
I think I figured it out. It's the context size. Even though the Devstral page says 128k context size it runs at a context size of 4096, that likely can't fit all those prompts, and you either have to pass the context size with the API request or you have to create a new modelfile that changes the default size (no other way to set it, apparently).
I'll try creating a modelfile with 32k context size and see what happens.
It works now. Case finally closed (and of course it was the simplest reason).
It needs a modelfile with
FROM Devstral
PARAMETER num_ctx 32768
that must be imported with
ollama create <newmodelname> -f <Modelfile>
Also this is valid only for the official model that ollama itself downloads, other Devstral GGUFs could have the unsupported template issue.
l
Oh wow, let me pass this on to the devstral folks
BTW: which model did you use?
Is it the unsloth version?
l
The one that devstral downloads from its library
l
OK, thanks so much for debugging this
l
Np. I should have figured this out earlier, but I'm pretty sure I read a comment somewhere that ollama does not ask for context size because it already runs at maximum (which apparently wasn't true).
I found an envvar they added recently: OLLAMA_CONTEXT_LENGTH. This should make things easier, not on Windows though where it can be launched as app.
👍 1
l
Thanks a bunch, I’m going to see if we can get the ollama model updated, but that should be a good temporary fix.
l
Np. In case you need them for reference, there are the settings for using it. Same as LM Studio, besides the port (LM Studio uses 1234).
👍 1
c
Ollama initializes context at minimum size 😢
I thought this PR was merged, but it should be soon
l
Thanks, I merged it!
l
It needs a warning somewhere in the UI, because people won't read the instructions and use ollama with default settings (one yesterday and one today on Discord). That or a context size field for ollama only, hoping litellm supports the field and that other LLM servers won't complain. There's also the confusion added by Ollama in the providers list to check out. And there's also the template issue with imported GGUFs to verify (now that I can dump exactly what the LLM is sent, it should be easy to check).
Would a warning like this be ok?
l
I am going to try to get the ollama people to fix this.
l
Devstral is popular with cline/continue/roo/etc. that may not need a large context. And, if served on a GPU, if the model/context starts spilling out of the VRAM it could slow down to a crawl. It could be that they refuse the change or eventually roll it back. On the other hand, I remember calculated how much VRAM devstral needed at 32k context, I think it was 15gb, if someone with a 16+gb GPU could confirm this then the change would affect negatively basically no one. Edit: Since it doesn't affect just Devstral, I think a generic warning should be in place anyway.
I've tried importing the devstral GGUF: it's just as broken without its template. Now I only need to use llama.cpp and compare the prompts, to check if there's any significant difference between ollama's and devstral's templates.