-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[BUG] Regression caused by v1.14.0 change in ActionStep.to_messages
method
#1224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting the regression and the details report. In principle, I'm OK with reverting the change to restore the tool_call_id in the short term. For future releases, do you have any suggestions on how we might better expose or preserve the tool call ID in a more robust or consistent way? Would be great to make this behavior more intentional and less prone to accidental breakage. |
Hey Albert, I think the main issue is that currently, the smolagents API assumes that models will want to consume tool calls and responses as raw text. We can see that here and here where messages are transformed into a message with content However, for both the OpenAI and Anthropic APIs, you are supposed to return tool calls/responses using a special content type ( I think this problem of needing to transform the raw text messages returned from smolagents to this structured format is the key point which is making the current API difficult to work with. Ideally, if self.tool_calls is not None:
messages.append(
Message(
role=MessageRole.TOOL_CALL,
content=[
{
"type": "tool_use",
"id": tool_call.id,
"name": tool_call.name,
"arguments": make_json_serializable(tool_call.arguments)
}
for tool_call in self.tool_calls
],
)
)
if self.observations is not None:
messages.append(
Message(
role=MessageRole.TOOL_RESPONSE,
content=[
# ideally, we should have one content block per tool response to avoid hardcoding self.tool_calls[0].id
# as-is, this will break if there is more than one tool response in a single message
# unfortunately, since `self.observations` is just `str` instead of `list[str]` it is probably the best we can do
{
"type": "tool_result",
"tool_use_id": self.tool_calls[0].id,
"content": self.observations,
}
],
)
) The exact format of these dictionaries is somewhat arbitrary as long as they contain all of the required information. I used something close to Anthropic's format here, but you could easily model them after OpenAPI/HuggingFace/LiteLLM/whatever instead. The idea is that consuming models could then adapt this dictionary to the exact format expected by their provider. Unfortunately, this would be a major breaking change, so I'm not sure if it would be feasible for you to implement. Maybe one alternative would be to pass |
Hi! We are encountering a regression after updating to v1.14.0.
Specifically, it's due to this change from #1148, which modified the
to_messages
method to no longer include the tool call ID in the returned message:It's a little hacky, but we were parsing the "Call id" section for our custom Anthropic model.
Anthropic requires that you pass in the
tool_use_id
for tool results (see here), and parsing it from the string was the only way we could figure out how to retrieve that ID in the context of a custom model.Code example
We were doing something like this:
which no longer works.
The text was updated successfully, but these errors were encountered: