Skip to content

Agent prompt field is not sent as system message to Ollama-compatible local models #24239

Closed as not planned

Description

@corneliustd

Description

Bug Description

When configuring a custom agent with a prompt field in opencode.json, the prompt is not injected as the system message when the agent uses a local model via an OpenAI-compatible provider (e.g. Ollama). The model receives no system prompt at all, so any instructions in the agent prompt are silently ignored.

Plugins

No response

OpenCode version

1.14.24

Steps to reproduce

Steps to Reproduce

  1. Configure a custom agent in opencode.json with a prompt field:
"gentleman-local": {
  "mode": "primary",
  "model": "ollama/qwen2.5:7b",
  "prompt": "Your working directory is /Users/me/project. Always use absolute paths when calling file tools."
}
2. Start a session with this agent
3. Ask it to read a file: read pom.xml
4. The model calls read with a placeholder path like /path/to/pom.xml instead of /Users/me/project/pom.xml
Expected Behavior
The prompt field should be sent as the system message in the chat completion request, exactly as it works for cloud models (e.g. Claude, GPT).
Actual Behavior
The model receives no system prompt. Verified by:
- Checking opencode logs: the prompt content never appears
- Testing the same model directly via curl with the prompt as system message → model behaves correctly
- Testing with inline prompt string in opencode.json (not {file:...}) → same result, prompt is ignored


### Screenshot and/or share link

Evidence
Direct curl with system prompt works correctly:
curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen2.5:7b",
    "messages": [
      {"role": "system", "content": "Working directory: /Users/me/project. Always prepend it to file paths."},
      {"role": "user", "content": "read pom.xml"}
    ],
    "tools": [...]
  }'
# → calls read with /Users/me/project/pom.xml ✅
Same model via opencode agent with prompt set:
# → calls read with /path/to/pom.xml ❌ (prompt was not sent)
Environment
- opencode version: 1.14.24
- OS: macOS (Apple M4, darwin)
- Provider: Ollama 0.21.1 via @ai-sdk/openai-compatible
- Model tested: qwen2.5:7b, qwen2.5-coder:7b
- Cloud agents (Claude Sonnet) work correctly with the same prompt field

### Operating System

26.3.1

### Terminal

iTerm2

Activity

  1. added
    bug
    on Apr 25, 2026
  2. added
    core
    on Apr 25, 2026
  3. tiffanychum commented on Apr 25, 2026

    @tiffanychum

    Tried to reproduce on dev (27353df).

    Wrote an HTTP-mock test alongside the existing sends temperature, tokens, and reasoning options for openai-compatible models test in packages/opencode/test/session/llm.test.ts. It captures the request body sent to an @ai-sdk/openai-compatible provider when an agent has prompt: set:

    const agent = {
      name: "ollama-agent", mode: "primary", options: {},
      permission: [{ permission: "*", pattern: "*", action: "allow" }],
      prompt: "ALWAYS_USE_ABSOLUTE_PATHS_FROM_/home/test",
    } satisfies Agent.Info
    // ... drain via LLM.stream, capture body ...
    expect(messages[0].role).toBe("system")
    expect(messages[0].content).toContain("ALWAYS_USE_ABSOLUTE_PATHS_FROM_/home/test")

    The test passes — body.messages[0] is a system message containing the agent prompt verbatim. So the prompt does reach the wire on the openai-compatible path.

    The symptom you're seeing (Claude works, qwen2.5:7b doesn't is most likely a different mechanism: when agent.prompt is set, SystemPrompt.provider() (the default tool-use guidance, e.g. session/prompt/default.txt) is replaced rather than appended in session/llm.ts:103. Strong cloud models tolerate the missing guidance; smaller local models often don't.

    Caveat: the replace behavior is load-bearing for built-in agents (title, summary, compaction, explore) which set their own focused prompt. So a scoped change would have to gate on agent.native. Happy to spin out a separate PR if append-for-non-native is the direction you want.
    EOF
    )

  4. removed
    bug
    core
    on May 3, 2026
  5. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions