I’m having trouble with Azure AI Agents. I made some custom functions and put them in a ToolSet. It works fine when everything’s in one file. But when I split it into two files (tools.py and main.py), I get an error.
Here’s what happens:
- I make functions and add them to a ToolSet in tools.py
- I create an agent in main.py and try to use the ToolSet
- I get this error: ‘ValueError: Toolset is not available in the client.’
I’ve checked that I’m importing stuff right and all my settings are correct. Why is this happening? How can I fix it so I can use my ToolSet from tools.py in my agent in main.py?
Here’s a simple example of what I’m trying to do:
# In tools.py
def my_function():
return 'Hello'
my_toolset = ToolSet()
my_toolset.add(FunctionTool(my_function))
# In main.py
from tools import my_toolset
agent = project_client.agents.create_agent(
model='my_model',
toolset=my_toolset
)
Any ideas on how to make this work? Thanks!
hey, try passin the toolset as a param when creatin the agent instead of importing it directly. i had a similar issue and a helper function fixed it for me. hope it helps!
yo, i ran into this too. the fix is pretty simple. instead of importing the toolset, try creating a function in tools.py that returns it. then call that function in main.py to get ur toolset. worked like a charm for me. good luck!
I encountered a similar issue when using Azure AI Agents with a toolset across multiple files. The problem appears to be related to how Azure handles toolsets in different modules. Rather than importing your toolset directly, you can serialize it in your tools file and then deserialize it in your main file. In tools.py, convert your toolset to a dictionary using a method like to_dict. Then, in main.py, import that dictionary and reconstruct the toolset with a corresponding from_dict method before using it to create your agent. This should resolve the error you are experiencing.
I’ve dealt with this exact issue before, and it can be frustrating. The problem lies in how Azure AI Agents handle toolsets across different modules. A workaround that worked for me was to create a function in tools.py that returns the toolset, rather than exporting the toolset directly. Then in main.py, you can call this function to get the toolset.
Here’s how you might modify your code:
# In tools.py
def get_toolset():
toolset = ToolSet()
toolset.add(FunctionTool(my_function))
return toolset
# In main.py
from tools import get_toolset
toolset = get_toolset()
agent = project_client.agents.create_agent(
model='my_model',
toolset=toolset
)
This approach ensures that the toolset is created in the same context where it’s used, which should resolve the ‘Toolset not available in client’ error. Give it a try and let me know if it works for you!