openclaw - 💡(How to fix) Fix Feature: Native local_llm tool for Ollama/llama.cpp integration [1 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
openclaw/openclaw#49942Fetched 2026-04-08 01:01:01
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
commented ×1mentioned ×1subscribed ×1

Add a native \local_llm\ tool that allows agents to call local models (Ollama, llama.cpp, LM Studio) without shell command gymnastics.

Error Message

This is verbose, error-prone, untracked, and has no fallback handling.

Root Cause

Add a native \local_llm\ tool that allows agents to call local models (Ollama, llama.cpp, LM Studio) without shell command gymnastics.

RAW_BUFFERClick to expand / collapse

Summary

Add a native \local_llm\ tool that allows agents to call local models (Ollama, llama.cpp, LM Studio) without shell command gymnastics.

Problem

Currently, agents must use shell commands to interact with local LLMs:

\\powershell $body = @{ model = qwen2.5-coder:14b-instruct; prompt = $prompt; stream = $false } | ConvertTo-Json Invoke-RestMethod -Uri http://localhost:11434/api/generate ... \\

This is verbose, error-prone, untracked, and has no fallback handling.

Proposed Solution

\\xml <invoke name=local_llm> <parameter name=prompt>Write a C# method to validate email</parameter> <parameter name=model>code</parameter> </invoke> \\

Key Features

  • Model aliases: \code, \ ast, \general\ → actual model names
  • Auto-fallback: If local fails, escalate to cloud model
  • Metrics: Track local vs cloud usage, latency, tokens
  • Provider abstraction: Support Ollama, llama.cpp, LM Studio

Configuration

\\yaml localModels: enabled: true provider: ollama endpoint: http://localhost:11434 aliases: code: qwen2.5-coder:14b-instruct fast: deepseek-coder-v2:latest fallback: enabled: true toModel: anthropic/claude-sonnet \\

Use Case

Cost optimization for code generation tasks. Local models handle routine code gen (free), cloud models handle planning/architecture (quality).

Full Spec

See: https://github.com/Bridge-Software-Technologies/bst-clawdbot-skills/blob/main/specs/local-llm-tool.md (or I can paste the full spec here if preferred)


/cc @jmikel

extent analysis

Fix Plan

To implement the native local_llm tool, follow these steps:

  • Create a new module or class to handle local LLM interactions
  • Define a function to parse the invoke XML and extract parameters
  • Implement model alias resolution and auto-fallback to cloud models
  • Add metrics tracking for local vs cloud usage, latency, and tokens
  • Integrate with the chosen provider (Ollama, llama.cpp, LM Studio)

Example Code (C#)

using System;
using System.Net.Http;
using System.Text.Json;
using System.Xml;

public class LocalLlmTool
{
    private readonly HttpClient _httpClient;
    private readonly LocalLlmConfig _config;

    public LocalLlmTool(LocalLlmConfig config)
    {
        _config = config;
        _httpClient = new HttpClient();
    }

    public async Task<string> InvokeAsync(string prompt, string modelAlias)
    {
        // Resolve model alias
        var modelName = _config.Aliases[modelAlias];

        // Create request body
        var requestBody = new
        {
            model = modelName,
            prompt = prompt,
            stream = false
        };

        // Send request to local model
        var response = await _httpClient.PostAsync(_config.Endpoint, new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json"));

        // Check for fallback
        if (!response.IsSuccessStatusCode && _config.Fallback.Enabled)
        {
            // Escalate to cloud model
            var cloudResponse = await EscalateToCloudModelAsync(prompt, _config.Fallback.ToModel);
            return cloudResponse;
        }

        // Return response
        return await response.Content.ReadAsStringAsync();
    }

    private async Task<string> EscalateToCloudModelAsync(string prompt, string cloudModelName)
    {
        // Implement cloud model escalation logic here
        throw new NotImplementedException();
    }
}

public class LocalLlmConfig
{
    public string Endpoint { get; set; }
    public Dictionary<string, string> Aliases { get; set; }
    public FallbackConfig Fallback { get; set; }
}

public class FallbackConfig
{
    public bool Enabled { get; set; }
    public string ToModel { get; set; }
}

Verification

To verify the fix, test the LocalLlmTool class with different model aliases and prompts. Check that the tool correctly resolves model aliases, sends requests to the local model, and escalates to the cloud model when necessary. Monitor metrics to ensure accurate tracking of local vs cloud usage, latency, and tokens.

Extra Tips

  • Ensure proper error handling and logging in the LocalLlmTool class.
  • Consider implementing a cache to store frequently used model responses.
  • Review the LocalLlmConfig class to ensure it meets the requirements of the local_llm tool.

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