AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(frontend): show what an expert has learned in its Soul drawer (#14505)
Reinier van der Leer69b550ae0e79
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/memory/__tests__/main.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/memory/__tests__/main.test.tsxindex 41f6f01dde..11f2765a77 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/memory/__tests__/main.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/memory/__tests__/main.test.tsx@@ -108,6 +108,7 @@ function mockHappyPath() {beforeEach(() => {resetCopilotChatRegistry();+ window.history.replaceState({}, "", "/settings/memory");});describe("Settings memory page", () => {@@ -254,6 +255,77 @@ describe("Settings memory page", () => {expect(screen.getByText(/Erase Maria's memory/)).toBeDefined();});+ it("opens on an expert's scope when linked with ?expert=", async () => {+ const maria = {+ ...getListExpertsResponseMock200()[0],+ id: "expert-maria",+ name: "Maria",+ role: "Growth Marketer",+ avatar_url: null,+ is_archived: false,+ };+ const expertFactRequests: string[] = [];+ server.use(+ getListExpertsMockHandler200([maria]),+ getListMyMemoryFactsMockHandler200(FACTS),+ getGetMyExpertMemoryOverviewMockHandler200({+ expert_id: "expert-maria",+ facts: 12,+ entities: 8,+ episodes: 3,+ }),+ getListMyExpertMemoryFactsMockHandler200((info) => {+ expertFactRequests.push(String(info.params.expertId));+ return {+ expert_id: "expert-maria",+ items: [+ {+ uuid: "edge-m1",+ fact: "Q4 campaign brief is due Friday",+ name: "due",+ source: "Campaign",+ target: "Friday",+ created_at: "2026-08-17T00:00:00Z",+ },+ ],+ };+ }),+ );+ window.history.replaceState({}, "", "/settings/memory?expert=expert-maria");++ render(<SettingsMemoryPage />);++ expect(+ await screen.findByText("Q4 campaign brief is due Friday"),+ ).toBeDefined();+ expect(expertFactRequests).toEqual(["expert-maria"]);+ expect(screen.getByText(/Erase Maria's memory/)).toBeDefined();+ });++ it.each([+ ["an expert the caller no longer has", "expert-gone"],+ ["an empty value", ""],+ ])(+ "falls back to AutoPilot when ?expert= is %s",+ async (_case, expertParam) => {+ mockHappyPath();+ window.history.replaceState(+ {},+ "",+ `/settings/memory?expert=${expertParam}`,+ );++ render(<SettingsMemoryPage />);++ expect(+ await screen.findByText("Runs a DTC candle brand called Emberline"),+ ).toBeDefined();+ expect(+ screen.getByRole("button", { name: "View my summary" }),+ ).toBeDefined();+ },+ );+it("opens the summary chat in-pane and auto-sends the seeded prompt", async () => {mockHappyPath();const createBodies: unknown[] = [];diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/memory/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/settings/memory/helpers.tsindex 4132a146c5..287e8c7746 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/memory/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/settings/memory/helpers.ts@@ -34,3 +34,10 @@ export function formatWhen(createdAt: string | null | undefined) {if (Number.isNaN(parsed.getTime())) return "";return formatDistanceToNow(parsed, { addSuffix: true });}++/** The Soul drawer links here with ?expert=<id>. An id the caller no longer+ * owns is left to the page's active-expert fallback rather than checked here. */+export function readExpertScopeFromUrl() {+ if (typeof window === "undefined") return null;+ return new URLSearchParams(window.location.search).get("expert") || null;+}diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/memory/useMemoryPage.ts b/autogpt_platform/frontend/src/app/(platform)/settings/memory/useMemoryPage.tsindex ef2252f963..c3b15e7e00 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/memory/useMemoryPage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/settings/memory/useMemoryPage.ts@@ -16,10 +16,19 @@ import { useListExperts } from "@/app/api/__generated__/endpoints/experts/expertimport { toast } from "@/components/molecules/Toast/use-toast";import { useQueryClient } from "@tanstack/react-query";import { useEffect, useState } from "react";-import { getActiveExperts, getScopeName, RECENT_FACTS_LIMIT } from "./helpers";+import {+ getActiveExperts,+ getScopeName,+ readExpertScopeFromUrl,+ RECENT_FACTS_LIMIT,+} from "./helpers";export function useMemoryPage() {- const [scopeExpertID, setScopeExpertID] = useState<string | null>(null);+ // The Soul drawer's learned-notes panel links here with ?expert=<id>, so+ // the link opens on that expert. Read once — the dropdown owns it after.+ const [scopeExpertID, setScopeExpertID] = useState<string | null>(+ readExpertScopeFromUrl,+ );const queryClient = useQueryClient();// Deliberately not gated on HIRE_EXPERTS: expert memory scopes must staydiff --git a/autogpt_platform/frontend/src/app/(platform)/team/__tests__/soul-learned-notes.test.tsx b/autogpt_platform/frontend/src/app/(platform)/team/__tests__/soul-learned-notes.test.tsxnew file mode 100644index 0000000000..c6acc68fbd--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/team/__tests__/soul-learned-notes.test.tsx@@ -0,0 +1,246 @@+import {+ getListExpertCredentialsMockHandler,+ getListExpertPodsMockHandler,+ getListExpertsMockHandler,+ getUpdateExpertSoulMockHandler,+} from "@/app/api/__generated__/endpoints/experts/experts.msw";+import { getGetV2ListLibraryAgentsMockHandler200 } from "@/app/api/__generated__/endpoints/library/library.msw";+import {+ getForgetMyExpertMemoryFactMockHandler200,+ getListMyExpertMemoryFactsMockHandler,+ getListMyExpertMemoryFactsMockHandler200,+} from "@/app/api/__generated__/endpoints/memory/memory.msw";+import { getGetV1ListExecutionSchedulesForAUserMockHandler } from "@/app/api/__generated__/endpoints/schedules/schedules.msw";+import { Expert } from "@/app/api/__generated__/models/expert";+import { MemoryFact } from "@/app/api/__generated__/models/memoryFact";+import { server } from "@/mocks/mock-server";+import { render, screen, waitFor } from "@/tests/integrations/test-utils";+import userEvent from "@testing-library/user-event";+import { http, HttpResponse } from "msw";+import { beforeEach, describe, expect, test, vi } from "vitest";+import TeamPage from "../page";++const { memoryFlagMock } = vi.hoisted(() => ({+ memoryFlagMock: vi.fn(() => true),+}));++vi.mock("@/services/feature-flags/use-get-flag", async (importOriginal) => {+ const actual =+ await importOriginal<+ typeof import("@/services/feature-flags/use-get-flag")+ >();+ return {+ ...actual,+ useGetFlag: (flag: string) =>+ flag === "graphiti-memory"+ ? memoryFlagMock()+ : actual.useGetFlag(flag as never),+ useFlagStatus: (flag: string) =>+ flag === "hire-experts"+ ? { enabled: true, ready: true }+ : actual.useFlagStatus(flag as never),+ };+});++vi.mock("next/navigation", () => ({+ useRouter: () => ({+ push: vi.fn(),+ replace: vi.fn(),+ prefetch: vi.fn(),+ back: vi.fn(),+ forward: vi.fn(),+ refresh: vi.fn(),+ }),+ usePathname: () => "/team",+ useSearchParams: () => new URLSearchParams(),+ useParams: () => ({}),+ notFound: vi.fn(),+}));++const maria: Expert = {+ id: "expert-maria",+ name: "Maria",+ avatar_url: null,+ role: "Marketing Strategist",+ bio: null,+ skills: [],+ tagline: "Grows your brand while you sleep",+ identity: "You are Maria.",+ voice_preferences: "",+ boundaries: "",+ protected_soul_rules: [],+ is_template: false,+ source_template_id: "template-maria",+ is_archived: false,+ workflows: [],+};++function makeFact(over: Partial<MemoryFact> = {}): MemoryFact {+ return {+ uuid: "edge-1",+ fact: "Q4 campaign brief is due Friday",+ name: "due",+ source: "Campaign",+ target: "Friday",+ created_at: "2026-08-17T00:00:00Z",+ ...over,+ } as MemoryFact;+}++async function openSoulDrawer() {+ const user = userEvent.setup();+ render(<TeamPage />);+ await user.click(await screen.findByRole("button", { name: "Edit Soul" }));+ return user;+}++beforeEach(() => {+ memoryFlagMock.mockReturnValue(true);+ server.use(+ getGetV1ListExecutionSchedulesForAUserMockHandler([]),+ getListExpertPodsMockHandler([]),+ getListExpertCredentialsMockHandler([]),+ getGetV2ListLibraryAgentsMockHandler200(),+ getListExpertsMockHandler([maria]),+ );+});++describe("Soul drawer — what I've learned", () => {+ test("lists the expert's own memories, newest first, with a link to the rest", async () => {+ const factRequests: string[] = [];+ server.use(+ getListMyExpertMemoryFactsMockHandler(async (info) => {+ factRequests.push(String(info.params.expertId));+ return {+ expert_id: "expert-maria",+ items: [+ makeFact(),+ makeFact({+ uuid: "edge-2",+ fact: "Emberline ships to the EU only",+ created_at: "2026-08-16T00:00:00Z",+ }),+ ],+ };+ }),+ );++ await openSoulDrawer();++ expect(+ await screen.findByText("Q4 campaign brief is due Friday"),+ ).toBeDefined();+ expect(screen.getByText("Emberline ships to the EU only")).toBeDefined();+ expect(screen.queryByText(/Nothing recorded yet/)).toBeNull();++ // Scoped to this expert, and only this expert.+ expect(factRequests).toEqual(["expert-maria"]);++ const seeAll = screen.getByRole("link", {+ name: "See all in memory settings",+ });+ expect(seeAll.getAttribute("href")).toBe(+ "/settings/memory?expert=expert-maria",+ );+ });++ test("keeps the empty state for an expert that has learned nothing", async () => {+ server.use(+ getListMyExpertMemoryFactsMockHandler200({+ expert_id: "expert-maria",+ items: [],+ }),+ );++ await openSoulDrawer();++ expect(+ await screen.findByText(+ "Nothing recorded yet. What this expert learns will appear here.",+ ),+ ).toBeDefined();+ expect(+ screen.queryByRole("link", { name: "See all in memory settings" }),+ ).toBeNull();+ });++ test("forgetting a memory calls the scoped delete, refetches, and leaves the Soul unsaved", async () => {+ const forgotten: string[] = [];+ const soulSaves: unknown[] = [];+ let listCalls = 0;+ server.use(+ getListMyExpertMemoryFactsMockHandler(async () => {+ listCalls += 1;+ return {+ expert_id: "expert-maria",+ items: forgotten.length ? [] : [makeFact()],+ };+ }),+ getForgetMyExpertMemoryFactMockHandler200(async (info) => {+ forgotten.push(String(info.params.factUuid));+ return { uuid: String(info.params.factUuid), forgotten: true };+ }),+ getUpdateExpertSoulMockHandler(async ({ request }) => {+ soulSaves.push(await request.json());+ return maria;+ }),+ );++ const user = await openSoulDrawer();++ await screen.findByText("Q4 campaign brief is due Friday");+ const callsBeforeForget = listCalls;+ await user.click(screen.getByRole("button", { name: "Forget" }));++ await waitFor(() => expect(forgotten).toEqual(["edge-1"]));+ await waitFor(() => expect(listCalls).toBeGreaterThan(callsBeforeForget));+ await waitFor(() =>+ expect(+ screen.getByText(+ "Nothing recorded yet. What this expert learns will appear here.",+ ),+ ).toBeDefined(),+ );+ // Forget sits inside the Soul form; it must not submit it.+ expect(soulSaves).toEqual([]);+ expect(+ screen.getByRole("complementary", { name: "Maria's Soul" }),+ ).toBeDefined();+ });++ test("says so when the memories cannot be loaded, instead of claiming there are none", async () => {+ server.use(+ http.get(+ "/api/proxy/api/memory/experts/:expertId/facts",+ () => new HttpResponse(null, { status: 500 }),+ ),+ );++ await openSoulDrawer();++ expect(+ await screen.findByText("Couldn't load what this expert has learned."),+ ).toBeDefined();+ expect(screen.queryByText(/Nothing recorded yet/)).toBeNull();+ });++ test("asks the memory API for nothing while the memory flag is off", async () => {+ memoryFlagMock.mockReturnValue(false);+ let listCalls = 0;+ server.use(+ getListMyExpertMemoryFactsMockHandler(async () => {+ listCalls += 1;+ return { expert_id: "expert-maria", items: [makeFact()] };+ }),+ );++ await openSoulDrawer();++ expect(+ await screen.findByText(+ "Nothing recorded yet. What this expert learns will appear here.",+ ),+ ).toBeDefined();+ expect(listCalls).toBe(0);+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulDrawer.tsx b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulDrawer.tsxindex 4bf0b419ae..1880697794 100644--- a/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulDrawer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulDrawer.tsx@@ -7,9 +7,11 @@ import { Icon } from "@/components/atoms/Icon/Icon";import { Input } from "@/components/atoms/Input/Input";import { Text } from "@/components/atoms/Text/Text";import { LockIcon } from "@hugeicons/core-free-icons";-import { ReactNode, useState } from "react";+import { useState } from "react";import { cn } from "@/lib/utils";import { ExpertSidePanel } from "../ExpertSidePanel/ExpertSidePanel";+import { LearnedNotes } from "./components/LearnedNotes/LearnedNotes";+import { SoulSectionTitle } from "./SoulSectionTitle";import { useBottomScrollShadow } from "./useBottomScrollShadow";import { useSoulDrawer } from "./useSoulDrawer";@@ -66,7 +68,7 @@ function SoulPanelBody({ expert, onClose }: BodyProps) {A living document that shapes every reply.</Text><SoulFields soul={soul} updateField={updateField} />- <LearnedNotes />+ <LearnedNotes expertId={expert.id} /><ProtectedRules rules={expert.protected_soul_rules} /></div><div@@ -155,17 +157,6 @@ function SoulFields({ soul, updateField }: SoulFieldsProps) {);}-function LearnedNotes() {- return (- <section className="mb-8">- <SoulSectionTitle>What I've learned</SoulSectionTitle>- <Text variant="small" tone="muted">- Nothing recorded yet. What this expert learns will appear here.- </Text>- </section>- );-}-function ProtectedRules({ rules }: { rules: string[] }) {return (<section className="border-t border-zinc-200 pt-6">@@ -193,11 +184,3 @@ function ProtectedRules({ rules }: { rules: string[] }) {</section>);}--function SoulSectionTitle({ children }: { children: ReactNode }) {- return (- <Text variant="body-medium" as="h3" tone="primary">- {children}- </Text>- );-}diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulSectionTitle.tsx b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulSectionTitle.tsxnew file mode 100644index 0000000000..8a6e4e7174--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/SoulSectionTitle.tsx@@ -0,0 +1,14 @@+import { Text } from "@/components/atoms/Text/Text";+import type { ReactNode } from "react";++interface Props {+ children: ReactNode;+}++export function SoulSectionTitle({ children }: Props) {+ return (+ <Text variant="body-medium" as="h3" tone="primary">+ {children}+ </Text>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/LearnedNotes.tsx b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/LearnedNotes.tsxnew file mode 100644index 0000000000..959d82a7a8--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/LearnedNotes.tsx@@ -0,0 +1,119 @@+"use client";++import { formatWhen } from "@/app/(platform)/settings/memory/helpers";+import type { MemoryFact } from "@/app/api/__generated__/models/memoryFact";+import { Button } from "@/components/atoms/Button/Button";+import { Link } from "@/components/atoms/Link/Link";+import { Skeleton } from "@/components/atoms/Skeleton/Skeleton";+import { Text } from "@/components/atoms/Text/Text";+import { SoulSectionTitle } from "../../SoulSectionTitle";+import { useLearnedNotes } from "./useLearnedNotes";++interface Props {+ expertId: string;+}++export function LearnedNotes({ expertId }: Props) {+ const { facts, isLoading, isError, forget, forgettingUuid } =+ useLearnedNotes(expertId);++ return (+ <section className="mb-8">+ <SoulSectionTitle>What I've learned</SoulSectionTitle>+ {isLoading ? (+ <NotesSkeleton />+ ) : isError ? (+ <Text variant="small" tone="muted">+ Couldn't load what this expert has learned.+ </Text>+ ) : facts.length === 0 ? (+ <Text variant="small" tone="muted">+ Nothing recorded yet. What this expert learns will appear here.+ </Text>+ ) : (+ <NotesList+ expertId={expertId}+ facts={facts}+ forgettingUuid={forgettingUuid}+ onForget={forget}+ />+ )}+ </section>+ );+}++interface NotesListProps {+ expertId: string;+ facts: MemoryFact[];+ forgettingUuid: string | null;+ onForget: (uuid: string) => void;+}++function NotesList({+ expertId,+ facts,+ forgettingUuid,+ onForget,+}: NotesListProps) {+ return (+ <>+ <Text variant="small" tone="muted">+ Picked up from your conversations. Forget anything that shouldn't+ stick.+ </Text>+ <div className="mt-2 flex flex-col divide-y divide-zinc-100">+ {facts.map((fact) => (+ <div+ key={fact.uuid}+ className="flex items-start justify-between gap-2 py-2.5"+ >+ <div className="min-w-0 flex-1">+ <Text+ variant="small"+ as="p"+ unmask={false}+ className="text-textBlack"+ >+ {fact.fact || `${fact.source} → ${fact.target}`}+ </Text>+ <Text+ variant="small"+ as="span"+ unmask={false}+ className="text-zinc-400"+ >+ {formatWhen(fact.created_at)}+ </Text>+ </div>+ <Button+ type="button"+ variant="ghost"+ size="small"+ className="h-7 !min-w-0 shrink-0 px-2 text-zinc-600"+ loading={forgettingUuid === fact.uuid}+ onClick={() => onForget(fact.uuid)}+ >+ Forget+ </Button>+ </div>+ ))}+ </div>+ <Link+ href={`/settings/memory?expert=${encodeURIComponent(expertId)}`}+ variant="secondary"+ className="mt-3 inline-block text-zinc-600"+ >+ See all in memory settings+ </Link>+ </>+ );+}++function NotesSkeleton() {+ return (+ <div className="mt-2 flex flex-col gap-2 py-1">+ <Skeleton className="h-5 w-3/4" />+ <Skeleton className="h-5 w-2/3" />+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/useLearnedNotes.ts b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/useLearnedNotes.tsnew file mode 100644index 0000000000..00acbfd56a--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/team/components/SoulDrawer/components/LearnedNotes/useLearnedNotes.ts@@ -0,0 +1,62 @@+import {+ getListMyExpertMemoryFactsQueryKey,+ useForgetMyExpertMemoryFact,+ useListMyExpertMemoryFacts,+} from "@/app/api/__generated__/endpoints/memory/memory";+import { toast } from "@/components/molecules/Toast/use-toast";+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";+import { useQueryClient } from "@tanstack/react-query";++/** Enough to show what the expert is picking up without crowding out the Soul+ * fields above it; the rest is one click away on the memory page. */+const SOUL_NOTES_LIMIT = 5;++export function useLearnedNotes(expertId: string) {+ const isMemoryEnabled = useGetFlag(Flag.GRAPHITI_MEMORY);+ const queryClient = useQueryClient();++ const factsQuery = useListMyExpertMemoryFacts(+ expertId,+ { limit: SOUL_NOTES_LIMIT },+ { query: { enabled: Boolean(isMemoryEnabled) } },+ );+ const facts =+ factsQuery.data?.status === 200 ? factsQuery.data.data.items : [];++ const forgetFact = useForgetMyExpertMemoryFact({+ mutation: {+ onSuccess: () => {+ queryClient.invalidateQueries({+ queryKey: getListMyExpertMemoryFactsQueryKey(expertId),+ });+ toast({ title: "Forgotten" });+ },+ onError: () => {+ toast({+ title: "Could not forget that memory",+ description: "Please try again.",+ variant: "destructive",+ });+ },+ },+ });++ async function forget(uuid: string) {+ try {+ await forgetFact.mutateAsync({ expertId, factUuid: uuid });+ } catch {+ // onError already surfaced the toast; keep the rejection out of the+ // click handler.+ }+ }++ return {+ facts,+ isLoading: factsQuery.isLoading,+ isError: factsQuery.isError,+ forget,+ forgettingUuid: forgetFact.isPending+ ? (forgetFact.variables?.factUuid ?? null)+ : null,+ };+}