This sample demonstrates how to dynamically expand the set of function tools available to an agent during a function-calling loop.
- The agent starts with only a single
RequestToolsfunction - When the model needs capabilities it doesn't have, it calls
RequestToolswith a description of the functionality needed - The
RequestToolsfunction uses the ambientFunctionInvokingChatClient.CurrentContextto accessChatOptions.Toolsand add new tools at runtime - The agent then uses the newly added tools in subsequent iterations of the same function-calling loop
- A tool catalog maps keywords (e.g. "weather", "time", "temperature") to pre-built
AIFunctioninstances - The
RequestToolsfunction matches the description against catalog keywords and adds matching tools toChatOptions.Tools FunctionInvokingChatClientautomatically picks up the new tools on the next iteration of its loop
- .NET 10 SDK or later
- OpenAI API key
Set the required environment variables:
export OPENAI_API_KEY="your-api-key"
export OPENAI_CHAT_MODEL_NAME="gpt-5.4-mini" # Optional, defaults to gpt-5.4-miniRun the sample:
dotnet run