Skip to content

feat(core): harden the local provider for multimodal agent loops#212

Merged
seanbrar merged 1 commit into
mainfrom
feat/local-provider-hardening
Jun 17, 2026
Merged

feat(core): harden the local provider for multimodal agent loops#212
seanbrar merged 1 commit into
mainfrom
feat/local-provider-hardening

Conversation

@seanbrar

Copy link
Copy Markdown
Owner

Summary

Make provider="local" a first-class agent backend against self-hosted, OpenAI-compatible servers. Local now accepts multimodal input, supports single-model servers that don't take a model field, and exposes a configurable request timeout.

  • Multimodal input: inline image and audio through Chat Completions content parts (uploads=True) and inline text files; unsupported MIME types raise specific guidance instead of a blanket "text-only" error.
  • Optional model: Config.model may be omitted for single-model local servers; the model field is then left out of local payloads. Cloud providers still require model, and create_cache()/defer() raise clearly when it is missing.
  • Configurable timeout: Config.request_timeout_s (default 300.0) for providers that own their transport, plumbed through to LocalProvider.

Related issue

None

Test plan

just check passes (ruff format, ruff check, mypy on 88 source files, 429 tests). New/updated tests:

  • tests/providers/test_local_contract.py: multimodal content parts, unsupported-MIME rejection, upload_file inlining, model-omitted payload, custom timeout, uploads=True capability.
  • tests/pipeline/test_cache_and_uploads.py: local file sources are inlined for Chat Completions.
  • tests/test_config.py: optional model for local, cloud model required, request_timeout_s validation.

Notes

First of a 3-PR stack hardening Pollux for v2 RC agent loops. Stacked PRs follow: error taxonomy + OpenAI interop, then the Session runtime + readiness probes. This PR targets main and stands alone.


  • PR title follows conventional commits
  • just check passes
  • Tests cover the meaningful cases, not just the happy path
  • Docs updated (if this changes public API or user-facing behavior)

Make provider="local" usable as a first-class agent backend against
self-hosted OpenAI-compatible servers:

- Inline image and audio inputs through Chat Completions content parts
  (uploads=True) and inline text files; reject unsupported MIME types
  with specific guidance instead of blanket "text-only" errors.
- Allow Config.model to be omitted for single-model local servers; the
  model field is left out of local payloads. Cloud providers still
  require model, and cache()/defer() raise clearly when it is missing.
- Add Config.request_timeout_s (default 300s) for providers that own
  their transport, plumbed through to LocalProvider.

Docs: document optional model and request_timeout_s in configuration.md.
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.24299% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pollux/providers/local.py 82.02% 16 Missing ⚠️
src/pollux/cache.py 66.66% 1 Missing ⚠️
src/pollux/config.py 87.50% 1 Missing ⚠️
src/pollux/deferred.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@seanbrar seanbrar merged commit 23f891b into main Jun 17, 2026
8 of 10 checks passed
@seanbrar seanbrar deleted the feat/local-provider-hardening branch June 17, 2026 09:05
seanbrar added a commit that referenced this pull request Jun 17, 2026
## Summary

Two agent-loop ergonomics improvements that build on the hardened local provider (#212): a richer error taxonomy and OpenAI Chat Completions message interop.

**Error taxonomy**
- `ContextOverflowError` (an `APIError` subclass) classifies context-window rejections and best-effort extracts requested/allowed token counts from provider messages.
- `ToolCallParseError` classifies unparseable model tool calls. `ToolCall.arguments_dict()` now raises it (carrying `tool_name`/`tool_call_id`/`arguments_text`), and the local provider maps server-side tool-call JSON parser failures, both HTTP errors and streamed error payloads, to the same recoverable type.

**OpenAI message interop**
- `Continuation.from_openai_messages` / `to_openai_messages` and `Message`/`ToolCall` `.from_openai` / `.to_openai` let harnesses that already store OpenAI Chat Completions transcripts replay them through Pollux.

## Related issue

None

## Test plan

`just check` passes (ruff format, ruff check, mypy, 435 tests). New tests:
- `tests/providers/test_errors.py`: context-overflow wrapping with token-count extraction.
- `tests/interaction/test_tools.py`: `arguments_dict()` raises `ToolCallParseError` with metadata.
- `tests/interaction/test_continuation.py`: OpenAI message import + tool-call round-trip.
- `tests/providers/test_local_contract.py` / `test_local_stream.py`: local tool-call-parse classification for HTTP and SSE error payloads.

## Notes

Second of a 3-PR stack for v2 RC. **Stacked on #212** - review/merge that first. The `Session` runtime + readiness probes follow in the next PR.
seanbrar added a commit that referenced this pull request Jun 17, 2026
## Summary

Make multi-turn agent loops first-class without re-creating a provider per call.

- **`Session`** owns one provider instance across many `interact()` / `stream()` / `run_many()` turns and closes it on exit. The one-shot module helpers now delegate to a single-use `Session`, so their behavior is unchanged.
- **Readiness probes**: a `ReadinessProvider` protocol + `ProviderReadiness` result let a provider expose a fast preflight. `Session.check_ready()` and the module-level `check_ready()` probe before packing context. The local provider implements it against `/health` and `/v1/models`, verifying the configured model when one is set.
- **`local_reasoning()`** helper returns the scoped `provider_options` for local servers that honor `enable_thinking`.

## Related issue

None

## Test plan

`just check` passes (ruff format, ruff check, mypy, 443 tests). New tests:
- `tests/interaction/test_interact_frontdoor.py`: `Session` reuses and closes its provider; module-level `check_ready()` uses the provider probe; `local_reasoning()` shape.
- `tests/providers/test_local_contract.py`: local `check_ready` health-endpoint path, models fallback, missing-model reporting, model-unset skip, and model-verification requirement.

## Notes

Third and final PR in the v2 RC stack. **Stacked on #213 (which is on #212)**.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant