Skip to content
Simon Place
FR EN
Book a Meet call

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 editor
const 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 editor

Running 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

Some of these need a free account or an API key, which may be paid.

Legal notice and privacy