@andriimartynov/pi-ollama-model-switcher

Monitors and manages Ollama model instances within the pi coding agent harness.

Packages

Package details

extension

Install @andriimartynov/pi-ollama-model-switcher from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@andriimartynov/pi-ollama-model-switcher
Package
@andriimartynov/pi-ollama-model-switcher
Version
0.1.0
Published
May 17, 2026
Downloads
245/mo · 11/wk
Author
andriimartynov
License
MIT
Types
extension
Size
6.8 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./src/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

Ollama Model Switcher Extension

Monitor and auto-manage Ollama model instances within the pi coding agent harness.

Description

This extension monitors changes in the selected language model. Its primary purpose is to automatically manage and stop a previously running Ollama model instance when a new model is selected, ensuring that system resources are released efficiently.

The extension communicates directly with the Ollama REST API using HTTP requests instead of shell commands, making it safer and more portable.

Prerequisites

  • pi coding agent harness must be installed.
  • Ollama must be installed and running on your system.
  • Ollama API must be accessible (default: http://localhost:11434).

Installation

From Npm

pi install npm:@andriimartynov/pi-ollama-model-switcher

From GitHub

pi install git:github.com/andriimartynov/pi-ollama-model-switcher

FROM LOCAL PATH (DEVELOPMENT)

pi install /path/to/pi-ollama-model-switcher

Configuration

OLLAMA_HOST

By default, the extension connects to Ollama at http://localhost:11434. To use a different host or port, set the OLLAMA_HOST environment variable:

export OLLAMA_HOST="http://192.168.1.100:11434"

This is the same environment variable used by the Ollama CLI.

Features

  • Model Change Detection: Listens for the model_select event.
  • Ollama Management: If the selected model changes from a previous Ollama model, it safely stops the old instance via the Ollama REST API.
  • Safe Operation: No shell commands are executed — only HTTP requests to the Ollama API.
  • Cancellation Support: Integrates with pi harness cancellation signals.

How it Works

  1. Trigger: A user changes the selected model in the harness.
  2. Check: The extension verifies if the previously active model was an Ollama model.
  3. Action: If so, it sends an HTTP POST request to ${OLLAMA_HOST}/api/generate with { model: "<previous_model_id>", keep_alive: 0 }, which forces Ollama to unload the model from memory immediately.

This ensures that resources tied to the old instance are released before new operations continue.

Limitations

  • Ollama Only: It only manages cleanup for Ollama models; switching to/from non-Ollama models does not trigger cleanup.
  • Stop Only: This extension manages stopping existing processes; it does not handle starting new models.

Changelog

See CHANGELOG.md for details.