More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    Local Model Pitfalls

    1

    Diagnose and fix silent context truncation, empty thinking-model outputs, and Gemini API parameter failures.

    Free

    Security scanned
    Local Model Pitfalls

    Local Model Pitfalls

    Example session with this skill installed

    My agent runs on Ollama with gemma4:12b. When the prompt gets long (around 40,000 characters) it starts ignoring its system prompt and answers like it never saw the instructions. No errors anywhere. Use the local-model-pitfalls skill to tell me what's going on and what num_ctx I should send for a 40K-character prompt with 2048 output tokens.

    • Read your context and instructions
    • Compiled the local model pitfalls

    Send num_ctx: 16384 for that call. Your model is not ignoring the system prompt. Ollama is deleting it before the model ever sees it.

    What is happening. Ollama's default context window is 4096 tokens. When a prompt exceeds it, Ollama does not return an error. It silently drops the oldest tokens from the front until the prompt fits. Your system prompt is at the front, so it is the first thing to go. A 40K-character prompt is roughly 10,000 to 13,000 tokens, so at the default window gemma4:12b sees only the last few thousand tokens of your conversation and answers fluently from that tail. Nothing in the harness or the model is broken.

    How to confirm it on your machine. Check prompt_eval_count in the Ollama response. If it is around 2,000 for a 40K-character prompt, truncation is happening. The skill also ships a probe that hides a secret word at the start of a padded prompt and asks for it at the end, with and without a sized window:

    python scripts/ollama_ctx.py probe --model gemma4:12b --chars 40000
    

    The sizing math from the skill's num_ctx_for function:

    StepValue
    40,000 chars / 3 chars per token13,333
    + 2,048 output tokens15,381
    + 512 margin15,893
    rounded up to a 1,024 multiple16,384

    That is under the 64K ceiling and well inside gemma4's trained window, so no cap applies. The script's size command returned the same number.

    Two things to do beyond this one call:

    Recompute per request. In a tool loop the history grows every round, so a fixed 16384 will eventually truncate again. Call num_ctx_for(len(prompt), max_output, model_context_length(...)) before each request.

    Do not just set it to the maximum. KV-cache memory grows linearly with num_ctx. Oversizing on a 12B model wastes VRAM and can push layers to CPU.

    One related trap worth checking. gemma4 is a thinking-capable model. If any of your short structured calls, like a compressor or classifier, ever return an empty string, that is the skill's second failure mode: the model spent its whole output budget inside the think block. Set "think": false for those calls and treat any result under about 20 characters as a failure.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Local and hosted models often fail silently when integrated into agent harnesses. A correct implementation can appear broken due to hidden context truncation, budget-exhausted thinking blocks, or deprecated API parameters. This skill provides the diagnostic logic and code to identify and fix these three specific points of failure.

    What it does

    • Dynamic Context Sizing calculates the required num_ctx for Ollama based on prompt character count and model limits to prevent front-end truncation.
    • Thinking Model Guards identify when models exhaust their output budget on reasoning and return empty strings, preventing data loss in structured tasks.
    • Gemini Parameter Enforcement manages the transition between legacy sampling parameters and new thinking levels to avoid 400 errors.
    • Automated Probing includes a script to verify context truncation on your local hardware by hiding and retrieving tokens in padded prompts.
    • JSON Sanitization provides a parser that strips leaked reasoning blocks before processing structured data.

    How it works

    1. Use ollama_ctx.py to calculate the correct context window before every call to ensure the system prompt isn't dropped.
    2. Run the probe command to confirm if your current local setup is silently truncating data.
    3. Apply the thinking-guard logic to structured tasks like classification or compression to handle empty string failures.
    4. Reference the version-specific policy table for Gemini to gate temperature and thinking parameters correctly.

    Frameworks & tools

    Python 3.9+ standard library. Works with local Ollama instances via the REST API and Gemini 3.x hosted models.

    Why this beats prompting it yourself

    Prompting cannot fix engine-level truncation or API-level parameter rejections. This skill provides the infrastructure-level logic required to ensure the model actually receives the prompt you sent.

    Use cases

    • Preventing "memory loss" in long-context local agent loops.
    • Fixing empty JSON responses from models like DeepSeek-R1 or Qwen.
    • Migrating Gemini integrations to 3.x models without 400 errors on sampling or thinking parameters.
    • Debugging why a local 12B model ignores its system instructions.

    Known limitations

    The probe script and context sizer require a reachable local Ollama API. Context sizing uses a character-to-token heuristic which may vary slightly by tokenizer.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free forever

    No account required to browse

    Trust & safety

    Security scanned

    Verified clean today

    • Free to download with an account

    Requires

    Ollama
    Python 3.9+
    Ollama (optional, for the probe and show commands)
    Python

    Listedtoday

    What's inside

    Frequently Asked Questions