Conversation
061a342 to
fa62848
Compare
8e8a624 to
155f4e6
Compare
eb8680
commented
Jan 28, 2026
Contributor
Author
eb8680
left a comment
There was a problem hiding this comment.
I know I suggested this API, but to address #495 I'm realizing we probably want to modify the interfaces of these new operations so that they return both a Message and correctly decoded data:
type ToolCallId = ...
class DecodedToolCall[T](typing.NamedTuple):
tool: Tool[..., T]
bound_args: inspect.BoundArguments
id: ToolCallId
final: bool
@Operation.define
def call_assistant[T](
messages: Sequence[Message],
encoding: Encodable[T, pydantic.BaseModel | str],
**kwargs
) -> tuple[Message, T | None, Sequence[DecodedToolCall]]:
...
message: Message = ...
if message.tool_calls:
decoded_tool_calls: Sequence[DecodedToolCall] = ...
return message, None, decoded_tool_calls
else:
result: T = encoding.decode(encoding.deserialize(message.content))
return message, result, ()
@Operation.define
def call_tool[T](
tc: DecodedToolCall[T],
) -> tuple[Message, T]:
result: T = tc.tool(*tc.bound_args.args, **tc.bound_args.kwargs)
encoding = Encodable.define(type(result))
msg: Message = Message(role="tool", content=encoding.serialize(encoding.encode(result)), tool_call_id=tc.id)
return msg, resultde0d915 to
1400d19
Compare
Contributor
|
@eb8680 , ready for review! |
ba8a6db to
c47abd6
Compare
eb8680
commented
Jan 30, 2026
Contributor
Author
eb8680
left a comment
There was a problem hiding this comment.
This removes RetryLLMHandler, is that still intended?
Contributor
|
Leaving |
Contributor
Author
|
OK, in that case it's good to merge. You'll have to approve and merge it yourself since I'm the original author of the PR. |
Contributor
|
Gotcha, will do once tests pass! Rebasing the synthesis on top of this, and working on that in parallel |
kiranandcode
approved these changes
Jan 31, 2026
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.
This refactoring PR reorganizes the internals of
handlers.llmaround four newOperations, each of which (call_assistant,call_user,call_system,call_tool) is responsible for constructing allMessages for onerole("assistant", "user", "system", "tool") in the completions API.It also avoids the anti-pattern of handling
Template.__apply__, except as a temporary expedient inRetryLLMHandler, and includes some general code cleanup ofcompletions.py.I'm putting it up as a draft for discussion, since I haven't finished getting tests to pass and there are still some outstanding design questions, particularly around the desired semantics of failure and repetition.