Skip to content

Move tool/tool call encoding logic from completion to encoding#548

Open
eb8680 wants to merge 16 commits intomasterfrom
eb-remove-response
Open

Move tool/tool call encoding logic from completion to encoding#548
eb8680 wants to merge 16 commits intomasterfrom
eb-remove-response

Conversation

@eb8680
Copy link
Contributor

@eb8680 eb8680 commented Feb 9, 2026

This refactoring PR cleans up some logic in handlers.llm.completions related to tool call encoding and decoding by coercing it into the existing Encodable API.

includes the raw assistant message for retry handling.
"""
tool_specs = {k: _function_model(t) for k, t in tools.items()}
response_model = pydantic.create_model(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing response_model here was the original motivation for this PR because it was causing problems with less capable LLMs in #545, but I ended up doing a bit more cleanup along the way.

@eb8680 eb8680 mentioned this pull request Feb 9, 2026
@eb8680 eb8680 linked an issue Feb 14, 2026 that may be closed by this pull request
@eb8680 eb8680 mentioned this pull request Feb 14, 2026
@eb8680 eb8680 marked this pull request as ready for review February 15, 2026 21:54
@eb8680 eb8680 requested a review from datvo06 February 15, 2026 21:54
@eb8680
Copy link
Contributor Author

eb8680 commented Feb 15, 2026

@datvo06 I refactored the Encodable tests as part of this PR to be parametric checks that a small number of key equational laws are satisfied rather than looking at implementation details and hand-defined gold values that are brittle and subject to change.

Copy link
Contributor

@datvo06 datvo06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one concern with using enc directly. It's ok, but we have to make the encoding complete.

model,
messages=list(messages),
response_format=response_model,
response_format=None if response_format.enc is str else response_format.enc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response_model is changed to response_format.enc.
response_format.enc is just a python type, not asserted to be a Pydantic model (created through pydantic.create_model).
I understand that we want to remove the extra value wrapping layer.
But _encodable_object is not handling dataclass: enc = ty sets the type to raw class.
I think I can add a 1-line fix inside there and see if it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, because we are not creating pydantic model here anymore, and instead leave that to encodable, we would need to handle primitive types as well.

@datvo06
Copy link
Contributor

datvo06 commented Feb 16, 2026

I accidentally pushed the fix. I reverted it and making a PR on top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encodable implementations should be tested more thoroughly

2 participants