Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: Chatui agent dropdown fields (#899)

Adam505c0e92d8dd
diff --git a/chatui/README.md b/chatui/README.md
index 6501e30a8..3eefccf6d 100644
--- a/chatui/README.md
+++ b/chatui/README.md
@@ -7,6 +7,7 @@ Running the Chat UI requires starting both the MemGPT API server, and the MemGPT
Before attempting to run the MemGPT API server, make sure you have `memgpt` installed and have been able to run basic `memgpt` commands (e.g. `memgpt run`). See installation instructions here: https://memgpt.readme.io/docs/quickstart.
Once you have MemGPT installed and running correctly, you can start the server with:
+
```sh
memgpt server
```
@@ -18,6 +19,7 @@ Once the API server is running, you can launch the Chat UI web app (which will c
If you don't already have Node.js installed, follow the installation instructions here: https://nodejs.org/en.
Then, in your terminal navigate to the `chatui` directory in the MemGPT project, and run:
+
```sh
npx nx serve
```
diff --git a/chatui/src/app/libs/humans/human.ts b/chatui/src/app/libs/humans/human.ts
new file mode 100644
index 000000000..c20bc8cd9
--- /dev/null
+++ b/chatui/src/app/libs/humans/human.ts
@@ -0,0 +1,8 @@
+import { z } from 'zod';
+
+export const HumanSchema = z.object({
+ name: z.string(),
+ text: z.string(),
+});
+
+export type Human = z.infer<typeof HumanSchema>;
diff --git a/chatui/src/app/libs/humans/use-humans.query.ts b/chatui/src/app/libs/humans/use-humans.query.ts
new file mode 100644
index 000000000..67542989a
--- /dev/null
+++ b/chatui/src/app/libs/humans/use-humans.query.ts
@@ -0,0 +1,18 @@
+import { useQuery } from '@tanstack/react-query';
+import { API_BASE_URL } from '../constants';
+import { Human } from './human';
+
+export const useHumansQuery = (userId: string | null | undefined) =>
+ useQuery({
+ queryKey: [userId, 'humans', 'list'],
+ enabled: !!userId,
+ queryFn: async () => {
+ const response = await fetch(`${API_BASE_URL}/humans?user_id=${encodeURIComponent(userId || '')}`);
+ if (!response.ok) {
+ throw new Error('Network response was not ok for fetching humans');
+ }
+ return (await response.json()) as Promise<{
+ humans: Human[];
+ }>;
+ },
+ });
diff --git a/chatui/src/app/libs/models/model.ts b/chatui/src/app/libs/models/model.ts
new file mode 100644
index 000000000..02d9e14bc
--- /dev/null
+++ b/chatui/src/app/libs/models/model.ts
@@ -0,0 +1,11 @@
+import { z } from 'zod';
+
+export const ModelSchema = z.object({
+ name: z.string(),
+ endpoint: z.string(),
+ endpoint_type: z.string(),
+ wrapper: z.string().optional(),
+ context_window: z.number(),
+});
+
+export type Model = z.infer<typeof ModelSchema>;
diff --git a/chatui/src/app/libs/models/use-models.query.ts b/chatui/src/app/libs/models/use-models.query.ts
new file mode 100644
index 000000000..454163330
--- /dev/null
+++ b/chatui/src/app/libs/models/use-models.query.ts
@@ -0,0 +1,18 @@
+import { useQuery } from '@tanstack/react-query';
+import { API_BASE_URL } from '../constants';
+import { Model } from './model';
+
+export const useModelsQuery = (userId: string | null | undefined) =>
+ useQuery({
+ queryKey: [userId, 'models', 'list'],
+ enabled: !!userId,
+ queryFn: async () => {
+ const response = await fetch(`${API_BASE_URL}/models?user_id=${encodeURIComponent(userId || '')}`);
+ if (!response.ok) {
+ throw new Error('Network response was not ok for fetching models');
+ }
+ return (await response.json()) as Promise<{
+ models: Model[];
+ }>;
+ },
+ });
diff --git a/chatui/src/app/libs/personas/persona.ts b/chatui/src/app/libs/personas/persona.ts
new file mode 100644
index 000000000..382a283ff
--- /dev/null
+++ b/chatui/src/app/libs/personas/persona.ts
@@ -0,0 +1,8 @@
+import { z } from 'zod';
+
+export const PersonaSchema = z.object({
+ name: z.string(),
+ text: z.string(),
+});
+
+export type Persona = z.infer<typeof PersonaSchema>;
diff --git a/chatui/src/app/libs/personas/use-personas.query.ts b/chatui/src/app/libs/personas/use-personas.query.ts
new file mode 100644
index 000000000..4acf5366d
--- /dev/null
+++ b/chatui/src/app/libs/personas/use-personas.query.ts
@@ -0,0 +1,18 @@
+import { useQuery } from '@tanstack/react-query';
+import { API_BASE_URL } from '../constants';
+import { Persona } from './persona';
+
+export const usePersonasQuery = (userId: string | null | undefined) =>
+ useQuery({
+ queryKey: [userId, 'personas', 'list'],
+ enabled: !!userId, // The query will not execute unless userId is truthy
+ queryFn: async () => {
+ const response = await fetch(`${API_BASE_URL}/personas?user_id=${encodeURIComponent(userId || '')}`);
+ if (!response.ok) {
+ throw new Error('Network response was not ok');
+ }
+ return (await response.json()) as Promise<{
+ personas: Persona[];
+ }>;
+ },
+ });
diff --git a/chatui/src/app/modules/home/create-agent-dialog.tsx b/chatui/src/app/modules/home/create-agent-dialog.tsx
index 9a421f86c..c7360ef48 100644
--- a/chatui/src/app/modules/home/create-agent-dialog.tsx
+++ b/chatui/src/app/modules/home/create-agent-dialog.tsx
@@ -9,35 +9,60 @@ import {
} from '@memgpt/components/dialog';
import { Input } from '@memgpt/components/input';
import { Label } from '@memgpt/components/label';
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@memgpt/components/select';
import { Loader2 } from 'lucide-react';
+import { Controller, useForm } from 'react-hook-form';
import { useAgentsCreateMutation } from '../../libs/agents/use-agents.mutation';
import { useAuthStoreState } from '../../libs/auth/auth.store';
+import { useHumansQuery } from '../../libs/humans/use-humans.query';
+import { useModelsQuery } from '../../libs/models/use-models.query';
+import { usePersonasQuery } from '../../libs/personas/use-personas.query';
+
+interface FormData {
+ name: string;
+ human: string;
+ persona: string;
+ model: string;
+}
const CreateAgentDialog = (props: { open: boolean; onOpenChange: (open: boolean) => void }) => {
const auth = useAuthStoreState();
const createAgent = useAgentsCreateMutation(auth.uuid);
+
+ const { register, handleSubmit, control } = useForm<FormData>({
+ defaultValues: {
+ name: 'James Bond',
+ human: 'cs_phd',
+ persona: 'sam_pov',
+ model: 'gpt-4',
+ },
+ });
+
+ // Fetch models, humans, and personas using the custom hooks
+ const { data: modelsData } = useModelsQuery(auth.uuid);
+ const { data: humansData } = useHumansQuery(auth.uuid);
+ const { data: personasData } = usePersonasQuery(auth.uuid);
+
+ const onSubmit = (data: FormData) => {
+ if (!auth.uuid) return;
+ // The data parameter already contains the values from the form
+ createAgent.mutate(
+ {
+ name: data.name,
+ human: data.human,
+ persona: data.persona,
+ model: data.model,
+ },
+ {
+ onSuccess: () => props.onOpenChange(false),
+ }
+ );
+ };
+
return (
<Dialog open={props.open} onOpenChange={props.onOpenChange}>
<DialogContent className="sm:max-w-[425px]">
- <form
- onSubmit={(event) => {
- event.preventDefault();
- if (!auth.uuid) return;
- const formData = new FormData(event.currentTarget);
- // ✅ mutation is invoked when the form is submitted
- createAgent.mutate(
- {
- name: `${formData.get('name')}`,
- human: `${formData.get('human')}`,
- persona: `${formData.get('persona')}`,
- model: `${formData.get('model')}`,
- },
- {
- onSuccess: () => props.onOpenChange(false),
- }
- );
- }}
- >
+ <form onSubmit={handleSubmit(onSubmit)}>
<DialogHeader>
<DialogTitle>Create Agent</DialogTitle>
<DialogDescription>Add a new agent here. Click create when you're done.</DialogDescription>
@@ -47,25 +72,76 @@ const CreateAgentDialog = (props: { open: boolean; onOpenChange: (open: boolean)
<Label htmlFor="name" className="text-right">
Name
</Label>
- <Input id="name" name="name" defaultValue="James Bond" className="col-span-3" />
+ <Input id="name" {...register('name')} className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="human" className="text-right">
Human
</Label>
- <Input id="human" name="human" defaultValue="cs_phd" className="col-span-3" />
+ <Controller
+ name="human"
+ control={control}
+ render={({ field: { onChange, value } }) => (
+ <Select value={value} onValueChange={(val) => onChange(val)}>
+ <SelectTrigger className="col-span-3">
+ <SelectValue placeholder="Select a human">{value}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ {humansData?.humans.map((human) => (
+ <SelectItem key={human.name} value={human.name}>
+ {human.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
+ />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="persona" className="text-right">
Persona
</Label>
- <Input id="persona" name="persona" defaultValue="sam_pov" className="col-span-3" />
+ <Controller
+ name="persona"
+ control={control}
+ render={({ field: { onChange, value } }) => (
+ <Select value={value} onValueChange={(val) => onChange(val)}>
+ <SelectTrigger className="col-span-3">
+ <SelectValue placeholder="Select a persona">{value}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ {personasData?.personas.map((persona) => (
+ <SelectItem key={persona.name} value={persona.name}>
+ {persona.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
+ />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="model" className="text-right">
Model
</Label>
- <Input id="model" name="model" defaultValue="gpt-4" className="col-span-3" />
+ <Controller
+ name="model"
+ control={control}
+ render={({ field: { onChange, value } }) => (
+ <Select value={value} onValueChange={(val) => onChange(val)}>
+ <SelectTrigger className="col-span-3">
+ <SelectValue placeholder="Select a model">{value}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ {modelsData?.models.map((model) => (
+ <SelectItem key={model.name} value={model.name}>
+ {model.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
+ />
</div>
</div>
<DialogFooter>
diff --git a/memgpt/server/rest_api/humans/__init__.py b/memgpt/server/rest_api/humans/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/memgpt/server/rest_api/humans/index.py b/memgpt/server/rest_api/humans/index.py
new file mode 100644
index 000000000..2cec1276c
--- /dev/null
+++ b/memgpt/server/rest_api/humans/index.py
@@ -0,0 +1,35 @@
+import uuid
+from typing import List
+from fastapi import APIRouter, Query
+from pydantic import BaseModel, Field
+
+from memgpt.server.server import SyncServer
+from memgpt.server.rest_api.interface import QueuingInterface
+
+router = APIRouter()
+
+
+class ListHumansResponse(BaseModel):
+ humans: List[dict] = Field(..., description="List of human configurations.")
+
+
+def setup_humans_index_router(server: SyncServer, interface: QueuingInterface):
+ @router.get("/humans", tags=["humans"], response_model=ListHumansResponse)
+ async def list_humans(user_id: str = Query(..., description="Unique identifier of the user.")):
+ # Validate and parse the user ID
+ user_id = None if user_id == "null" else user_id
+ user_id = uuid.UUID(user_id) if user_id else None
+
+ # Clear the interface
+ interface.clear()
+
+ # TODO: Replace with actual data fetching logic once available
+ humans_data = [
+ {"name": "Marco", "text": "About Me"},
+ {"name": "Sam", "text": "About Me 2"},
+ {"name": "Bruce", "text": "About Me 3"},
+ ]
+
+ return ListHumansResponse(humans=humans_data)
+
+ return router
diff --git a/memgpt/server/rest_api/models/__init__.py b/memgpt/server/rest_api/models/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/memgpt/server/rest_api/models/index.py b/memgpt/server/rest_api/models/index.py
new file mode 100644
index 000000000..9027d69df
--- /dev/null
+++ b/memgpt/server/rest_api/models/index.py
@@ -0,0 +1,48 @@
+import uuid
+from typing import List
+from fastapi import APIRouter, Query
+from pydantic import BaseModel, Field
+
+from memgpt.server.server import SyncServer
+from memgpt.server.rest_api.interface import QueuingInterface
+
+router = APIRouter()
+
+
+class Model(BaseModel):
+ name: str = Field(..., description="The name of the model.")
+ endpoint: str = Field(..., description="Endpoint URL for the model.")
+ endpoint_type: str = Field(..., description="Type of the model endpoint.")
+ wrapper: str = Field(None, description="Wrapper used for the model.")
+ context_window: int = Field(..., description="Context window size for the model.")
+
+
+class ListModelsResponse(BaseModel):
+ models: List[Model] = Field(..., description="List of model configurations.")
+
+
+def setup_models_index_router(server: SyncServer, interface: QueuingInterface):
+ @router.get("/models", tags=["models"], response_model=ListModelsResponse)
+ async def list_models(user_id: str = Query(..., description="Unique identifier of the user.")):
+ # Validate and parse the user ID
+ user_id = None if user_id == "null" else user_id
+ user_id = uuid.UUID(user_id) if user_id else None
+
+ # Clear the interface
+ interface.clear()
+
+ # TODO: Replace with actual data fetching logic once available
+ models_data = [
+ Model(
+ name="ehartford/dolphin-2.5-mixtral-8x7b",
+ endpoint="https://api.memgpt.ai",
+ endpoint_type="vllm",
+ wrapper="chatml",
+ context_window=16384,
+ ),
+ Model(name="gpt-4", endpoint="https://api.openai.com/v1", endpoint_type="openai", context_window=8192),
+ ]
+
+ return ListModelsResponse(models=models_data)
+
+ return router
diff --git a/memgpt/server/rest_api/personas/__init__.py b/memgpt/server/rest_api/personas/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/memgpt/server/rest_api/personas/index.py b/memgpt/server/rest_api/personas/index.py
new file mode 100644
index 000000000..87b266a26
--- /dev/null
+++ b/memgpt/server/rest_api/personas/index.py
@@ -0,0 +1,35 @@
+import uuid
+from typing import List
+from fastapi import APIRouter, Query
+from pydantic import BaseModel, Field
+
+from memgpt.server.server import SyncServer
+from memgpt.server.rest_api.interface import QueuingInterface
+
+router = APIRouter()
+
+
+class ListPersonasResponse(BaseModel):
+ personas: List[dict] = Field(..., description="List of persona configurations.")
+
+
+def setup_personas_index_router(server: SyncServer, interface: QueuingInterface):
+ @router.get("/personas", tags=["personas"], response_model=ListPersonasResponse)
+ async def list_personas(user_id: str = Query(..., description="Unique identifier of the user.")):
+ # Validate and parse the user ID
+ user_id = None if user_id == "null" else user_id
+ user_id = uuid.UUID(user_id) if user_id else None
+
+ # Clear the interface
+ interface.clear()
+
+ # TODO: Replace with actual data fetching logic once available
+ personas_data = [
+ {"name": "Persona 1", "text": "Details about Persona 1"},
+ {"name": "Persona 2", "text": "Details about Persona 2"},
+ {"name": "Persona 3", "text": "Details about Persona 3"},
+ ]
+
+ return ListPersonasResponse(personas=personas_data)
+
+ return router
diff --git a/memgpt/server/rest_api/server.py b/memgpt/server/rest_api/server.py
index f717e2963..9552e32e9 100644
--- a/memgpt/server/rest_api/server.py
+++ b/memgpt/server/rest_api/server.py
@@ -13,6 +13,9 @@ from memgpt.server.rest_api.agents.memory import setup_agents_memory_router
from memgpt.server.rest_api.agents.message import setup_agents_message_router
from memgpt.server.rest_api.auth.index import setup_auth_router
from memgpt.server.rest_api.config.index import setup_config_index_router
+from memgpt.server.rest_api.humans.index import setup_humans_index_router
+from memgpt.server.rest_api.personas.index import setup_personas_index_router
+from memgpt.server.rest_api.models.index import setup_models_index_router
from memgpt.server.server import SyncServer
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.rest_api.static_files import mount_static_files
@@ -57,6 +60,9 @@ app.include_router(setup_agents_config_router(server, interface), prefix=API_PRE
app.include_router(setup_agents_index_router(server, interface), prefix=API_PREFIX)
app.include_router(setup_agents_memory_router(server, interface), prefix=API_PREFIX)
app.include_router(setup_agents_message_router(server, interface), prefix=API_PREFIX)
+app.include_router(setup_humans_index_router(server, interface), prefix=API_PREFIX)
+app.include_router(setup_personas_index_router(server, interface), prefix=API_PREFIX)
+app.include_router(setup_models_index_router(server, interface), prefix=API_PREFIX)
# /api/config endpoints
app.include_router(setup_config_index_router(server, interface), prefix=API_PREFIX)
# / static files