fix(rag): restore adapter from null; gate serializer to json mode

Address Cursor bugbot review: _resolve_adapter now substitutes the
placeholder for None payloads (so _ensure_adapter rebuilds), and
_serialize_adapter only fires under when_used='json' to keep python-mode
dumps lossless.
This commit is contained in:
Greyson LaLonde
2026-05-23 13:06:34 -07:00
parent 7bc995bec5
commit a76b99478a

View File

@@ -103,16 +103,16 @@ class Adapter(BaseModel, ABC):
def _resolve_adapter(value: Any) -> Any:
"""Validate the ``adapter`` field, returning a placeholder for dict input.
"""Validate the ``adapter`` field, returning a placeholder for dict/None input.
Adapter state is not round-tripped; the ``_ensure_adapter`` post-validator
rebuilds a fresh adapter from the tool's ``config``.
"""
if isinstance(value, Adapter):
return value
if not isinstance(value, dict):
return value
return RagTool._AdapterPlaceholder()
if value is None or isinstance(value, dict):
return RagTool._AdapterPlaceholder()
return value
def _serialize_adapter(adapter: Any, info: Any) -> Any:
@@ -148,7 +148,7 @@ class RagTool(BaseTool):
adapter: Annotated[
Adapter,
BeforeValidator(_resolve_adapter),
PlainSerializer(_serialize_adapter),
PlainSerializer(_serialize_adapter, when_used="json"),
] = Field(default_factory=_AdapterPlaceholder)
config: RagToolConfig = Field(
default_factory=RagToolConfig,