Cross-module ToolSet usage fails with 'Toolset is not available in the client' error in Azure AI Agent

I’m having trouble with Azure AI Agents when I try to use custom functions that are defined in separate modules. I created some custom functions and wrapped them with FunctionTool, then put them into a ToolSet. But when I try to use this toolset in a different file, I get an error.

Here’s my setup:

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

# In my main module
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=custom_toolset,
)

The error I keep getting is:

ValueError: Toolset is not available in the client.

What’s weird is that if I put everything in one file, it works perfectly fine. The problem only happens when I import the toolset from another module.

I’ve double checked that I’m importing the toolset correctly and all my functions are properly defined. Has anyone run into this issue before? How do I fix the cross-module toolset problem?

had the same issue last week - you need to register the toolset with the same client instance yer using for the agent. try passing the project_client to ur tools module, or just create the toolset after u initialize the client in main.