Class AgentGlobalConfigurationBuilder
Provides a fluent interface for configuring global AI agent settings including API keys and default providers.
public class AgentGlobalConfigurationBuilder
- Inheritance
-
AgentGlobalConfigurationBuilder
- Inherited Members
Remarks
This builder class is used internally by AgentGlobalConfiguration.Configure() to provide a type-safe, fluent API for setting up global agent configuration. It allows you to configure API keys for multiple LLM providers (OpenAI, Anthropic, Azure OpenAI) and specify which provider should be used by default. The builder pattern enables method chaining for clean, readable configuration code. Once all settings are configured, the Apply() method transfers them to the AgentGlobalConfiguration static class where they're stored for use across the application.
For Beginners: This class helps you set up your AI agent credentials using a clean, readable syntax.
You don't create this class directly - instead, you receive it through AgentGlobalConfiguration.Configure():
AgentGlobalConfiguration.Configure(builder => builder
.ConfigureOpenAI("your-api-key")
.UseDefaultProvider(LLMProvider.OpenAI));
The builder pattern:
- Makes configuration code easy to read
- Lets you chain multiple setup calls together
- Provides IntelliSense (autocomplete) to guide you
- Ensures all settings are valid before they're applied
Think of it as a temporary workspace where you specify all your settings. Once you're done configuring, the builder transfers everything to the global configuration where it's stored and used by your models.
For example:
// At application startup
AgentGlobalConfiguration.Configure(config => config
.ConfigureOpenAI("sk-...") // Set OpenAI API key
.ConfigureAnthropic("sk-ant-...") // Set Anthropic API key
.UseDefaultProvider(LLMProvider.OpenAI)); // Choose default
// All three methods return the builder, so they chain together
// When the lambda completes, Apply() is called automatically
// Your settings are now stored globally for all models to use
This approach keeps your configuration code organized and readable, especially when setting up multiple providers.
Methods
ConfigureAnthropic(string)
Configures the API key for Anthropic's Claude language models.
public AgentGlobalConfigurationBuilder ConfigureAnthropic(string apiKey)
Parameters
apiKeystringYour Anthropic API key, obtainable from console.anthropic.com.
Returns
- AgentGlobalConfigurationBuilder
The current builder instance for method chaining.
Remarks
This method sets the API key that will be used for all Anthropic API calls when agent assistance is enabled. The key should be obtained from your Anthropic account at console.anthropic.com. Once configured, this key will be used automatically by any AiModelBuilder that enables agent assistance with the Anthropic provider, unless explicitly overridden at the builder level. Anthropic's Claude models are known for detailed explanations and large context windows.
For Beginners: This sets up your Anthropic credentials so the AI agent can use Claude models.
How to get an Anthropic API key:
- Sign up at console.anthropic.com
- Navigate to API keys in your account settings
- Click to create a new key
- Copy the key (it starts with "sk-ant-") and save it securely
- Use it here in your configuration
Example:
AgentGlobalConfiguration.Configure(config => config
.ConfigureAnthropic("sk-ant-...your-key-here..."));
Why choose Anthropic:
- Claude models provide very detailed, thoughtful explanations
- Large context windows can handle more information at once
- Known for being particularly helpful and safe
- Good for educational use cases where detailed reasoning matters
Security tips:
- Never commit your API key to source control
- Use environment variables or secret management in production
- Monitor your usage to control costs
Once configured, all your models can use Anthropic's Claude for agent assistance.
ConfigureAzureOpenAI(string)
Configures the API key for Azure OpenAI Service.
public AgentGlobalConfigurationBuilder ConfigureAzureOpenAI(string apiKey)
Parameters
apiKeystringYour Azure OpenAI API key, obtainable from the Azure Portal.
Returns
- AgentGlobalConfigurationBuilder
The current builder instance for method chaining.
Remarks
This method sets the API key that will be used for all Azure OpenAI API calls when agent assistance is enabled. The key should be obtained from your Azure OpenAI resource in the Azure Portal. Note that Azure OpenAI requires additional configuration beyond just the API key - you'll also need to specify the endpoint URL and deployment name when configuring individual models. Azure OpenAI provides the same models as OpenAI but with enterprise features like regional data residency, enhanced security, and integration with Azure services.
For Beginners: This sets up your Azure OpenAI credentials for enterprise-grade AI assistance.
How to get an Azure OpenAI API key:
- Create an Azure account and get approved for Azure OpenAI Service
- Create an Azure OpenAI resource in the Azure Portal
- Navigate to "Keys and Endpoint" in your resource
- Copy one of the keys shown
- Also note your endpoint URL - you'll need it later
- Deploy a model (like GPT-4) and note the deployment name
- Use the key here in your global configuration
Example:
AgentGlobalConfiguration.Configure(config => config
.ConfigureAzureOpenAI("your-azure-key")
.UseDefaultProvider(LLMProvider.AzureOpenAI));
Why choose Azure OpenAI:
- Enterprise-grade security and compliance (SOC 2, HIPAA, etc.)
- Data stays in your specified Azure region
- Integrated billing with other Azure services
- Same powerful GPT models as OpenAI
- Virtual network support and private endpoints
Important notes:
- Azure OpenAI requires approval (apply at azure.microsoft.com/products/cognitive-services/openai-service)
- You need to specify endpoint and deployment name when building models
- Pricing may differ from direct OpenAI API
This is the preferred option for enterprise applications with strict compliance requirements.
ConfigureOpenAI(string)
Configures the API key for OpenAI's language models (GPT-3.5, GPT-4, etc.).
public AgentGlobalConfigurationBuilder ConfigureOpenAI(string apiKey)
Parameters
apiKeystringYour OpenAI API key, obtainable from platform.openai.com.
Returns
- AgentGlobalConfigurationBuilder
The current builder instance for method chaining.
Remarks
This method sets the API key that will be used for all OpenAI API calls when agent assistance is enabled. The key should be obtained from your OpenAI account at platform.openai.com. Once configured, this key will be used automatically by any AiModelBuilder that enables agent assistance with the OpenAI provider, unless explicitly overridden at the builder level.
For Beginners: This sets up your OpenAI credentials so the AI agent can use OpenAI's models.
How to get an OpenAI API key:
- Sign up at platform.openai.com
- Navigate to API keys in your account settings
- Click "Create new secret key"
- Copy the key (it starts with "sk-") and save it securely
- Use it here in your configuration
Example:
AgentGlobalConfiguration.Configure(config => config
.ConfigureOpenAI("sk-proj-...your-key-here..."));
Security tips:
- Never commit your API key to source control (use environment variables or secret management)
- Don't share your key publicly or in screenshots
- Rotate keys periodically for security
- Use OpenAI's usage limits and monitoring to prevent unexpected charges
Once configured, all your models can use OpenAI's GPT models for agent assistance without needing to provide the key again.
UseDefaultProvider(LLMProvider)
Sets which LLM provider should be used by default when one is not explicitly specified.
public AgentGlobalConfigurationBuilder UseDefaultProvider(LLMProvider provider)
Parameters
providerLLMProviderThe LLMProvider to use as the default (OpenAI, Anthropic, or AzureOpenAI).
Returns
- AgentGlobalConfigurationBuilder
The current builder instance for method chaining.
Remarks
This method specifies which LLM provider will be used by default across all model builders when agent assistance is enabled but no specific provider is chosen. This eliminates the need to specify the provider for each individual model, while still allowing overrides when needed. Choose the provider you'll use most frequently as your default. If not specified, OpenAI is used as the default.
For Beginners: This tells the system which AI service to use when you don't specify one.
Setting a default provider:
- Saves you from specifying the provider every time you build a model
- Ensures consistency across your application
- Can still be overridden for specific models when needed
Example:
AgentGlobalConfiguration.Configure(config => config
.ConfigureOpenAI("sk-...")
.ConfigureAnthropic("sk-ant-...")
.UseDefaultProvider(LLMProvider.Anthropic)); // Use Anthropic by default
How to choose your default:
- If you primarily use OpenAI: LLMProvider.OpenAI
- If you primarily use Anthropic: LLMProvider.Anthropic
- If you're in an enterprise Azure environment: LLMProvider.AzureOpenAI
What happens:
// Uses your default provider (Anthropic in the example above)
var result = await builder
.ConfigureAgentAssistance(options => options.EnableModelSelection())
.BuildAsync();
// Override to use a different provider for this specific model
var result2 = await builder
.ConfigureAgentAssistance(
options => options.EnableModelSelection(),
provider: LLMProvider.OpenAI) // Use OpenAI just for this one
.BuildAsync();
Choose whichever provider best fits your needs, budget, and compliance requirements.