Skip to content

Expand OllamaProvider response parser (thinking, tool_calls, done_reason) #133

Description

@yacosta738

Context

The current OllamaChatResponse parser in
crates/infrastructure/providers-ollama/src/lib.rs only extracts:

  • model
  • message.role, message.content
  • done
  • prompt_eval_count, eval_count

The OpenAPI spec at https://docs.ollama.com/api/chat.md documents several
more fields that the Ollama native API returns but we currently drop:

Field Use case
done_reason Distinguish 'stop' vs 'length' vs 'load' for better finish_reason reporting in StreamChunk and CompletionResponse.
message.thinking Surfacing reasoning traces from thinking models (e.g. gpt-oss, qwen3 with think: true).
message.tool_calls Tool/function calling — required to route Ollama native function calls through Rook.
message.images Multimodal responses (when the model returns inline base64 images).
total_duration, load_duration, prompt_eval_duration, eval_duration Useful for observability.
logprobs Token-level probabilities — needed for some structured-output workflows.

These are out of scope for the Ollama Cloud bring-up but will need to land
soon for parity with OpenAI/Anthropic adapters and to support thinking models.

Acceptance criteria

  • OllamaChatResponse deserializes all fields listed in the OpenAPI ChatResponse schema.
  • StreamChunk carries thinking content separately from delta (already part of MessageContent).
  • done_reason flows into StreamChunk.finish_reason and CompletionResponse.finish_reason (mapping the Ollama-specific reasons to the existing FinishReason enum).
  • tool_calls are deserialized (storage location TBD — likely a new domain field on Message).
  • Timing fields are exposed in the audit log / observability surface.
  • Existing wiremock tests in crates/infrastructure/providers-ollama/tests/provider.rs keep passing.
  • New wiremock tests cover: done_reason: "length", thinking trace, tool calls.
  • No regression on the Ollama Cloud bring-up (Bearer auth tests still pass).

Out of scope

  • Cloud-side tool calling / thinking-specific model selection — that's a UI follow-up.
  • Streaming x-ndjson schema for /api/chat events is identical to the non-streaming ChatResponse except done_reason is not always present in the final chunk — verify the parser handles that.

Reference

  • OpenAPI spec: https://docs.ollama.com/api/chat.md
  • ChatResponse schema fields: model, created_at, message.{role,content,thinking,tool_calls,images}, done, done_reason, total_duration, load_duration, prompt_eval_count, prompt_eval_duration, eval_count, eval_duration, logprobs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreCore domain logic and modelsarea/providersProvider integrations (OpenAI, Anthropic, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions