Getting "Toolset is not available in the client" error with Azure AI Agent when importing custom tools from separate file

I’m having trouble with Azure AI Agents when I try to import custom function tools from a different Python file. I have created some custom functions and put them in a ToolSet, but I get an error when the agent tries to use them.

Here’s my setup:

# In my tools file
custom_toolset = ToolSet()
my_functions = FunctionTool.from_defaults({
    method1,
    method2, 
    method3,
    method4,
    method5
})
custom_toolset.add(my_functions)

# In my main file  
my_agent = project_client.agents.create_agent(
    model=os.environ.get("AZURE_AOAI_CHAT_MODEL_NAME_DEPLOYMENT_ID"),
    name="custom-tool-agent",
    instructions="You can call custom functions when needed to help users.",
    toolset=custom_toolset
)

The error I get is: ValueError: Toolset is not available in the client.

What’s weird is that if I put everything in one file, it works fine. The problem only happens when I import the ToolSet from another module. I’ve double checked that the import is working correctly and all the functions are defined properly.

Why does this happen when using separate files? Is there a way to fix this so I can keep my tools organized in a separate module?

This is a classic serialization issue with Azure AI Agents. When you create the ToolSet in a separate module, the client can’t properly serialize function references across module boundaries.

I hit this exact problem about 6 months ago. You need to import and register your tools in the same context where you create the agent.

Try this instead:

# In your main file
from your_tools_module import method1, method2, method3, method4, method5

# Create the toolset in the same file where you use it
custom_toolset = ToolSet()
my_functions = FunctionTool.from_defaults({
    method1,
    method2, 
    method3,
    method4,
    method5
})
custom_toolset.add(my_functions)

my_agent = project_client.agents.create_agent(
    model=os.environ.get("AZURE_AOAI_CHAT_MODEL_NAME_DEPLOYMENT_ID"),
    name="custom-tool-agent",
    instructions="You can call custom functions when needed to help users.",
    toolset=custom_toolset
)

Import the individual functions but create the ToolSet in your main execution context. This way the agent client can properly handle the function references.

If you want more details on how Azure AI Agent Service handles tool registration, check out this video: