-
-
Notifications
You must be signed in to change notification settings - Fork 14
AgentFactories
Rasmus Wulff Jensen edited this page Dec 25, 2025
·
18 revisions
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 methods; one with simplified options, and one with more advanced options