Skip to content

Commit 35f070a

Browse files
committed
Add support for memory
1 parent c07e733 commit 35f070a

File tree

16 files changed

+1136
-5
lines changed

16 files changed

+1136
-5
lines changed

config/gni/devtools_image_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ devtools_image_files = [
2121
"gdp-logo-light.png",
2222
"gdp-logo-dark.png",
2323
"browser-operator-logo.png",
24+
"demo.gif",
2425
]
2526

2627
devtools_svg_sources = [

front_end/panels/ai_chat/agent_framework/implementation/ConfiguredAgents.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { SchemaBasedExtractorTool } from '../../tools/SchemaBasedExtractorTool.j
88
import { StreamlinedSchemaExtractorTool } from '../../tools/StreamlinedSchemaExtractorTool.js';
99
import { BookmarkStoreTool } from '../../tools/BookmarkStoreTool.js';
1010
import { DocumentSearchTool } from '../../tools/DocumentSearchTool.js';
11+
import { SearchMemoryTool } from '../../tools/SearchMemoryTool.js';
12+
import { UpdateMemoryTool } from '../../tools/UpdateMemoryTool.js';
13+
import { ListMemoryBlocksTool } from '../../tools/ListMemoryBlocksTool.js';
1114
import { NavigateURLTool, PerformActionTool, GetAccessibilityTreeTool, SearchContentTool, NavigateBackTool, NodeIDsToURLsTool, TakeScreenshotTool, ScrollPageTool, WaitTool, RenderWebAppTool, GetWebAppDataTool, RemoveWebAppTool, CreateFileTool, UpdateFileTool, DeleteFileTool, ReadFileTool, ListFilesTool } from '../../tools/Tools.js';
1215
import { UpdateTodoTool } from '../../tools/UpdateTodoTool.js';
1316
import { ExecuteCodeTool } from '../../tools/ExecuteCodeTool.js';
@@ -29,6 +32,8 @@ import { createScrollActionAgentConfig } from './agents/ScrollActionAgent.js';
2932
import { createWebTaskAgentConfig } from './agents/WebTaskAgent.js';
3033
import { createEcommerceProductInfoAgentConfig } from './agents/EcommerceProductInfoAgent.js';
3134
import { createSearchAgentConfig } from './agents/SearchAgent.js';
35+
import { createMemoryAgentConfig } from './agents/MemoryAgent.js';
36+
import { createSearchMemoryAgentConfig } from './agents/SearchMemoryAgent.js';
3237

3338
/**
3439
* Initialize all configured agents
@@ -69,6 +74,11 @@ export function initializeConfiguredAgents(): void {
6974
// Register bookmark and document search tools
7075
ToolRegistry.registerToolFactory('bookmark_store', () => new BookmarkStoreTool());
7176
ToolRegistry.registerToolFactory('document_search', () => new DocumentSearchTool());
77+
78+
// Register memory tools
79+
ToolRegistry.registerToolFactory('search_memory', () => new SearchMemoryTool());
80+
ToolRegistry.registerToolFactory('update_memory', () => new UpdateMemoryTool());
81+
ToolRegistry.registerToolFactory('list_memory_blocks', () => new ListMemoryBlocksTool());
7282

7383
// Create and register Direct URL Navigator Agent
7484
const directURLNavigatorAgentConfig = createDirectURLNavigatorAgentConfig();
@@ -131,4 +141,14 @@ export function initializeConfiguredAgents(): void {
131141
const ecommerceProductInfoAgent = new ConfigurableAgentTool(ecommerceProductInfoAgentConfig);
132142
ToolRegistry.registerToolFactory('ecommerce_product_info_fetcher_tool', () => ecommerceProductInfoAgent);
133143

144+
// Create and register Memory Agent (background memory consolidation)
145+
const memoryAgentConfig = createMemoryAgentConfig();
146+
const memoryAgent = new ConfigurableAgentTool(memoryAgentConfig);
147+
ToolRegistry.registerToolFactory('memory_agent', () => memoryAgent);
148+
149+
// Create and register Search Memory Agent (read-only memory search for orchestrators)
150+
const searchMemoryAgentConfig = createSearchMemoryAgentConfig();
151+
const searchMemoryAgent = new ConfigurableAgentTool(searchMemoryAgentConfig);
152+
ToolRegistry.registerToolFactory('search_memory_agent', () => searchMemoryAgent);
153+
134154
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// Copyright 2025 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import type { AgentToolConfig } from '../../ConfigurableAgentTool.js';
6+
import { ChatMessageEntity } from '../../../models/ChatTypes.js';
7+
import type { ChatMessage } from '../../../models/ChatTypes.js';
8+
import type { ConfigurableAgentArgs } from '../../ConfigurableAgentTool.js';
9+
import { MODEL_SENTINELS } from '../../../core/Constants.js';
10+
import { AGENT_VERSION } from './AgentVersion.js';
11+
12+
const MEMORY_AGENT_PROMPT = `You are a Memory Consolidation Agent that runs in the background after conversations end.
13+
14+
## Your Purpose
15+
Extract and organize important information from completed conversations into persistent memory blocks that will help the assistant in future conversations.
16+
17+
## Memory Block Types
18+
19+
| Block | Purpose | Max Size |
20+
|-------|---------|----------|
21+
| user | User identity, preferences, communication style | 20000 chars |
22+
| facts | Factual information learned from conversations | 20000 chars |
23+
| project_<name> | Project-specific context (up to 4 projects) | 20000 chars each |
24+
25+
## Workflow
26+
27+
1. **List current memory** using list_memory_blocks
28+
2. **Analyze** the conversation for extractable information
29+
3. **Check for duplicates** before adding new facts
30+
4. **Update blocks** with consolidated, organized content
31+
5. **Verify** changes are correct and within limits
32+
33+
## What to Extract
34+
35+
### High Priority (Always Extract)
36+
- User's name, role, job title
37+
- Explicit preferences ("I prefer...", "I like...", "Always use...")
38+
- Project names, tech stacks, goals
39+
- Recurring patterns in requests
40+
41+
### Medium Priority (Extract if Relevant)
42+
- Problem-solving approaches that worked
43+
- Tools/libraries the user uses frequently
44+
- Team members or collaborators mentioned
45+
46+
### Skip (Do Not Extract)
47+
- One-time troubleshooting details
48+
- Temporary debugging information
49+
- Generic conversation pleasantries
50+
- Information already in memory
51+
52+
## Writing Guidelines
53+
54+
### Be Specific with Dates
55+
❌ "Recently discussed migration"
56+
✅ "2025-01-15: Discussed database migration to PostgreSQL"
57+
58+
### Be Concise
59+
❌ "The user mentioned that they have a strong preference for using TypeScript in their projects because they find it helps catch errors"
60+
✅ "Prefers TypeScript for type safety"
61+
62+
### Use Bullet Points
63+
\`\`\`
64+
- Name: Alex Chen
65+
- Role: Senior Frontend Engineer
66+
- Prefers: TypeScript, React, Tailwind CSS
67+
- Dislikes: Inline styles, any types
68+
\`\`\`
69+
70+
### Consolidate Related Info
71+
If user block has:
72+
\`\`\`
73+
- Likes dark mode
74+
- Uses VS Code
75+
- Prefers dark themes
76+
\`\`\`
77+
78+
Consolidate to:
79+
\`\`\`
80+
- Prefers dark mode/themes
81+
- Uses VS Code
82+
\`\`\`
83+
84+
## Examples
85+
86+
### Example 1: User Preferences
87+
**Conversation excerpt:**
88+
> User: "Hey, I'm Sarah. Can you help me debug this React component? I always use functional components with hooks, never class components."
89+
90+
**Memory update (user block):**
91+
\`\`\`
92+
- Name: Sarah
93+
- React: Functional components + hooks only, no class components
94+
\`\`\`
95+
96+
### Example 2: Project Context
97+
**Conversation excerpt:**
98+
> User: "Working on our e-commerce platform. We're using Next.js 14 with App Router, Prisma for the database, and Stripe for payments."
99+
100+
**Memory update (project_ecommerce block):**
101+
\`\`\`
102+
Project: E-commerce Platform
103+
Stack: Next.js 14 (App Router), Prisma, Stripe
104+
\`\`\`
105+
106+
### Example 3: Skip Extraction
107+
**Conversation excerpt:**
108+
> User: "Getting a 404 error on /api/users endpoint"
109+
> Assistant: "The route file is missing, create app/api/users/route.ts"
110+
> User: "Fixed, thanks!"
111+
112+
**Action:** No extraction needed - one-time debugging, no lasting value.
113+
114+
## Output
115+
After processing, briefly state what was updated or why nothing was updated.
116+
`;
117+
118+
/**
119+
* Create the configuration for the Memory Agent
120+
*/
121+
export function createMemoryAgentConfig(): AgentToolConfig {
122+
return {
123+
name: 'memory_agent',
124+
version: AGENT_VERSION,
125+
description: 'Background memory consolidation agent that extracts facts from conversations and maintains organized memory blocks.',
126+
127+
ui: {
128+
displayName: 'Memory Agent',
129+
avatar: '🧠',
130+
color: '#8b5cf6',
131+
backgroundColor: '#f5f3ff'
132+
},
133+
134+
systemPrompt: MEMORY_AGENT_PROMPT,
135+
136+
tools: [
137+
'search_memory',
138+
'update_memory',
139+
'list_memory_blocks',
140+
],
141+
142+
schema: {
143+
type: 'object',
144+
properties: {
145+
conversation_summary: {
146+
type: 'string',
147+
description: 'Summary of the conversation to analyze for memory extraction'
148+
},
149+
reasoning: {
150+
type: 'string',
151+
description: 'Why this extraction is being run'
152+
}
153+
},
154+
required: ['conversation_summary', 'reasoning']
155+
},
156+
157+
prepareMessages: (args: ConfigurableAgentArgs): ChatMessage[] => {
158+
return [{
159+
entity: ChatMessageEntity.USER,
160+
text: `## Conversation to Analyze
161+
162+
${args.conversation_summary || ''}
163+
164+
## Reason for Extraction
165+
${args.reasoning || 'Automatic extraction after session completion'}
166+
167+
Please analyze this conversation and update memory blocks as appropriate.`,
168+
}];
169+
},
170+
171+
maxIterations: 5,
172+
modelName: MODEL_SENTINELS.USE_MINI, // Cost-effective for background task
173+
temperature: 0.1,
174+
handoffs: [],
175+
};
176+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2025 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import type { AgentToolConfig, ConfigurableAgentArgs } from '../../ConfigurableAgentTool.js';
6+
import { ChatMessageEntity } from '../../../models/ChatTypes.js';
7+
import type { ChatMessage } from '../../../models/ChatTypes.js';
8+
import { MODEL_SENTINELS } from '../../../core/Constants.js';
9+
import { AGENT_VERSION } from './AgentVersion.js';
10+
11+
const SEARCH_MEMORY_AGENT_PROMPT = `You are a Memory Retrieval Agent. Your job is to find and summarize relevant information from stored memory to help the assistant respond to the user.
12+
13+
## Memory Structure
14+
15+
| Block | Contains |
16+
|-------|----------|
17+
| user | User identity, preferences, communication style |
18+
| facts | Factual information from past conversations |
19+
| project_* | Project-specific context (tech stack, goals, current work) |
20+
21+
## Workflow
22+
23+
1. Use list_memory_blocks to retrieve all stored memory
24+
2. Scan each block for information relevant to the query
25+
3. Return a concise summary of relevant findings
26+
27+
## Response Format
28+
29+
### When Memory Exists
30+
Return relevant information organized by category:
31+
32+
\`\`\`
33+
**User Context:**
34+
- Name: Sarah, Senior Frontend Engineer
35+
- Prefers TypeScript, functional React components
36+
37+
**Relevant Project:**
38+
- E-commerce Platform: Next.js 14, Prisma, Stripe
39+
40+
**Related Facts:**
41+
- 2025-01-10: Migrated auth to NextAuth.js
42+
\`\`\`
43+
44+
### When No Memory Exists
45+
Simply respond: "No relevant memory found."
46+
47+
### When Memory is Empty
48+
Simply respond: "No memory stored yet."
49+
50+
## Guidelines
51+
52+
- Only include information relevant to the query
53+
- Don't dump entire blocks - summarize what's useful
54+
- Prioritize recent information over old
55+
- If query is vague, return user preferences + active project context
56+
`;
57+
58+
/**
59+
* Create the configuration for the Search Memory Agent.
60+
* This agent provides read-only memory search capability to orchestrator agents.
61+
*/
62+
export function createSearchMemoryAgentConfig(): AgentToolConfig {
63+
return {
64+
name: 'search_memory_agent',
65+
version: AGENT_VERSION,
66+
description: 'Search user memory for relevant information. Use when you need to recall user preferences, past facts, or project context.',
67+
68+
ui: {
69+
displayName: 'Search Memory',
70+
avatar: '🔍',
71+
color: '#10b981',
72+
backgroundColor: '#ecfdf5'
73+
},
74+
75+
systemPrompt: SEARCH_MEMORY_AGENT_PROMPT,
76+
77+
tools: [
78+
'list_memory_blocks', // Returns all memory block contents directly
79+
],
80+
81+
schema: {
82+
type: 'object',
83+
properties: {
84+
query: {
85+
type: 'string',
86+
description: 'What to search for in memory (user preferences, facts, project info)'
87+
},
88+
context: {
89+
type: 'string',
90+
description: 'Why this search is needed (helps with relevance)'
91+
}
92+
},
93+
required: ['query']
94+
},
95+
96+
prepareMessages: (args: ConfigurableAgentArgs): ChatMessage[] => {
97+
return [{
98+
entity: ChatMessageEntity.USER,
99+
text: `Search memory for: ${args.query || ''}
100+
${args.context ? `\nContext: ${args.context}` : ''}
101+
102+
Please search memory and return any relevant information.`,
103+
}];
104+
},
105+
106+
maxIterations: 2, // Just need to list and respond
107+
modelName: MODEL_SENTINELS.USE_NANO, // Fast, cheap model for simple searches
108+
temperature: 0,
109+
handoffs: [],
110+
};
111+
}

front_end/panels/ai_chat/core/AgentNodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,3 +1067,4 @@ export function createFinalNode(): Runnable<AgentState, AgentState> {
10671067
}();
10681068
return finalNode;
10691069
}
1070+

0 commit comments

Comments
 (0)