I’m having trouble with Azure AI Agents when trying to use custom functions that are defined in a separate module. I created some user-defined functions and wrapped them with FunctionTool, then put them in a ToolSet. Here’s my setup:
{
helper_func1,
helper_func2,
helper_func3,
helper_func4,
helper_func5
})
my_custom_toolset = ToolSet()
my_custom_toolset.add(helper_functions_tool)
ai_agent = project_client.agents.create_agent(
model=os.environ.get("AZURE_AOAI_CHAT_MODEL_NAME_DEPLOYMENT_ID"),
name="helper-functions-agent",
instructions="""
You are a smart assistant that can execute user-defined functions when needed.
""",
toolset=my_custom_toolset,
)
But when I try to create a thread and run it, I get this error:
ValueError: Toolset is not available in the client.
What I noticed:
When I put everything in one file (combining helpers.py and app.py), it works fine without any errors
The problem only happens when the ToolSet is created in one file and the agent is created in another file
My questions:
Why does this ValueError: Toolset is not available in the client. happen when I split the code across different files?
What’s the right way to use a ToolSet that’s defined in one file (helpers.py) inside an agent created in another file (app.py)?
Things I already tried:
Made sure my_custom_toolset is properly imported into app.py
Double-checked all environment variables and dependencies
Confirmed the ToolSet and FunctionTool are built correctly
I encountered a similar issue recently. The problem arises from how Azure AI manages function references during agent initialization. The client requires actual function objects, not just their definitions. When you separate code into different files, the client can lose track of the original function definitions, despite correct imports. A solution that worked for me was to create a factory function in your helpers.py that not only returns the toolset but also registers the functions within the client context. For example:
Then, invoke this function from app.py to ensure proper context for function registration alongside agent creation. Additionally, verify that your Azure AI SDK is up to date, as older versions had limitations regarding cross-module function resolution.
sounds like serialization might be the issue here. azure ai agents perhaps can’t handle custom functions when you’re passing toolsets across files. maybe try registering your functions right where you create the agent instead of importing the whole toolset.
This happens because Azure AI can’t serialize the toolset when your functions are in external modules. The client needs access to function definitions at runtime, but external files break serialization. I’ve hit this before. Fix it by creating the ToolSet in the same file as your project_client, or skip the ToolSet wrapper and pass FunctionTool objects directly to the agent. What also worked for me: use absolute imports and make sure the module with your functions is installed in your environment. Sometimes the client can’t find function definitions during serialization if the import path isn’t resolved right.
Had the same issue last week. Import the functions directly in app.py and rebuild the toolset there instead of passing a pre-built one. Azure client loses function context when the toolset crosses file boundaries. Fixed it by moving toolset creation to the same file as agent initialization.
I hit this exact same issue 6 months ago. Azure AI client validates toolsets during agent creation, but it can’t validate functions from a different execution context.
Here’s what worked for me: move the toolset creation to app.py but keep your actual functions in helpers.py:
# In app.py
from helpers import helper_func1, helper_func2, helper_func3, helper_func4, helper_func5
# Create toolset here, not in helpers.py
helper_functions_tool = FunctionTool({
helper_func1,
helper_func2,
helper_func3,
helper_func4,
helper_func5
})
my_custom_toolset = ToolSet()
my_custom_toolset.add(helper_functions_tool)
# Now create agent
ai_agent = project_client.agents.create_agent(...)
Import the functions but build the toolset wrapper where you create the agent. Client validation happens during agent creation, so everything needs to be in the same scope then.
You still get clean code separation without the serialization headaches.