fix: use single source of truth for agent name (#602)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
jnjpng
2026-01-20 12:00:37 -08:00
committed by GitHub
parent acc134027b
commit e6661e7699
2 changed files with 17 additions and 13 deletions

View File

@@ -567,6 +567,11 @@ export default function App({
const [agentId, setAgentId] = useState(initialAgentId);
const [agentState, setAgentState] = useState(initialAgentState);
// Helper to update agent name (updates agentState, which is the single source of truth)
const updateAgentName = useCallback((name: string) => {
setAgentState((prev) => (prev ? { ...prev, name } : prev));
}, []);
// Track current conversation (always created fresh on startup)
const [conversationId, setConversationId] = useState(initialConversationId);
@@ -902,7 +907,8 @@ export default function App({
llmConfigRef.current = llmConfig;
}, [llmConfig]);
const [currentModelId, setCurrentModelId] = useState<string | null>(null);
const [agentName, setAgentName] = useState<string | null>(null);
// Derive agentName from agentState (single source of truth)
const agentName = agentState?.name ?? null;
const [agentDescription, setAgentDescription] = useState<string | null>(null);
const [agentLastRunAt, setAgentLastRunAt] = useState<string | null>(null);
const currentModelLabel =
@@ -1527,8 +1533,8 @@ export default function App({
const { getClient } = await import("../agent/client");
const client = await getClient();
const agent = await client.agents.retrieve(agentId);
setAgentState(agent);
setLlmConfig(agent.llm_config);
setAgentName(agent.name);
setAgentDescription(agent.description ?? null);
// Get last message timestamp from agent state if available
const lastRunCompletion = (agent as { last_run_completion?: string })
@@ -1926,7 +1932,7 @@ export default function App({
}
// Also update agent state if other fields changed
setAgentName(agent.name);
setAgentState(agent);
setAgentDescription(agent.description ?? null);
const lastRunCompletion = (
agent as { last_run_completion?: string }
@@ -3284,7 +3290,6 @@ export default function App({
agentIdRef.current = targetAgentId;
setAgentId(targetAgentId);
setAgentState(agent);
setAgentName(agent.name);
setLlmConfig(agent.llm_config);
setConversationId(targetConversationId);
@@ -3376,7 +3381,6 @@ export default function App({
agentIdRef.current = agent.id;
setAgentId(agent.id);
setAgentState(agent);
setAgentName(agent.name);
setLlmConfig(agent.llm_config);
// Build success message with hints
@@ -4613,7 +4617,7 @@ export default function App({
try {
const client = await getClient();
await client.agents.update(agentId, { name: newName });
setAgentName(newName);
updateAgentName(newName);
buffersRef.current.byId.set(cmdId, {
kind: "command",
@@ -4916,7 +4920,7 @@ export default function App({
agentId,
agentName: agentName || "",
setCommandRunning,
setAgentName,
updateAgentName,
};
// /profile - open agent browser (now points to /agents)
@@ -5012,7 +5016,7 @@ export default function App({
agentId,
agentName: agentName || "",
setCommandRunning,
setAgentName,
updateAgentName,
};
await handlePin(profileCtx, msg, argsStr);
return { submitted: true };
@@ -5026,7 +5030,7 @@ export default function App({
agentId,
agentName: agentName || "",
setCommandRunning,
setAgentName,
updateAgentName,
};
const argsStr = msg.trim().slice(6).trim();
handleUnpin(profileCtx, msg, argsStr);
@@ -8476,7 +8480,7 @@ Plan file path: ${planFilePath}`;
// Rename if new name provided
if (newName && newName !== agentName) {
await client.agents.update(agentId, { name: newName });
setAgentName(newName);
updateAgentName(newName);
}
// Pin the agent

View File

@@ -21,7 +21,7 @@ export interface ProfileCommandContext {
agentId: string;
agentName: string;
setCommandRunning: (running: boolean) => void;
setAgentName: (name: string) => void;
updateAgentName: (name: string) => void;
}
// Helper to add a command result to buffers
@@ -163,7 +163,7 @@ export async function handleProfileSave(
const client = await getClient();
// Update agent name via API
await client.agents.update(ctx.agentId, { name: profileName });
ctx.setAgentName(profileName);
ctx.updateAgentName(profileName);
// Save profile to BOTH local and global settings
settingsManager.saveProfile(profileName, ctx.agentId);
@@ -332,7 +332,7 @@ export async function handlePin(
const { getClient } = await import("../../agent/client");
const client = await getClient();
await client.agents.update(ctx.agentId, { name });
ctx.setAgentName(name);
ctx.updateAgentName(name);
} catch (error) {
addCommandResult(
ctx.buffersRef,