When I create tools programmatically with function...
# ask-ai
t
When I create tools programmatically with function_tool() in Agent's constructor, I am passing raw_schema as the 4th argument to it. My raw schema defines required arguments and their types. However, when agent calls the tool, it fails with "missing a required argument" error. How do i troubleshoot this? How do I make sure functions are actually created with arguments I need?
t
Thanks for reaching out, Aivis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's work together to troubleshoot the "missing required argument" error you’re seeing when using
function_tool()
with
raw_schema
. Here are some friendly steps to guide you: 1. First, please check that your
raw_schema
includes a
parameters
key. If it’s missing, you might see a
ValueError
saying: "raw function description must contain a parameters key." Adding this key should help! 2. Next, take a look at the
name
field in your
raw_schema
. It shouldn’t be empty, because an empty name will trigger a
ValueError
with the message: "raw function name cannot be empty." Giving it a proper name will get you past this. 3. Make sure all required parameters are clearly listed in the
required
array inside the
parameters
object. If any required parameters are missing here, they won’t be recognized as required, which could cause issues. 4. Also, double-check your function handler’s signature. When you use raw schemas, the parameters come in as a dictionary called
raw_arguments
. So, your function handler should accept
raw_arguments: dict[str, object]
as its parameter to work smoothly. 5. Finally, it can be really helpful to compare your schema with examples from the documentation. For example, the
open_gate
tool shows a nicely formatted
required
array that includes "gate_id". This can be a great reference to ensure your format is spot on. By following these steps, you’ll be well on your way to resolving the issue and having your functions created with all the required arguments. If you have any questions along the way, I’m here to help! Sources: livekit-plugins/livekit-plugins-anthropic/livekit/plugins/anthropic/utils.p... | Docs::Agents
👍 1