I’m building an Azure AI Agent that needs to work with custom functions. I created several helper functions and wrapped them using FunctionTool, then put them into a ToolSet. Here’s my setup:
custom_functions = FunctionTool({
helper1,
helper2,
helper3,
helper4,
helper5
})
my_toolset = ToolSet()
my_toolset.add(custom_functions)
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 smart assistant that can execute custom functions when needed.
""",
toolset=my_toolset,
)
But when I try to create a thread and execute 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
The problem only happens when I define the ToolSet in one file and use it in another
My questions:
Why does this ValueError: Toolset is not available in the client. happen when I split my code across files?
How do I correctly use a ToolSet from helpers.py in my agent that’s created in app.py?
Things I already tried:
Made sure my_toolset is properly imported in app.py
Double checked all environment variables and dependencies
Confirmed the ToolSet and FunctionTool are built correctly
I’ve hit this exact issue multiple times with Azure AI agents. It’s not a serialization problem like the other answer says.
Azure validates the toolset when creating the client, but can’t find your function definitions because they’re in a different execution context.
Here’s my production fix:
Create your toolset in the same file as your agent. Import helper functions individually:
from helpers import helper1, helper2, helper3, helper4, helper5
# Create toolset in the same file as the agent
custom_functions = FunctionTool({
helper1,
helper2,
helper3,
helper4,
helper5
})
my_toolset = ToolSet()
my_toolset.add(custom_functions)
# Now create your agent
ai_agent = project_client.agents.create_agent(...)
Don’t import a pre-built toolset object. Build the FunctionTool and ToolSet where you create the agent.
Spent hours debugging this same error. Azure needs “live” function references in the current execution context when creating the agent.
Been there. Azure AI’s toolset validation is super finicky with function context and module boundaries.
Why deal with Azure’s serialization headaches when you can just avoid the problem entirely?
I used to fight these same Azure AI agent issues. Now I build everything in Latenode instead. You can create workflows that call custom functions without any toolset serialization or module context drama.
Latenode lets you define helper functions as workflow nodes and chain them visually. No more ValueError nightmares when you split code across files. Plus you get better debugging and can tweak logic without redeploying.
Migrated three Azure AI projects to Latenode last year. Zero serialization issues and way easier to maintain. The visual builder makes it dead simple to see how functions connect.
This happens because Python can’t properly serialize functions across different modules. Azure’s AI client needs to serialize your functions for the toolset, but it loses track of where the original functions are defined when they’re in one module and used in another. The problem is that importing your toolset into app.py breaks the function references in your FunctionTool - they lose their proper module context. I ran into the same thing with Azure Functions and fixed it by making sure the functions stay bound to their original module namespace before adding them to the toolset. Here’s what works: create your toolset in the same file where you set up the agent, but import the individual functions instead of importing a pre-built toolset. This lets the client properly serialize everything when creating the agent.