-
-
Notifications
You must be signed in to change notification settings - Fork 14
AgentFactories
Note
In the sample below, we create and use an OpenAIAgentFactory, but all factories works the same (but with slight variations)
(AnthropicAgentFactory, AzureOpenAIAgentFactory, GitHubAgentFactory, GoogleAgentFactory, MistralAgentFactory, OpenAIAgentFactory, OpenRouterAgentFactory, OpenAIAgentFactory)
Each AgentFactory serves the same purpose of creating Agent Definitions for you to use to call the LLMs.
You have 2 ways to create an Agent Factory (using simplified connection info or a Connection instance)
Option 1. Create a new instance manually
OpenAIAgentFactory agentFactory1 = new OpenAIAgentFactory("<api-key>");
//or
OpenAIAgentFactory agentFactory2 = new OpenAIAgentFactory(new OpenAIConnection
{
ApiKey = "<api-key>",
NetworkTimeout = TimeSpan.FromMinutes(5)
});Option 2. Use Dependency Injection
builder.Services.AddOpenAIAgentFactory("<api-key");
//or
builder.Services.AddOpenAIAgentFactory(new OpenAIConnection
{
ApiKey = "<api-key>",
NetworkTimeout = TimeSpan.FromMinutes(5)
});Each AgentFactory has 2 CreateAgent method overloads: one with simplified options, and one with more advanced options
//Create your simplified Agent (Support 'model', 'instructions', 'name', and 'tools')
OpenAIAgent agent = agentFactory.CreateAgent(model: "gpt-5", instructions: "You are a nice AI");
//Create your more advanced Agent with access to all options
OpenAIAgent agent = agentFactory.CreateAgent(new AgentOptions
{
Model = "gpt-5",
ReasoningEffort = OpenAIReasoningEffort.Low, //Set reasoning effort
Instructions = "You are a nice AI", //The System Prompt
Tools = [], //Add your tools here
});In all AgentFactories, Model is mandatory; in AnthropicAgentFactory, the property MaxOutputTokens is also mandatory to set, while it is optional for the rest.
| Property | Notes |
|---|---|
Model |
- In AzureOpenAI, you technically provide the 'DeploymentName' from https://ai.azure.com and not the Model name- Several of the Providers have a 'const' collection of Model-name, example OpenAIChatModels
|
MaxOutputTokens |
Only Anthropic has this requirement, and the rest can optionally set this. |
Most Agents needs Instructions and Tools to be of true value. Beyond that, the various 'Thinking settings' for reasoning models are common to set, and on OpenAI-based providers, you can choose ClientType. Finally, some scenarios require you to specify a name for your Agent
| Property | Notes |
|---|---|
Name |
The Name of the Agent (Optional in most cases, but some scenarios do require one) |
Instructions |
Instructions is the LLMs System Message (sometimes also called the Developer Message). It allows you to steer the models, tone, rules, and behaviour through Prompt Engineering |
Tools |
You can on an Agent set a collection of tools that Agent can choose to activate during a prompt (You often use the Instructions to steer the model on when and in what order tools should be called) - Tip: You can use AIToolsFactory to help define your Tools beyond the normal AIFunctionFactory
|
ClientType |
In OpenAI-based systems (OpenAI, ÀzureOpenAI, OpenRouter, and XAI), you can choose for each agent if you wish to use OpenAI's ChatClient protocol or their ResponseAPI protocol. By default, an Agent uses the ClientType defined on the parent Connection, which has ChatClient as default, but you can override the default at the connection level or directly on Agent creation using this property |
| 'Thinking Settings' | Across the various providers there is different ways to set how much an LLM should 'think' before answering - On OpenAI-based Agents you can set the ReasoningEffort to none, minimal, low, medium, high or xhigh- On OpenAI-based Agent using the ResponsesAPI you can set the ReasoningSummaryVerbosity for what reasoning summary should be returned (aka text on what the model 'thought' about)- On AnthropicAgents you can set the BudgetTokens property to indicate how many tokens the Agent are allowed to think (minimum 1024 tokens)- On GoogleAgents you can set the ThinkingBudget property to indicate how many tokens the Agent are allowed to think |