fix: pass model and system prompt when resuming agent (#227)

This commit is contained in:
Kevin Lin
2025-12-15 19:38:13 -08:00
committed by GitHub
parent e23e27c519
commit f354e6aa41
2 changed files with 86 additions and 1 deletions

View File

@@ -249,6 +249,45 @@ export async function handleHeadlessCommand(
agent = result.agent;
}
// Check if we're resuming an existing agent (not creating a new one)
const isResumingAgent = !!(
specifiedAgentId ||
shouldContinue ||
(!forceNew && !fromAfFile)
);
// If resuming and a model or system prompt was specified, apply those changes
if (isResumingAgent && (model || specifiedSystem)) {
if (model) {
const { updateAgentLLMConfig } = await import("./agent/modify");
const { resolveModel } = await import("./agent/model");
const modelHandle = resolveModel(model);
if (!modelHandle) {
console.error(`Error: Invalid model "${model}"`);
process.exit(1);
}
const updateArgs = getModelUpdateArgs(model);
await updateAgentLLMConfig(agent.id, modelHandle, updateArgs);
// Refresh agent state after model update
agent = await client.agents.retrieve(agent.id);
}
if (specifiedSystem) {
const { updateAgentSystemPrompt } = await import("./agent/modify");
const { SYSTEM_PROMPTS } = await import("./agent/promptAssets");
const systemPromptOption = SYSTEM_PROMPTS.find(
(p) => p.id === specifiedSystem,
);
if (!systemPromptOption) {
console.error(`Error: Invalid system prompt "${specifiedSystem}"`);
process.exit(1);
}
await updateAgentSystemPrompt(agent.id, systemPromptOption.content);
// Refresh agent state after system prompt update
agent = await client.agents.retrieve(agent.id);
}
}
// Save agent ID to both project and global settings
await settingsManager.loadLocalProjectSettings();
settingsManager.updateLocalProjectSettings({ lastAgent: agent.id });

View File

@@ -757,10 +757,56 @@ async function main() {
}
// Check if we're resuming an existing agent
// We're resuming if:
// 1. We specified an agent ID via --agent flag (agentIdArg)
// 2. We used --continue flag (continueSession)
// 3. We're reusing a project agent (detected early as resumingAgentId)
// 4. We retrieved an agent from LRU (detected by checking if agent already existed)
const isResumingProject = !forceNew && !!resumingAgentId;
const resuming = !!(continueSession || agentIdArg || isResumingProject);
const isReusingExistingAgent =
!forceNew && !fromAfFile && agent && agent.id;
const resuming = !!(
continueSession ||
agentIdArg ||
isResumingProject ||
isReusingExistingAgent
);
setIsResumingSession(resuming);
// If resuming and a model or system prompt was specified, apply those changes
if (resuming && (model || system)) {
if (model) {
const { updateAgentLLMConfig } = await import("./agent/modify");
const { getModelUpdateArgs, resolveModel } = await import(
"./agent/model"
);
const modelHandle = resolveModel(model);
if (!modelHandle) {
console.error(`Error: Invalid model "${model}"`);
process.exit(1);
}
const updateArgs = getModelUpdateArgs(model);
await updateAgentLLMConfig(agent.id, modelHandle, updateArgs);
// Refresh agent state after model update
agent = await client.agents.retrieve(agent.id);
}
if (system) {
const { updateAgentSystemPrompt } = await import("./agent/modify");
const { SYSTEM_PROMPTS } = await import("./agent/promptAssets");
const systemPromptOption = SYSTEM_PROMPTS.find(
(p) => p.id === system,
);
if (!systemPromptOption) {
console.error(`Error: Invalid system prompt "${system}"`);
process.exit(1);
}
await updateAgentSystemPrompt(agent.id, systemPromptOption.content);
// Refresh agent state after system prompt update
agent = await client.agents.retrieve(agent.id);
}
}
// Get resume data (pending approval + message history) if resuming
if (resuming) {
setLoadingState("checking");