fix: Model flag parsing and model args (#42)
This commit is contained in:
@@ -7,7 +7,6 @@ import type {
|
||||
Block,
|
||||
CreateBlock,
|
||||
} from "@letta-ai/letta-client/resources/agents/agents";
|
||||
import { formatAvailableModels, resolveModel } from "../model";
|
||||
import {
|
||||
loadProjectSettings,
|
||||
updateProjectSettings,
|
||||
@@ -16,12 +15,15 @@ import { loadSettings, updateSettings } from "../settings";
|
||||
import { getToolNames } from "../tools/manager";
|
||||
import { getClient } from "./client";
|
||||
import { getDefaultMemoryBlocks } from "./memory";
|
||||
import { formatAvailableModels, resolveModel } from "./model";
|
||||
import { updateAgentLLMConfig } from "./modify";
|
||||
import { SYSTEM_PROMPT } from "./promptAssets";
|
||||
|
||||
export async function createAgent(
|
||||
name = "letta-cli-agent",
|
||||
model?: string,
|
||||
embeddingModel = "openai/text-embedding-3-small",
|
||||
updateArgs?: Record<string, unknown>,
|
||||
) {
|
||||
// Resolve model identifier to handle
|
||||
let modelHandle: string;
|
||||
@@ -168,5 +170,13 @@ export async function createAgent(
|
||||
include_base_tool_rules: false,
|
||||
initial_message_sequence: [],
|
||||
});
|
||||
|
||||
// Apply updateArgs if provided (e.g., reasoningEffort, contextWindow, etc.)
|
||||
if (updateArgs && Object.keys(updateArgs).length > 0) {
|
||||
await updateAgentLLMConfig(agent.id, modelHandle, updateArgs);
|
||||
// Refresh agent state to get updated config
|
||||
return await client.agents.retrieve(agent.id);
|
||||
}
|
||||
|
||||
return agent; // { id, ... }
|
||||
}
|
||||
|
||||
64
src/agent/model.ts
Normal file
64
src/agent/model.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Model resolution and handling utilities
|
||||
*/
|
||||
import modelsData from "../models.json";
|
||||
|
||||
export const models = modelsData;
|
||||
|
||||
/**
|
||||
* Resolve a model by ID or handle
|
||||
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
||||
* @returns The model handle if found, null otherwise
|
||||
*/
|
||||
export function resolveModel(modelIdentifier: string): string | null {
|
||||
const byId = models.find((m) => m.id === modelIdentifier);
|
||||
if (byId) return byId.handle;
|
||||
|
||||
const byHandle = models.find((m) => m.handle === modelIdentifier);
|
||||
if (byHandle) return byHandle.handle;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default model handle
|
||||
*/
|
||||
export function getDefaultModel(): string {
|
||||
const defaultModel = models.find((m) => m.isDefault);
|
||||
return defaultModel?.handle || models[0].handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format available models for error messages
|
||||
*/
|
||||
export function formatAvailableModels(): string {
|
||||
return models.map((m) => ` ${m.id.padEnd(20)} ${m.handle}`).join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get model info by ID or handle
|
||||
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
||||
* @returns The model info if found, null otherwise
|
||||
*/
|
||||
export function getModelInfo(modelIdentifier: string) {
|
||||
const byId = models.find((m) => m.id === modelIdentifier);
|
||||
if (byId) return byId;
|
||||
|
||||
const byHandle = models.find((m) => m.handle === modelIdentifier);
|
||||
if (byHandle) return byHandle;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updateArgs for a model by ID or handle
|
||||
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
|
||||
* @returns The updateArgs if found, undefined otherwise
|
||||
*/
|
||||
export function getModelUpdateArgs(
|
||||
modelIdentifier?: string,
|
||||
): Record<string, unknown> | undefined {
|
||||
if (!modelIdentifier) return undefined;
|
||||
const modelInfo = getModelInfo(modelIdentifier);
|
||||
return modelInfo?.updateArgs;
|
||||
}
|
||||
Reference in New Issue
Block a user