chore: allow renaming agent (#83)

Co-authored-by: Shubham Naik <shub@memgpt.ai>
This commit is contained in:
Shubham Naik
2025-11-07 20:48:12 -08:00
committed by GitHub
parent d762859963
commit eab04aaee3
5 changed files with 90 additions and 2 deletions

View File

@@ -174,6 +174,7 @@ export default function App({
// Model selector state
const [modelSelectorOpen, setModelSelectorOpen] = useState(false);
const [llmConfig, setLlmConfig] = useState<LlmConfig | null>(null);
const [agentName, setAgentName] = useState<string | null>(null);
// Token streaming preference (can be toggled at runtime)
const [tokenStreamingEnabled, setTokenStreamingEnabled] =
@@ -397,8 +398,9 @@ export default function App({
const client = await getClient();
const agent = await client.agents.retrieve(agentId);
setLlmConfig(agent.llm_config);
setAgentName(agent.name);
} catch (error) {
console.error("Error fetching llm_config:", error);
console.error("Error fetching agent config:", error);
}
};
fetchConfig();
@@ -1014,6 +1016,69 @@ export default function App({
return { submitted: true };
}
// Special handling for /rename command - rename the agent
if (msg.trim().startsWith("/rename")) {
const parts = msg.trim().split(/\s+/);
const newName = parts.slice(1).join(" ");
if (!newName) {
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: "Please provide a new name: /rename <name>",
phase: "finished",
success: false,
});
buffersRef.current.order.push(cmdId);
refreshDerived();
return { submitted: true };
}
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `Renaming agent to "${newName}"...`,
phase: "running",
});
buffersRef.current.order.push(cmdId);
refreshDerived();
setCommandRunning(true);
try {
const client = await getClient();
await client.agents.modify(agentId, { name: newName });
setAgentName(newName);
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `Agent renamed to "${newName}"`,
phase: "finished",
success: true,
});
refreshDerived();
} catch (error) {
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: msg,
output: `Failed: ${error instanceof Error ? error.message : String(error)}`,
phase: "finished",
success: false,
});
refreshDerived();
} finally {
setCommandRunning(false);
}
return { submitted: true };
}
// Immediately add command to transcript with "running" phase
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
@@ -1662,6 +1727,7 @@ export default function App({
onInterrupt={handleInterrupt}
interruptRequested={interruptRequested}
agentId={agentId}
agentName={agentName}
/>
{/* Model Selector - conditionally mounted as overlay */}