Module 2 of 10, lesson 4 of 5
Practice
Anatomy: components and memory
Write the code
Runs in your browser, with no install, account or API key. The model is scripted, so the results are repeatable.
// Rough estimate: about 4 characters per token.const countTokens = (message) => Math.ceil(JSON.stringify(message.content).length / 4);function trimContext(messages, maxTokens) { // TODO return messages;}module.exports = { trimContext, countTokens };
Give the agent a skillTrim the context
Open in the editorconst DAY = 24 * 60 * 60 * 1000;function relevance(memory, query) { const words = query.toLowerCase().split(/\s+/); const hits = words.filter((w) => memory.text.toLowerCase().includes(w)); return hits.length / words.length;}function score(memory, query, now) {
Repair the agentFix memory recall
Open in the editorRunning project
Running project: list what the refund agent needs to know. Put each item in one of the four memories. Cross out anything that doesn’t improve a concrete decision. For what’s left, write down when the information expires.
Practice
- Long-Term Agentic Memory with LangGraph DeepLearning.AI
Short course on building an agent that remembers.
Some of these need a free account or an API key, which may be paid.