feat(adapter): add native tool-call controls - #56
Conversation
Greptile SummaryThis PR refactors the adapter layer to split the previously unified
Confidence Score: 3/5The call pipeline change is functionally correct, but it silently drops adapter format callbacks for all existing users. The rerouting of dspy/adapters/base.py — specifically the relationship between the callback-decorated Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Adapter
participant plan_fields
participant render_request
participant render_messages
participant format
Caller->>Adapter: __call__(lm, lm_kwargs, signature, demos, inputs)
Adapter->>plan_fields: plan_fields(lm, lm_kwargs, signature, inputs)
Note over plan_fields: Strips tool/reasoning/citations fields<br/>Appends native_feature_instructions<br/>Sets parallel_tool_calls in lm_kwargs
plan_fields-->>Adapter: "plan{prompt_signature, inputs, lm_kwargs, tools, ...}"
Adapter->>render_request: render_request(plan, lm, demos, inputs)
render_request->>render_messages: render_messages(prompt_signature, demos, plan.inputs)
Note over render_messages: Returns list[LMMessage] — NO callbacks
render_messages-->>render_request: list[LMMessage]
render_request-->>Adapter: LMRequest
Adapter->>Adapter: call_lm(lm, request)
Adapter->>Adapter: parse_response(plan, response, lm)
Adapter-->>Caller: list[dict]
Note over format: Public API only (OpenAI-shaped output)<br/>Callbacks fire here, but this path<br/>is NOT used during normal calls
Caller->>format: format(signature, demos, inputs)
format->>render_messages: render_messages(...)
format-->>Caller: list[dict] (OpenAI-chat-shaped)
|
Summary
format()output OpenAI-chat-shaped while using normalizedrender_messages()internallyStack
Validation
uv run --extra dev pytest -q tests/adapters/test_history_formatting.py tests/adapters/test_history_lm_messages.py tests/adapters/test_tool.py::test_native_tool_response_preserves_call_ids tests/adapters/test_chat_adapter.py::test_chat_adapter_with_tool tests/adapters/test_chat_adapter.py::test_tool_call_with_null_content_does_not_raise