Skip to content

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.

Create the Agent Factory

You have 2 ways to create an Agent Factory

Option 1. Create a new instance manually (Simplified info or a Connection instance)

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 (Simplified info or a Connection instance)

builder.Services.AddOpenAIAgentFactory("<api-key");

//or

builder.Services.AddOpenAIAgentFactory(new OpenAIConnection
{
    ApiKey = "<api-key>",
    NetworkTimeout = TimeSpan.FromMinutes(5)
});

Using AgentFactory to create Agents

Each AgentFactory has 2 CreateAgent methods; one with simplified options, and one with more advanced options

Clone this wiki locally