Skip to content

refactor(adapter): simplify base adapter flow - #64

Draft
isaacbmiller wants to merge 1 commit into
reviewable/adapter-simplify-01-type-bridgesfrom
reviewable/adapter-simplify-02-base-flow
Draft

refactor(adapter): simplify base adapter flow#64
isaacbmiller wants to merge 1 commit into
reviewable/adapter-simplify-01-type-bridgesfrom
reviewable/adapter-simplify-02-base-flow

Conversation

@isaacbmiller

@isaacbmiller isaacbmiller commented May 27, 2026

Copy link
Copy Markdown

Summary

This is PR 2 of 2 in the adapter simplification stack. It sits on top of #63.

This PR simplifies dspy/adapters/base.py now that PR 1 gives native response types a normalized LMOutput parse hook. The adapter still builds an LMRequest internally, but it does not change dspy.LM, BaseLM, or the provider/client boundary.

Key changes:

  • Collapses the adapter call path into a small prepare/call/postprocess flow.
  • Keeps the current BaseLM boundary by converting the internal LMRequest back to legacy OpenAI-shaped kwargs inside the adapter edge.
  • Parses normalized LMResponse / LMOutput values directly instead of converting back through legacy postprocess dictionaries.
  • Preserves native tool-call parsing, ToolCalls output filling, native response types, logprobs, and empty-output handling.
  • Keeps custom/unknown legacy content blocks round-trippable while adapters still render legacy Type.format() content blocks.

Why This Belongs After #63

The base adapter can only parse LMResponse directly once custom/native response fields know how to read normalized output parts. #63 adds that output hook and the small history/type bridge; this PR then uses it to remove the bulk of the internal legacy parsing path.

Review Notes

This deliberately avoids the LM/client files. The adapter builds LMRequest because that is the internal shape we want to move toward, but the call into current BaseLM remains:

  1. Build normalized LMRequest from adapter-rendered messages.
  2. Convert it to current BaseLM-compatible kwargs with to_openai_chat_request(...) at the adapter edge.
  3. Call lm(messages=..., **kwargs) / lm.acall(...).
  4. Normalize legacy LM outputs to LMResponse for adapter parsing.

That leaves the future deletion path clear: when BaseLM accepts/returns normalized request/response objects, remove the adapter-local _legacy_call_kwargs(...) and legacy-output normalization call.

Validation

  • uv run --frozen ruff check dspy/adapters/base.py dspy/adapters/types/base_type.py dspy/adapters/types/citation.py dspy/adapters/types/reasoning.py dspy/core/types.py
  • uv run --frozen pytest --deno -q tests/core/test_types.py tests/streaming/test_streaming.py::test_streaming_allows_custom_streamable_type tests/adapters tests/signatures/test_adapter_file.py
    • 279 passed, 14 warnings
  • uv run --frozen pytest --deno -q tests
    • 1046 passed, 233 skipped, 2 xfailed, 50 warnings

@isaacbmiller
isaacbmiller force-pushed the reviewable/adapter-simplify-02-base-flow branch from c6f76a0 to c45be69 Compare May 27, 2026 05:28
@isaacbmiller
isaacbmiller force-pushed the reviewable/adapter-simplify-01-type-bridges branch from 1d4c395 to 188e60a Compare May 27, 2026 05:28
@isaacbmiller
isaacbmiller force-pushed the reviewable/adapter-simplify-02-base-flow branch from c45be69 to d479da7 Compare May 27, 2026 05:44
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