Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions LocalAgent.ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@
.UseFunctionInvocation()
.UseOpenTelemetry(configure: t => t.EnableSensitiveData = true);

// Configure extended timeouts for local LLM operations
// The HttpClient naming convention is "{connectionName}_httpClient"
builder.Services.AddHttpClient("llama32_httpClient")
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
{
// Configure connection pooling to keep connections alive longer for LLM requests
PooledConnectionLifetime = TimeSpan.FromMinutes(10),
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(5)
})
.ConfigureHttpClient(client =>
{
// Set to infinite to let the resilience pipeline handle timeouts
client.Timeout = Timeout.InfiniteTimeSpan;
})
.AddStandardResilienceHandler(options =>
{
// Increase total request timeout to 5 minutes for local LLM inference
options.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(5);
// Increase attempt timeout to 2 minutes, leaving room for retry logic
options.AttemptTimeout.Timeout = TimeSpan.FromMinutes(2);
});

builder.Services.AddSingleton<IClientTransport>(sp =>
{
var mcpServerEndpoint = builder.Configuration.GetConnectionString("McpServer")!;
Expand Down
Loading