Serialize code-derived values as raw strings - #778
Open
eb8680 wants to merge 1 commit into
Open
Conversation
A synthesized function crossed the model boundary as source escaped inside a
JSON object -- `{"code": ...}`, via the `EncodedFunction` model on the way out
and the `SynthesizedFunction` family on the way in. Providers that decode
structured output approximately (ds4) have to get that escaping right by hand,
and the wrapper dragged a `$defs`/`$ref` into every schema mentioning a
callable. Generalize what `synthesis.snippet` already does for `types.CodeType`:
a bare `str`, with `BeforeValidator`/`PlainSerializer` doing the work.
`EncodedFunction` becomes an `Annotated[str, Field(...)]`, and the
`SynthesizedFunction`/`SynthesizedSkillBody`/`SynthesizedMethodSkillBody`
hierarchy flattens into `_signature_str`, `_synthesized_source_schema` and
`_checked_source`. The prose those classes carried was split across a model
docstring and a field description, which the single string schema merges: the
signature line and all five constraints survive, and constraints 1-3 -- until
now repeated verbatim at three sites -- are stated once. The method body's
`_extra_instructions` is dropped as the third statement of its `self` receiver,
which the rendered `Callable[[self, ...], R]` and constraint 4 both still make.
A prompt-spliced function now also reaches the model as unencoded source rather
than escaped inside a string, which `to_content_blocks` gets for free once the
encoding is a top-level string.
The replay fixtures are migrated rather than re-recorded: `REBUILD_FIXTURES`
cannot run, because `ReplayLiteLLMProvider._completion` forwards `fwd(*args,
**kwargs)` without `model` and litellm rejects the call. That fails identically
on the base branch, so it is a separate bug; only each fixture's JSON envelope
is rewritten, and every recorded source string is preserved byte for byte.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #775 , blocked by #770
This pure-refactoring PR implements the suggestion in #775 to remove the junk Pydantic intermediates in code generation. The diff looks bigger than it is because of reindentation and needing to propagate the schema change to test fixtures, but it's conceptually just replacing
SynthesizedFunctionet al withAnnotated[str, BeforeValidator(...)]and should be completely semantics-preserving, including what is shown to the model in the schema. It also eliminates some redundant types and docstrings.This would be even cleaner in conjunction with #765 but it shouldn't be blocked by that.