I’m building an Azure AI Agent that needs to use custom functions. I created several helper functions and used FunctionTool to wrap them, then put everything into a ToolSet. The problem happens when I split my code across multiple files.
Here’s my setup:
# Creating the toolset with custom functions
custom_functions = {
helper1,
helper2,
helper3,
helper4,
helper5
}
my_toolset = ToolSet()
my_toolset.add(custom_functions)
# Setting up the agent
ai_agent = project_client.agents.create_agent(
model=os.environ.get("AZURE_AOAI_CHAT_MODEL_NAME_DEPLOYMENT_ID"),
name="custom-function-agent",
instructions="""
You are a helpful assistant that can execute custom functions when needed.
""",
toolset=my_toolset,
)
The weird thing is this works perfectly when everything is in one file. But when I separate the toolset creation (in helpers.py) from the agent creation (in app.py), I get this error:
ValueError: Toolset is not available in the client.
What I noticed:
Single file = works fine
Split across files = throws the error
Seems like a module import issue
Questions:
Why does splitting the code cause this “Toolset is not available” error?
What’s the right way to import and use a ToolSet from another Python module?
Already tried:
Double checked my imports from helpers.py to app.py
Made sure all environment variables are set correctly
Verified the ToolSet and FunctionTool objects are built properly
Any ideas what might be causing this cross-module issue?
Hit this same wall about 6 months ago on a project where I was modularizing Azure AI agents. The root cause is actually in how Python handles function object imports combined with Azure’s client serialization.
When you import a ToolSet from another module, the function objects inside it lose their original context. Azure’s client needs to serialize these functions, but it can’t properly access the function metadata when they’ve been imported across module boundaries.
Here’s what fixed it for me:
Don’t import the ToolSet object itself. Instead, import the raw functions and build the ToolSet locally in your main file.
# helpers.py
def helper1():
# your code
pass
def helper2():
# your code
pass
# app.py
from helpers import helper1, helper2, helper3, helper4, helper5
# Build toolset here, not in helpers.py
custom_functions = {helper1, helper2, helper3, helper4, helper5}
my_toolset = ToolSet()
my_toolset.add(custom_functions)
The key insight is that Azure needs direct access to the function objects in the same execution context where the agent gets created. When you cross module boundaries with complex objects like ToolSet, you break that chain.
I’ve used this pattern across multiple projects now and never had the error come back.
I encountered this exact issue last month when restructuring my Azure AI Agent project. The problem stems from how Azure AI handles object serialization across module boundaries. When you create the ToolSet in a separate file, the client can’t properly serialize the function references during the agent creation process. The solution that worked for me was to ensure the ToolSet creation happens in the same execution context as the agent creation. Instead of creating the complete ToolSet in helpers.py, export your individual functions and create the ToolSet in app.py where you instantiate the agent. So in helpers.py just define your helper functions, then in app.py import those functions and create both the ToolSet and agent in the same scope. Alternatively, you can create a factory function in helpers.py that returns a fresh ToolSet instance when called, rather than importing a pre-created ToolSet object. This maintains the separation while avoiding the serialization issue that causes the ‘not available in client’ error.