--- title: "Ollama agent" description: "Connect an Ollama backend to Hivenet Router, select the model an agent represents, and bound its load for local or edge inference." sidebarTitle: "Ollama" --- Connect an Ollama server to Hivenet Router by running an agent beside the backend. The agent checks Ollama through its `/api/tags` endpoint, registers one available model with the router, and forwards chat-completion requests to Ollama’s OpenAI-compatible API. One Hivenet Router agent represents one model. If your Ollama server contains several models, pin each agent to a model with `--model` and run a separate agent process for each one. Ollama does not provide the engine metrics collected from vLLM, SGLang, or metrics-enabled llama.cpp servers. Hivenet Router still records routing, request, latency, health, and available hardware metrics for the agent. ## Before you start You need: - a running Hivenet Router router - Ollama on the agent host - at least one model pulled in Ollama - network access between the agent and router - the Hivenet Router agent binary or Docker image - the same JWT secret used by the router The examples use: ```text Router IP: 192.168.1.100 Router gRPC port: 50051 Router libp2p port: 9000 Agent IP: 192.168.1.101 Ollama port: 11434 Model: llama3.1:8b ``` Replace these values with addresses and model names from your deployment. ## Start Ollama Install Ollama: ```bash curl -fsSL https://ollama.com/install.sh | sh ``` Start the server: ```bash export OLLAMA_HOST=127.0.0.1:11434 export OLLAMA_KEEP_ALIVE=-1 nohup ollama serve > ~/ollama.log 2>&1 & ``` `OLLAMA_KEEP_ALIVE=-1` keeps loaded models in memory instead of unloading them after an idle period. To store models in another directory, set `OLLAMA_MODELS` before starting the server: ```bash export OLLAMA_MODELS=/path/to/models ``` The agent runs on the same host, so Ollama does not need to listen on a public interface. Bind it to `0.0.0.0` only when another machine must connect directly and your network controls restrict access appropriately. Start Ollama with persistent model storage: ```bash docker run -d \ --name ollama \ --restart unless-stopped \ --network host \ --gpus all \ -e OLLAMA_KEEP_ALIVE=-1 \ -v ollama:/root/.ollama \ ollama/ollama ``` For a CPU-only host, omit: ```text --gpus all ``` Follow the logs: ```bash docker logs -f ollama ``` ## Pull a model ```bash ollama pull llama3.1:8b ``` List the available models: ```bash ollama list ``` ```bash docker exec ollama \ ollama pull llama3.1:8b ``` List the available models: ```bash docker exec ollama \ ollama list ``` Check that the Ollama server is ready: ```bash curl http://localhost:11434/api/tags \ | jq . ``` The response should contain the model you pulled. ## Prepare the Hivenet Router agent Pull the prebuilt agent image from the GitHub Container Registry: ```bash docker pull ghcr.io/hivenetoss/hivenet-agent:latest ``` Use `:nightly` if you want the moving pre-release tag built from the latest commit on `main`. Immutable `:nightly-` tags are also published. To build a custom image from source instead, clone the Hivenet Router repository and run: ```bash docker build \ -f Dockerfile.agent \ -t hivenet-router/agent:latest \ . ``` Create a directory for the shared secret and persistent agent identity: ```bash sudo mkdir -p /opt/hivenet-router sudo chown "$USER":"$USER" /opt/hivenet-router ``` Place the router’s JWT secret at: ```text /opt/hivenet-router/jwt.secret ``` Protect it: ```bash chmod 600 /opt/hivenet-router/jwt.secret ``` Build the agent from the Hivenet Router repository: ```bash go build -o bin/hivenet-agent ./cmd/agent/ ``` Place the router’s JWT secret somewhere the agent can read, for example: ```text /opt/hivenet-router/jwt.secret ``` Create a writable directory for the persistent agent identity: ```bash sudo mkdir -p /var/lib/hivenet-router/agent sudo chown "$USER":"$USER" /var/lib/hivenet-router/agent ``` ## Start the agent The examples pin the agent to `llama3.1:8b`. This avoids ambiguity when more than one model is available in Ollama. ```bash docker run -d \ --name hivenet-agent \ --restart unless-stopped \ --network host \ --gpus all \ -v /opt/hivenet-router/jwt.secret:/jwt.secret:ro \ -v /opt/hivenet-router:/data \ ghcr.io/hivenetoss/hivenet-agent:latest \ --engine ollama \ --model llama3.1:8b \ --backend-url http://localhost:11434 \ --router-grpc 192.168.1.100:50051 \ --jwt-secret-file /jwt.secret \ --region EU-France \ --identity-path /data/agent-identity.key ``` The agent container receives GPU access so it can collect NVIDIA hardware metrics. For a CPU-only host, omit: ```text --gpus all ``` The `/data` mount preserves the agent’s peer identity across container replacement and restarts. ```bash ./bin/hivenet-agent \ --engine ollama \ --model llama3.1:8b \ --backend-url http://localhost:11434 \ --router-grpc 192.168.1.100:50051 \ --jwt-secret-file /opt/hivenet-router/jwt.secret \ --region EU-France \ --identity-path /var/lib/hivenet-router/agent/identity.key ``` The agent waits until Ollama responds and the selected model is available. If Ollama is still starting or loading its model list, the agent continues polling instead of exiting permanently. For a chat model (`--capability llm`), it then sends one chat completion with `max_tokens: 1` and registers only once it succeeds: Ollama loads the model into memory on its first request, so this keeps that delay off the first client request. ## Understand the agent settings | Setting | Purpose | | --- | --- | | `--engine ollama` | Selects the Ollama integration | | `--model` | Pins the agent to one Ollama model | | `--backend-url` | Base URL of the local Ollama server | | `--router-grpc` | Router endpoint used for agent authentication. For a site with several routers, use `--routers`: every router's address, or one of them when the routers advertise their address ([Run several routers](/deploy/multiple-routers#connect-agents-to-every-router)) | | `--jwt-secret-file` | Shared secret used to authenticate the agent | | `--region` | Region metadata available to routing policies | | `--identity-path` | Persistent private key that keeps the peer ID stable | You can provide more routing metadata: ```bash --organization edge-team \ --machine office-gpu-1 \ --tags local,ollama,production ``` Policies can match these values when selecting agents. ## Model discovery and naming If you omit `--model`, the agent requests: ```text GET /api/tags ``` It registers the first model returned by Ollama. Automatic discovery is convenient when the Ollama server contains one model. Pin the model explicitly when more than one is available. ### The `:latest` suffix Ollama adds `:latest` when a model has no explicit tag. Hivenet Router removes that implicit suffix during discovery. | Ollama model name | Registered with Hivenet Router | | --- | --- | | `llama3.1:latest` | `llama3.1` | | `llama3.1:8b` | `llama3.1:8b` | | `mistral:7b` | `mistral:7b` | Explicit tags remain unchanged. When using `--model`, provide the model name expected by Ollama: ```bash --model llama3.1:8b ``` The model name clients send to Hivenet Router must match the model registered by the agent. ## Run several Ollama models Run one agent for each model you want Hivenet Router to expose. For the first model: ```bash ./bin/hivenet-agent \ --engine ollama \ --model llama3.1:8b \ --backend-url http://localhost:11434 \ --identity-path /var/lib/hivenet-router/agent/llama-8b.key \ ... ``` For another model: ```bash ./bin/hivenet-agent \ --engine ollama \ --model mistral:7b \ --backend-url http://localhost:11434 \ --identity-path /var/lib/hivenet-router/agent/mistral-7b.key \ ... ``` Each agent on the same host needs a separate `--identity-path` so every process keeps a distinct peer identity. The agents can share the same Ollama backend URL. ## Use an Ollama server behind an authenticating proxy Ollama has no API key of its own. If you place it behind a reverse proxy that requires `Authorization: Bearer `, give the agent that key: ```bash Key file --backend-api-key-file /opt/hivenet-router/ollama.key ``` ```bash Environment variable export HIVENET_ROUTER_BACKEND_API_KEY="" ``` The agent then sends `Authorization: Bearer ` on every request to the backend: readiness checks, model discovery through `/api/tags`, and inference. It is the only `Authorization` header the backend receives. The client's router credentials are never forwarded to the backend, with or without this key. See [Backend API key](/reference/configuration-reference#backend-api-key). ## How load is bounded Ollama does not report a KV-cache size, so the router sets no automatic token budget for this agent. Instead, the router allows `HIVENET_ROUTER_DEFAULT_MAX_INFLIGHT_PER_REPLICA` (default `8`) requests in flight per healthy replica of the model. To choose your own bound, set `admit_budget_tokens` or `max_inflight` in the model's policy. See [Admission control](/routing/admission-control#b2-pool-occupancy). With `HIVENET_ROUTER_DEFAULT_MAX_INFLIGHT_PER_REPLICA=0` and no policy bound, Ollama's own queue protects it. Ollama's own parallelism settings still apply. `--capacity` is deprecated and ignored by routers. The agent still sends it so older routers accept the registration. ## Verify the connection On the router, check agent health: ```bash curl http://192.168.1.100:8080/admin/health \ | jq . ``` List the models exposed to clients: ```bash curl http://192.168.1.100:8080/v1/models \ | jq '.data[].id' ``` Inspect the Ollama agent: ```bash curl http://192.168.1.100:8080/admin/routing-table \ | jq '.agents[] | select(.metadata.engine == "ollama")' ``` Send a chat-completion request: ```bash curl -X POST http://192.168.1.100:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "llama3.1:8b", "messages": [ { "role": "user", "content": "Explain what an inference router does in one sentence." } ] }' ``` Applications call Hivenet Router’s OpenAI-compatible endpoint. The agent forwards the request to the Ollama backend. ## Available observability The Ollama integration does not scrape an engine-specific Prometheus endpoint. Hivenet Router can still expose: - agent health - routed request counts - failed request counts - active request state - smoothed round-trip time - success and failure history - CPU and memory metrics - NVIDIA GPU utilization, memory, temperature, and power when NVML is available View metrics through the router: ```bash curl http://192.168.1.100:2112/metrics \ | grep hivenet-router ``` View current agent state: ```bash curl http://192.168.1.100:8080/admin/routing-table \ | jq '.agents[] | select(.metadata.engine == "ollama")' ``` Engine-specific values such as KV cache utilization, waiting requests, time to first token, and inter-token latency are not available from the Ollama integration. ## Troubleshooting List the pulled models: ```bash ollama list ``` ```bash docker exec ollama \ ollama list ``` Pull the missing model: ```bash ollama pull llama3.1:8b ``` Check the endpoint used by the agent: ```bash curl http://localhost:11434/api/tags \ | jq . ``` When `--model` is omitted, the agent registers the first model returned by `/api/tags`. Restart the agent with an explicit model: ```bash --model llama3.1:8b ``` This is expected. Hivenet Router converts: ```text llama3.1:latest ``` to: ```text llama3.1 ``` Explicit tags such as `:8b` or `:7b` are preserved. Check the server: ```bash curl http://localhost:11434/api/tags ``` For a Linux process, inspect its log: ```bash tail -f ~/ollama.log ``` For Docker: ```bash docker logs ollama ``` Confirm that the agent’s `--backend-url` matches the address where Ollama is listening. Ollama may need to load the model into memory before serving the first request. Check loaded models: ```bash ollama ps ``` ```bash docker exec ollama \ ollama ps ``` Using: ```bash OLLAMA_KEEP_ALIVE=-1 ``` keeps the model loaded after it has been used. Check the agent logs: ```bash docker logs hivenet-agent ``` ```bash sudo journalctl \ -u hivenet-agent \ -n 100 \ --no-pager ``` Test connectivity from the agent to the router: ```bash nc -zv 192.168.1.100 50051 nc -zv 192.168.1.100 9000 ``` Check that: - the router and agent use the same JWT secret - the router’s libp2p interface is reachable - the router advertises a libp2p address the agent can reach - Ollama contains the selected model Make sure `--identity-path` points to persistent storage. For Docker: ```bash docker inspect hivenet-agent \ | jq '.[0].Mounts' ``` For bare metal: ```bash ls -l /var/lib/hivenet-router/agent/identity.key ``` Check that NVIDIA tools work on the host: ```bash nvidia-smi ``` For Docker, confirm the agent received GPU access: ```bash docker inspect hivenet-agent \ | jq '.[0].HostConfig.DeviceRequests' ``` The agent continues to operate without NVML. It reports CPU and memory metrics but omits GPU measurements. The agent’s backend HTTP timeout defaults to two minutes. Increase it for long-running requests: ```bash --http-timeout 10m ``` Also check whether the policy's `max_inflight` or `admit_budget_tokens` lets too much work reach the model and hardware. ## Next steps Connect an SGLang backend and collect engine metrics. Learn how metadata, load, and policies affect agent selection. Understand the CPU, memory, and GPU signals reported by agents.