Skip to content

feat(core): add error taxonomy and OpenAI message interop#213

Merged
seanbrar merged 3 commits into
mainfrom
feat/error-taxonomy-interop
Jun 17, 2026
Merged

feat(core): add error taxonomy and OpenAI message interop#213
seanbrar merged 3 commits into
mainfrom
feat/error-taxonomy-interop

Conversation

@seanbrar

@seanbrar seanbrar commented Jun 17, 2026

Copy link
Copy Markdown
Owner

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.


  • 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)

Sean Brar added 2 commits June 17, 2026 01:52
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.
Two agent-loop ergonomics improvements that build on the local provider:

Error taxonomy:
- ContextOverflowError (APIError subclass) classifies context-window
  rejections and best-effort extracts requested/allowed token counts.
- ToolCallParseError classifies unparseable model tool calls. ToolCall
  .arguments_dict() now raises it (with tool name/id/arguments_text), and
  the local provider maps server-side tool-call JSON parser failures —
  HTTP 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.

Docs: document the OpenAI replay import/export in agent-loop.md.
Base automatically changed from feat/local-provider-hardening to main June 17, 2026 09:05
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
src/pollux/interaction/continuation.py 65.71% 12 Missing ⚠️
src/pollux/providers/local.py 80.00% 6 Missing ⚠️
src/pollux/interaction/tools.py 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@seanbrar seanbrar merged commit a63b666 into main Jun 17, 2026
10 checks passed
@seanbrar seanbrar deleted the feat/error-taxonomy-interop branch June 17, 2026 09:09
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