Skip to content
Discussion options

You must be logged in to vote

Great question — the design you've landed on is actually very close to the framework's intended pattern, but the framework has a first-class hook for exactly this scenario that lets you drop the factory altogether. Walking through your three questions:

1. The agent should be a singleton, not per-request

AIAgent instances are designed to be stateless and long-lived. All of the AddAIAgent overloads in Microsoft.Agents.AI.Hosting default to ServiceLifetime.Singleton for that reason — see AgentHostingServiceCollectionExtensions.cs:

public static IHostedAgentBuilder AddAIAgent(
    this IServiceCollection services,
    string name,
    string? instructions,
    ServiceLifetime lifetime = Servi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ahmar-husain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants