agent: skip network requests during initialization

Avoids network round trips during agent startup to keep it snappy.
Skips model reconciliation in REPL mode and loads the model-list
cache lazily instead of pre-warming it.
This commit is contained in:
Adrià Arrufat
2026-06-05 16:34:29 +02:00
parent 9d4f284c73
commit 200cbe623f

View File

@@ -279,7 +279,9 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agent
var model = try allocator.dupe(u8, resolveModelName(opts, resolved, remembered));
errdefer allocator.free(model);
if (llm) |l| {
// The REPL skips this network round trip to keep startup snappy; an invalid
// model surfaces on the first turn instead.
if (llm) |l| if (!will_repl) {
const remembered_matches = remembered != null and remembered.?.provider == l.provider;
const explicit = opts.model != null or remembered_matches;
switch (try reconcileModel(allocator, l, model, opts.base_url, explicit)) {
@@ -289,7 +291,7 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agent
},
.abort => return error.ModelNotAvailable,
}
}
};
const effort = resolveEffort(opts, remembered, will_repl);
const verbosity = resolveVerbosity(opts, remembered);
@@ -357,9 +359,8 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agent
.providers = completionProviders,
.models = completionModels,
};
// Warm the model-list cache so the first autocomplete keystroke doesn't
// block on the network.
if (self.model_credentials != null) _ = completionModels(self, allocator);
// The model-list cache fills lazily on the first `/model` completion so
// startup never blocks on the network.
}
return self;