Skip to content
1 min read · 240 words

@nhtio/adk/batteries/llm/ollama/adapter

Cross-environment executor adapter for the native Ollama /api/chat endpoint.

Remarks

Native Ollama LLM adapter targeting /api/chat (NOT the OpenAI-compat /v1 layer — the openai_chat_completions battery already covers /v1). Works against both LOCAL Ollama (http://localhost:11434, no auth) and CLOUD Ollama (https://ollama.com, Authorization: Bearer <apiKey>); the only difference is baseURL + the auth header. Native is HTTP-only — a Unix-socket deployment is reached via a custom fetch or an external bridge, not an adapter option.

Structurally a sibling of the OpenAI Chat Completions adapter, with the native-wire divergences:

  • Request body: generation params are NESTED under options; think / format / keep_alive are top-level native controls; ADK control fields are stripped before sending.
  • Streaming: NDJSON (newline-delimited JSON objects), terminated in-band by done: true — there is no SSE data: framing and no [DONE] sentinel. Whole tool_calls arrive per chunk (no delta accumulation).
  • Reasoning: the single native message.thinking field (no multi-field precedence dance).
  • Tool calls: arguments is already a JSON OBJECT (no JSON.parse); native calls carry no id, so the adapter synthesizes one (uuidv6) for correlation / checksum / spool keying. Tool-result history messages use tool_name (the originating tool), not tool_call_id.
  • Generation stats: the terminal done: true object's token counts + nanosecond durations + done_reason are surfaced via helpers.reportGenerationStats.

Classes

ClassDescription
OllamaAdapterOpinionated cross-environment LLM adapter for the native Ollama /api/chat wire shape.