ollama-code

Ollama Code Architecture Overview

This document provides a high-level overview of Ollama Code’s architecture.

Core Components

Ollama Code is primarily composed of two main packages, along with a suite of tools that can be used by the system in the course of handling command-line input:

1. CLI Package (packages/cli)

Purpose: This contains the user-facing portion of Ollama Code, such as handling the initial user input, presenting the final output, and managing the overall user experience.

Key Functions:

2. Core Package (packages/core)

Purpose: This acts as the backend for Ollama Code. It receives requests sent from packages/cli, orchestrates interactions with the configured model API, and manages the execution of available tools.

Key Functions:

3. Tools (packages/core/src/tools/)

Purpose: These are individual modules that extend the capabilities of the Qwen model, allowing it to interact with the local environment (e.g., file system, shell commands, web fetching).

Interaction: packages/core invokes these tools based on requests from the Qwen model.

Common Tools Include:

Interaction Flow

A typical interaction with Ollama Code follows this flow:

  1. User Input: The user types a prompt or command into the terminal, which is managed by packages/cli.
  2. Request to Core: packages/cli sends the user’s input to packages/core.
  3. Request Processing: The core package:
    • Constructs an appropriate prompt for the configured model API, possibly including conversation history and available tool definitions.
    • Sends the prompt to the model API.
  4. Model API Response: The model API processes the prompt and returns a response. This response might be a direct answer or a request to use one of the available tools.
  5. Tool Execution (if applicable):
    • When the model API requests a tool, the core package prepares to execute it.
    • If the requested tool can modify the file system or execute shell commands, the user is first given details of the tool and its arguments, and the user must approve the execution.
    • Read-only operations, such as reading files, might not require explicit user confirmation to proceed.
    • Once confirmed, or if confirmation is not required, the core package executes the relevant action within the relevant tool, and the result is sent back to the model API by the core package.
    • The model API processes the tool result and generates a final response.
  6. Response to CLI: The core package sends the final response back to the CLI package.
  7. Display to User: The CLI package formats and displays the response to the user in the terminal.

Configuration Options

Ollama Code offers multiple ways to configure its behavior:

Configuration Layers (in order of precedence)

  1. Command-line arguments
  2. Environment variables
  3. Project settings file (.ollama-code/settings.json)
  4. User settings file (~/.ollama-code/settings.json)
  5. System settings files
  6. Default values

Key Configuration Categories

Key Design Principles