microsoft/autogen · error · InvalidOperationException
RequestUri is null
Error message
RequestUri is null
What it means
LMStudioAgent routes HTTP traffic through CustomHttpClientHandler, which rewrites each request's URI to the configured model service URL. The rewrite reads request.RequestUri.PathAndQuery; if the outgoing HttpRequestMessage has a null RequestUri, UriBuilder cannot proceed and this InvalidOperationException is thrown.
Source
Thrown at dotnet/src/AutoGen.LMStudio/LMStudioAgent.cs:84
};
return new OpenAIClient("api-key", option);
}
private sealed class CustomHttpClientHandler : HttpClientHandler
{
private Uri _modelServiceUrl;
public CustomHttpClientHandler(Uri modelServiceUrl)
{
_modelServiceUrl = modelServiceUrl;
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// request.RequestUri = new Uri($"{_modelServiceUrl}{request.RequestUri.PathAndQuery}");
var uriBuilder = new UriBuilder(_modelServiceUrl);
uriBuilder.Path = request.RequestUri?.PathAndQuery ?? throw new InvalidOperationException("RequestUri is null");
request.RequestUri = uriBuilder.Uri;
return base.SendAsync(request, cancellationToken);
}
}
}
View on GitHub (pinned to 027ecf0a37)
Solutions
- Verify the modelServiceUrl passed to LMStudioAgent is an absolute URI including scheme and host (e.g. http://127.0.0.1:1234).
- Confirm the local LM Studio server is running and reachable at that URL.
- Align the Google.Cloud.AIPlatform / REST client package versions with the AutoGen.LMStudio version you use.
- If it persists, report upstream — a null RequestUri at this point indicates a client-pipeline mismatch, not a user input error.
Example fix
// before
var agent = new LMStudioAgent("agent", modelServiceUrl: new Uri("localhost:1234", UriKind.Relative));
// after
var agent = new LMStudioAgent("agent", modelServiceUrl: new Uri("http://127.0.0.1:1234")); Defensive patterns
Strategy: validation
Validate before calling
if (!modelServiceUrl.IsAbsoluteUri || string.IsNullOrEmpty(modelServiceUrl.Scheme))
{
throw new ArgumentException("modelServiceUrl must be absolute, e.g. http://127.0.0.1:1234");
} Prevention
- Always construct the agent URL with scheme+host
- Health-check the LM Studio server before starting the agent
- Pin compatible package versions
When it happens
Trigger: Creating an LMStudioAgent and issuing a completion request where the underlying HttpClient sends a request with a relative/null URI that this handler did not expect — typically a misconstructed base address in modelServiceUrl or an SDK/client version whose request pipeline differs.
Common situations: Passing a malformed Uri to the LMStudioAgent constructor (e.g. new Uri("" ) variants or a URL without scheme); mixing Google Cloud library versions where the generated client builds request URIs differently; local LM Studio server moved/changed base path.
Related errors
- Failed to get login URL
- Authentication failed
- Template ${templateId} not found for component type ${compon
- Failed to create gallery
- Failed to delete gallery
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/31397bd5f907a237.
Report an issue: GitHub.