Azure AI Agent throws "ValueError: Toolset is not available in the client." error when using custom function tools from separate files

I’m having trouble with Azure AI Agents when I try to use custom functions that are defined in different files. I created some custom functions and wrapped them with FunctionTool, then put them in a ToolSet. Here’s my setup:

{
    my_function1,
    my_function2, 
    my_function3,
    my_function4,
    my_function5
}

custom_toolset = ToolSet()
custom_toolset.add(my_functions_tool)

my_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=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 functions.py and app.py), it works fine without any errors
  • The problem only happens when I define the ToolSet in one file and try to use it in another file

My questions:

  • Why does this ValueError: Toolset is not available in the client. happen when I split my code across multiple files?
  • What’s the right way to use a ToolSet from one module (functions.py) in an agent created in another module (app.py)?

Things I already tried:

  • Made sure I’m importing custom_toolset correctly into app.py
  • Double checked all my environment variables and dependencies
  • Confirmed that my ToolSet and FunctionTool objects are built properly