diff --git a/src/headless.ts b/src/headless.ts index 018e4b0..fed441c 100644 --- a/src/headless.ts +++ b/src/headless.ts @@ -259,17 +259,25 @@ export async function handleHeadlessCommand( // 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); + + // Optimization: Skip update if agent is already using the specified model + const currentModel = agent.llm_config?.model; + const currentEndpointType = agent.llm_config?.model_endpoint_type; + const currentHandle = `${currentEndpointType}/${currentModel}`; + + if (currentHandle !== modelHandle) { + const { updateAgentLLMConfig } = await import("./agent/modify"); + 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) { diff --git a/src/index.ts b/src/index.ts index 6ee5b2d..609e68f 100755 --- a/src/index.ts +++ b/src/index.ts @@ -200,6 +200,13 @@ async function main() { const fromAfFile = values["from-af"] as string | undefined; const isHeadless = values.prompt || values.run || !process.stdin.isTTY; + // Fail if an unknown command/argument is passed (and we're not in headless mode where it might be a prompt) + if (command && !isHeadless) { + console.error(`Error: Unknown command or argument "${command}"`); + console.error("Run 'letta --help' for usage information."); + process.exit(1); + } + // --init-blocks only makes sense when creating a brand new agent if (initBlocksRaw && !forceNew) { console.error( @@ -785,19 +792,26 @@ async function main() { // 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 { 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); + + // Optimization: Skip update if agent is already using the specified model + const currentModel = agent.llm_config?.model; + const currentEndpointType = agent.llm_config?.model_endpoint_type; + const currentHandle = `${currentEndpointType}/${currentModel}`; + + if (currentHandle !== modelHandle) { + const { updateAgentLLMConfig } = await import("./agent/modify"); + const { getModelUpdateArgs } = await import("./agent/model"); + 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) {