ollama - ✅(Solved) Fix x/tools: add a no-op think tool for structured reasoning before action [1 pull requests, 1 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#15134Fetched 2026-04-08 01:48:50
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1mentioned ×1subscribed ×1

Fix Action

Fixed

PR fix notes

PR #15136: feat: add no‑op think tool for structured reasoning

Description (problem / solution / changelog)

This PR adds a minimal think tool to the x/tools package. It provides a simple no‑op reasoning step that models can call before performing external actions.

Why: Encourages a plan‑first pattern (think → choose tool → act) and reduces malformed tool calls.

What

  • x/tools/think.go – implementation with JSON input { "thought": "…" }.
  • Returns { "status": "ok" } after validation.
  • Stub Register function ready for integration.

Next steps: Wire the tool into the global registry, add tests, and expose it in the UI.

@jmorganca, happy to iterate on this if it aligns with the roadmap.

Closes #15134

Changed files

  • docs/webgpu-stub.md (added, +24/-0)
  • x/tools/think.go (added, +45/-0)
RAW_BUFFERClick to expand / collapse

I'd like to propose a small addition to the agent/tooling layer: a built-in think tool in x/tools that gives models a structured no-op reasoning step before taking an external action.

Why

The current tool loop supports acting (bash, web/search-style tools, etc.), but there doesn't appear to be a built-in reasoning primitive for cases where a model should explicitly plan before choosing its next tool call.

For local/smaller models, this can help reduce bad tool selection and malformed arguments by encouraging a plan-first pattern:

  1. think
  2. choose tool
  3. act

Proposed behavior

  • Tool name: think
  • Input schema: { "thought": string }
  • Execution: validates input and returns "ok"
  • Side effects: none
  • Optional opt-out via env var, e.g. OLLAMA_AGENT_DISABLE_THINK=1

Scope

This would be intentionally small:

  • x/tools/think.go
  • tests
  • registry wiring
  • human-readable display name in approval UI

If this direction fits the roadmap, I can open a focused PR with tests. @jmorganca

extent analysis

Fix Plan

To implement the proposed think tool, follow these steps:

  • Create a new file think.go in the x/tools directory with the following content:
package tools

import (
	"encoding/json"
	"fmt"
)

type ThinkInput struct {
	Thought string `json:"thought"`
}

func Think(input []byte) (string, error) {
	var thinkInput ThinkInput
	err := json.Unmarshal(input, &thinkInput)
	if err != nil {
		return "", err
	}
	if thinkInput.Thought == "" {
		return "", fmt.Errorf("thought is required")
	}
	return "ok", nil
}
  • Add tests for the Think function in a new file think_test.go:
package tools

import (
	"encoding/json"
	"testing"
)

func TestThink(t *testing.T) {
	input := `{"thought": "example thought"}`
	output, err := Think([]byte(input))
	if err != nil {
		t.Errorf("Think returned error: %v", err)
	}
	if output != "ok" {
		t.Errorf("Think returned unexpected output: %s", output)
	}
}
  • Wire the think tool to the registry by adding an entry to the tools.go file:
func init() {
	registry.Register("think", Think)
}
  • Add an optional opt-out via an environment variable OLLAMA_AGENT_DISABLE_THINK:
func Think(input []byte) (string, error) {
	if os.Getenv("OLLAMA_AGENT_DISABLE_THINK") == "1" {
		return "", nil
	}
	// ... rest of the function remains the same
}

Verification

To verify that the fix worked, run the tests and check that the think tool is registered and functioning correctly. You can also test the opt-out feature by setting the OLLAMA_AGENT_DISABLE_THINK environment variable to 1.

Extra Tips

  • Make sure to follow the existing coding standards and conventions in the x/tools directory.
  • Consider adding additional error handling and logging to the Think function as needed.

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