Welcome to Portkey Forum

Updated 2 weeks ago

Anthropic tool calling

[
{
"role": "system",
"content": "My System Prompt"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "when does the flight from baroda to bangalore land tomorrow, what time, what is its flight number, and what is its baggage belt?"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_018fPMpEdPiCjkK8AkfCXgLh",
"name": "send_message_to_agent",
"input": {
"agent_name": "aggreg-agent",
"message": "WHAT: flight information from Baroda to Bangalore for tomorrow\nWHEN: tomorrow\nWHERE: Baroda to Bangalore"
}
}
]
},
{
"role": "user",
"content": [
{
"content": "tool call successful",
"type": "tool_result",
"tool_use_id": "toolu_018fPMpEdPiCjkK8AkfCXgLh"
}
]
}
]
1
V
s
G
34 comments
cant use anthropic tool calling via portkey, i have tried it with their own SDK, message formats, everything is exactly right and as per anthropics requirements.. the tool call format, the tool response format, everything is correct, have cross verified to that, still getting errors of empty content blocks from anthropic when used from portkey, not getting them when used from the anthropic SDK
{'message': 'anthropic error: messages.1: all messages must have non-empty content except for the optional final assistant message', 'type': 'invalid_request_error', 'param': None, 'code': None}, 'provider': 'anthropic'} .. error
my query/issue ⏫
i tried that
i get a provider error that a certain field is missing, or a key is mis formatted,
if self.api_key == const.OPENAI_VIRTUAL_KEY:
to_append_history = {
"type": "function",
"id": function_id,
"function": {"name": call.function.name, "arguments": call.function.arguments,}
}
elif self.api_key == const.ANTHROPIC_VIRTUAL_KEY:
to_append_history = {
"type": "tool_use",
"id": function_id,
"name": call.function.name,
"input": json.loads(call.function.arguments)
} .. i had to add handling like this bcs of such errors
Okay, can you provide the final request body that you’ve constructed?
Request body in the sense
I am using the portkey library itself
Pip install portkey
this one
Plain Text
[
    {
        "role": "system",
        "content": "My System Prompt"
    },
    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": "when does the flight from baroda to bangalore land tomorrow, what time, what is its flight number, and what is its baggage belt?"
            }
        ]
    },
    {
        "role": "assistant",
        "content": [
            {
                "type": "tool_use",
                "id": "toolu_018fPMpEdPiCjkK8AkfCXgLh",
                "name": "send_message_to_agent",
                "input": {
                    "agent_name": "aggreg-agent",
                    "message": "WHAT: flight information from Baroda to Bangalore for tomorrow\nWHEN: tomorrow\nWHERE: Baroda to Bangalore"
                }
            }
        ]
    },
    {
        "role": "user",
        "content": [
            {
                "content": "tool call successful",
                "type": "tool_result",
                "tool_use_id": "toolu_018fPMpEdPiCjkK8AkfCXgLh"
            }
        ]
    }
]
is this the json you're using when you use portkey.chat.completions()?
As the messages array
That is bcs if you use the OpenAI format
You get a provider error
If you think otherwise, try it
I had to add conditionals to handle this everywhere
oh wait my bad, let me check what is wrong
sorry I got a little confused about what exception you were getting
Like I said it's not a formatting error
wait xd, its formatting only, I got double confused :'|, you should be sending your request in openai format
No content blocks are empty...
joinign the huddle
one sec, rejoining
please join here
call summary:
  • enhancement request: merge parallel tool messages from openai format into one user message with multiple tool use blocks in content
  • bug report: handle mapping additional_properties in tool defintions from openai to gemini
  • the current request is working fine
Hey @Griphook | Portkey @s44002
What was the resolution for this issue? I'm getting the same error when i try to use anthropic computer use tools using portkey. Working fine when i directly call anthropic SDK.
Add a reply
Sign up and join the conversation on Discord