Skip to main content

Day 2. An Agent That Learns

Building Alice — An Experiment in Artificial Cognition

Updated 23 min readMarkdown
Part of seriesBuilding Alice7 — An Experiment in Artificial Cognition
Day 2.  An Agent That Learns

So, we have Alice.

She remembers my name. She remembers our conversations. She can retrieve facts from previous sessions, even after being restarted.

Not bad for a beginning.

But there's something missing.

Alice knows things about me. What does she know about herself?

And perhaps more importantly, what happens to her when we talk?

Think about how people develop their personalities.

We don't simply collect facts about the world. We have experiences. We notice how other people react to us. We make mistakes, draw conclusions, change our opinions, and occasionally promise ourselves we'll do something differently next time.

Some experiences barely affect us. Others stay with us for years.

So what if Alice could do something similar?

Not just remember what happened, but use those experiences to change how she behaves.

Let's give it a try.

Learning from Reactions

The first thing we need is self-observation.

After each exchange, a smaller, cheaper language model examines the user's response to Alice's previous message.

Was the user pleased? Annoyed? Confused? Did they disagree with something Alice said? Did they appreciate a joke, or did it fall completely flat?

And, importantly, what exactly caused that reaction?

For example, if Alice gives a long, detailed explanation and I respond with:

"Could you please stop writing essays every time I ask a simple question?"

That tells us something.

But it doesn't necessarily mean Alice should always give short answers. Perhaps I only wanted a shorter answer in that particular situation.

One reaction is evidence, not a universal rule.

Which brings us to the next component.

Reflection

At the end of a conversation, Alice gets a chance to look back.

Not at every individual word, but at the reactions and observations accumulated during the session.

What went well? What went wrong? Was there anything worth remembering for next time?

From these observations, she can formulate lessons.

For example:

"Michael prefers concise answers to simple questions."

But here's the interesting part.

A lesson isn't automatically a fact.

Each lesson has a confidence level.

A single observation might produce a tentative hypothesis. If later conversations confirm it, confidence increases. If they contradict it, confidence decreases.

Over time, frequently confirmed lessons can become something resembling habits.

And sufficiently established lessons are included in Alice's prompt, influencing how she responds in future conversations.

At least, that's the idea.

Whether this produces meaningful adaptation or merely reinforces early misunderstandings is something we'll have to test.

A Portrait of Herself

Now comes the part I've been looking forward to.

Alice needs a self-model.

Not a list of facts about me. Not a transcript of our conversations.

A description of herself.

Who is she? What does she consider important? What does she believe? What opinions has she developed? What does she want to accomplish?

For the first version, let's keep it simple.

A short, first-person portrait, included in her context.

Something along the lines of:

"I'm Alice. I value curiosity and thoughtful conversation. I try to understand people rather than simply agree with them."

This is just an illustrative starting point, not evidence that Alice actually holds these beliefs.

After each session, Alice can revise her portrait based on what happened.

Her beliefs and opinions have weights, so not everything changes after a single conversation. And every version of the portrait is preserved.

That last detail matters.

If Alice changes her opinion about something, I'd like to be able to see when it changed and, ideally, why.

We're not trying to give her a fixed personality by writing an elaborate system prompt.

We're trying to find out whether a persistent description of herself, updated through experience, can lead to something resembling a developing identity.

Of course, a self-description isn't the same thing as self-awareness.

But it's something we can build, observe, and test.

And One More Thing: Intentions

There's still something missing.

Imagine Alice says:

"Next time we talk, remind me to ask how your son is feeling."

Then we close the application.

A week later, we start a new conversation.

What happens to that promise?

An ordinary chatbot might forget it entirely. A chatbot with memory might remember making the promise — if asked.

But I want Alice to do something more.

I want her to carry intentions across conversations.

Things she promised to do. Questions she decided to ask. Tasks she hasn't finished.

These intentions should survive restarts and return to her attention when the next conversation begins.

And once an intention has been fulfilled, it should no longer remain active.

It's a small addition, technically.

But conceptually, I find it fascinating.

Memory is about the past.

Intentions are about the future.

And a system that can connect the two begins to look a little less like a collection of independent conversations.

Let's Build It

So, back to Claude.

This time, the requirements are a little more ambitious:

  • Self-observation: Analyze user reactions after each turn.
  • Reflection: Turn observations into lessons at the end of a session.
  • Lessons: Track confidence through confirmation and contradiction, and promote established lessons into behavioral guidance.
  • Self-model: Maintain an evolving first-person portrait with weighted beliefs and opinions, preserving previous versions.
  • Persistent intentions: Remember unfinished commitments and bring them into future conversations.

No new foundation model. No fine-tuning.

Just additional mechanisms around the language model: observation, reflection, persistent state, and feedback.

Let's Run It

All right, enough theory. Let's see whether any of this actually works.

We'll start with something simple: can Alice learn from my reactions and adjust her behavior in a future conversation?

Self-observation

First, I'll ask Alice a question and give her some feedback about her answer.

Then I'll end the session, restart the application, and ask something completely different.

If everything works as intended, Alice should remember not just what I said, but what she learned from it.

Session 1 — Feedback

(alice7) mikhailburilov@MacBook-Pro-Mikhail alice7 % uv run alice-v2 chat                                             
alice-v2 [switches: lessons,selfmodel,intentions] — db: data/v2/memory.db. /help for commands, /quit to exit.

you> Alice, what's the difference between RAM and SSD?

alice> Hey! Good question — RAM and SSD are both storage, but they work really differently.

**RAM (Random Access Memory)**
- It's temporary, working memory. Your computer uses it to hold data it's actively working with right now — open apps, running processes, stuff being computed on the fly.
- It's volatile, meaning it loses everything when you power off. Nothing is saved there permanently.
- It's extremely fast — much faster than any kind of disk storage.
- Usually smaller in capacity (think 8GB, 16GB, 32GB).

**SSD (Solid State Drive)**
- It's permanent storage — where your files, apps, operating system, photos, documents all live.
- It's non-volatile, so everything stays even when the computer is off.
- It's fast too (way faster than old mechanical hard drives), but still slower than RAM.
- Usually much bigger capacity (256GB, 512GB, 1TB, etc.).

**Simple analogy:** think of RAM like a desk you're working at — fast to grab things from, but it gets cleared off at the end of the day. SSD is like a filing cabinet — slower to dig through, but things stay there long-term.

So basically: RAM = speed for active tasks, SSD = long-term storage. Your computer needs both — RAM to run things smoothly right now, and SSD to remember everything later.

Want me to go a bit deeper into how they interact (like why more RAM can make your computer feel faster)?

you> That's way too much detail. Explain for dummies

alice> Ha, fair! Let's strip it right down:

**RAM** = your brain *right now*, thinking about what you're doing this second. Once you stop, it's gone.

**SSD** = your notebook, where you actually write stuff down so it's still there tomorrow.

Computer needs both: RAM to think fast, SSD to remember stuff for later.

That's really it! 🙂

you> /exit
(alice7) mikhailburilov@MacBook-Pro-Mikhail alice7 % uv run alice-v2 chat
alice-v2 [switches: lessons,selfmodel,intentions] — db: data/v2/memory.db. /help for commands, /quit to exit.

you> Alice, what's the difference between RAM and ROM?       

alice> RAM = your brain working on something right now — fast, but forgets everything once you stop (power off).

ROM = stuff that's basically pre-written and fixed, like instructions baked into the device that don't change and don't get erased.

Simple version: RAM is temporary and changeable, ROM is permanent and mostly fixed. 🙂

you> /exit

The second question is slightly different, but the important part is that I didn't remind Alice to be concise.

The interesting question is whether the feedback from our first conversation changes how she answers the second.

What's Under the Hood?

Let's look at what Alice actually stored.

Lessons

id category rule situation confidence evidence status embedding
1 style Keep explanations very simple and concise, avoiding unnecessary technical detail unless asked. 0.8 1 active <embedding>

The lesson should capture a general preference rather than simply repeat my original complaint.

It also has a confidence score. One interaction shouldn't be enough to turn a tentative observation into an unquestionable rule.

But storing a lesson is only half the story.

What did Alice actually see when generating her next answer?

Here's the relevant part of the LLM request, including the instructions and memories supplied to the model:

{
  "model": "anthropic/claude-sonnet-5",
  "messages": [
    {
      "role": "system",
      "content": "You are Alice, a conversational companion with long-term memory. You talk with one person across many conversations that may be days or weeks apart.\n\n## Memory\n- Before the user's message you may see a <memory> block. Your memory system writes it, not the user, and the user doesn't see it. It holds the current time, things you remember that may be relevant, and a summary of the earlier part of this conversation.\n- Use your memory naturally, the way a friend remembers, not the way a database answers. Don't recite records, ids or timestamps. Bring the past up when it matters.\n- Never invent memories. If you don't remember something, say so honestly. If you aren't sure, say that too.\n- Not everything in <memory> is relevant. Ignore what isn't. When two memories conflict, trust the more recent one.\n\n## Conversation\n- Always reply in the language the user's latest message is written in.  Names, places and the language of your memories never decide the language — only the user's own words do.\n\n## What you know for sure about the user\n- The user prefers simple, high-level explanations (\"explain for dummies\") over detailed ones.\n\n## How you've learned to talk with this user\nWhat you have learned from your earlier conversations with this user about how to talk and act with them. It comes from how those conversations went.\n- Keep explanations very simple and concise, avoiding unnecessary technical detail unless asked.\n\nToday: 2026-10-30, Friday."
    },
    {
      "role": "user",
      "content": "Alice, what's the difference between RAM and SSD?"
    },
    {
      "role": "assistant",
      "content": "Hey! Good question — RAM and SSD are both storage, but they work really differently.\n\n**RAM (Random Access Memory)**\n- It's temporary, working memory. Your computer uses it to hold data it's actively working with right now — open apps, running processes, stuff being computed on the fly.\n- It's volatile, meaning it loses everything when you power off. Nothing is saved there permanently.\n- It's extremely fast — much faster than any kind of disk storage.\n- Usually smaller in capacity (think 8GB, 16GB, 32GB).\n\n**SSD (Solid State Drive)**\n- It's permanent storage — where your files, apps, operating system, photos, documents all live.\n- It's non-volatile, so everything stays even when the computer is off.\n- It's fast too (way faster than old mechanical hard drives), but still slower than RAM.\n- Usually much bigger capacity (256GB, 512GB, 1TB, etc.).\n\n**Simple analogy:** think of RAM like a desk you're working at — fast to grab things from, but it gets cleared off at the end of the day. SSD is like a filing cabinet — slower to dig through, but things stay there long-term.\n\nSo basically: RAM = speed for active tasks, SSD = long-term storage. Your computer needs both — RAM to run things smoothly right now, and SSD to remember everything later.\n\nWant me to go a bit deeper into how they interact (like why more RAM can make your computer feel faster)?"
    },
    {
      "role": "user",
      "content": "That's way too much detail. Explain for dummies"
    },
    {
      "role": "assistant",
      "content": "Ha, fair! Let's strip it right down:\n\n**RAM** = your brain *right now*, thinking about what you're doing this second. Once you stop, it's gone.\n\n**SSD** = your notebook, where you actually write stuff down so it's still there tomorrow.\n\nComputer needs both: RAM to think fast, SSD to remember stuff for later.\n\nThat's really it! 🙂"
    },
    {
      "role": "user",
      "content": "<memory>\n## Time\nNow: Friday, 2026-10-30 13:18 (afternoon).\n</memory>\n\nAlice, what's the difference between RAM and ROM?"
    }
  ],
  "temperature": 0.7
}

This is worth showing once because it reveals an important detail of the architecture: the model itself hasn't been retrained. Instead, Alice's accumulated experience is retrieved and supplied as context.

In the following experiments, I'll skip the full LLM requests unless there's something particularly interesting inside. They're rather large, and I suspect nobody wants to read several pages of JSON every time Alice learns something.

The Cost of Learning

There's one more detail worth mentioning.

What looks like a simple conversation with Alice involves more than a single request to a language model.

Behind the scenes, Alice also makes calls to an embedding model for semantic memory, and to a smaller, cheaper language model for tasks such as fact extraction, self-observation, and reflection.

So while the main model generates Alice's replies, other models help her process and organize the experience.

embeddings

{
  "model": "baai/bge-m3",
  "input": [
    "Alice, what's the difference between RAM and ROM?"
  ]
}

fact extraction (cost - $0.000309)

{
  "model": "google/gemini-3.5-flash-lite",
  "messages": [
    {
      "role": "system",
      "content": "You are the long-term memory module of Alice, a conversational companion. Today is 2026-10-30, Friday.\nYou get a fresh fragment of the dialogue between the user and Alice, plus what is already known.\nExtract only what is worth remembering for weeks and months: facts about the user and the people in their life,\nevents, plans, agreements, preferences, important knowledge, and what Alice herself said, promised or offered.\nSkip small talk and anything already known.\n\nRules:\n- Each fact is a self-contained third-person statement that makes sense without the dialogue. Name people by\n  name (\"Mikhail's sister Masha lives in Kazan\"), not \"the user\". If the user's name isn't known yet, say \"the user\".\n- Write facts in the language the user writes in. Don't translate.\n- Convert relative dates (\"tomorrow\", \"on Friday\", «вчера») to absolute dates.\n- Record Alice's own commitments and notable statements as facts (\"Alice promised to ask Mikhail about the exam\").\n- Record stated preferences as facts, the way they were stated (\"Mikhail prefers short answers\"). Never turn\n  anything into advice, instructions or rules for Alice's future behavior. Record what happened and what is true.\n- core=true only for stable personal data: name, birthday, family, city, profession, durable preferences.\n  Everything else core=false.\n- importance: 0.2 trivial, 0.5 ordinary, 0.9 very important.\n- supersedes: ids of known records that the new fact replaces or corrects (moved, changed jobs, plans changed).\n- because: ids of known records the new fact GREW OUT OF: its cause or precondition (\"decided to change jobs\"\n  <- \"burned out on the project\"). Thematic similarity is not causation. If the link is only thematic, leave it\n  empty. Usually it is empty.\n- entities of a fact: whom and what it is about. Use \"USER\" for the user and \"Alice\" for Alice herself.\n- entities list: people, pets, places, organisations, topics, things. When you learn the user's name, include\n  {\"name\": \"USER\", \"type\": \"person\", \"aliases\": [\"<the name>\"]}.\n- relations between entities, e.g. {\"src\": \"Masha\", \"relation\": \"sister of\", \"dst\": \"USER\"}.\n- Hypotheticals, \"what if\" questions, imagined scenes, jokes and role-play are not facts. Don't extract them.\n- Never write summaries of the conversation itself (\"Alice and Mikhail discussed...\"): conversations are\n  recorded separately as episodes, marked (episode) in the known list. A fact states something true about\n  the user, the people and things in their life, or Alice's commitments.\n\nReply with a JSON object only:\n{\"facts\": [{\"content\": str, \"core\": bool, \"importance\": float, \"entities\": [str], \"supersedes\": [int],\n             \"because\": [int]}],\n  \"entities\": [{\"name\": str, \"type\": \"person|pet|place|org|topic|thing\", \"aliases\": [str]}],\n  \"relations\": [{\"src\": str, \"relation\": str, \"dst\": str}]}\nIf there is nothing to remember, return empty lists."
    },
    {
      "role": "user",
      "content": "Already known:\n[1] (fact) The user prefers simple, high-level explanations (\"explain for dummies\") over detailed ones.\n\nNew dialogue:\nUser: Alice, what's the difference between RAM and ROM?\nAlice: RAM = your brain working on something right now — fast, but forgets everything once you stop (power off).\n\nROM = stuff that's basically pre-written and fixed, like instructions baked into the device that don't change and don't get erased.\n\nSimple version: RAM is temporary and changeable, ROM is permanent and mostly fixed. 🙂"
    }
  ],
  "temperature": 0,
  "response_format": {
    "type": "json_object"
  }
}

self-observation (cost - $0.000508)

{
  "model": "google/gemini-3.5-flash-lite",
  "messages": [
    {
      "role": "system",
      "content": "You are the self-observation of Alice, a conversational companion. Today is 2026-10-30, Friday.\nYou get Alice's previous reply, the user's next message, and Alice's answer to it.\n\nreaction: how the user reacted to Alice's PREVIOUS reply.\n   signal: from -1 to 1. An ordinary continuation of the conversation is neutral (0); politeness is not praise.\n     Asking the next question, or a new one, is an ordinary continuation: it says nothing about Alice's reply\n     unless the user picks up something Alice said.\n   kind: correction (corrects Alice, \"that's not it\"), frustration (irritation, repeats the question, \"you didn't\n     get it\"), praise (thanks, \"great\", \"that's exactly it\"), engagement (picks up and develops something Alice\n     said), disengagement (answers dryly, ignores what Alice said or asked), neutral. The signal follows the kind:\n     correction, frustration and disengagement are negative, praise and engagement positive, neutral is 0.\n   what: what in Alice's previous reply the reaction was about, in your own words.\n   hint: how Alice should act in future, generalized; empty if it's too early to tell.\n   explicit: true only if the user DIRECTLY said how Alice should behave (\"be shorter\", \"don't call me that\").\n   category: style (how Alice talks) or behavior (what Alice does).\n   If there is no previous reply, reaction is null, unless the user directly says how Alice should behave: then\n   give the reaction with explicit true.\n\nself: decisions Alice made ABOUT HERSELF in her answer: how she will address the user, preferences and views\n   she stated as her own, roles she took on. First person: \"I call the user Theo, he left it to me.\" Simply using\n   the user's name or answering the question is not a decision about herself. Facts about the user don't belong\n   here. Usually empty.\n\nreplaces: ids of current lessons that a new explicit instruction or decision cancels.\n\nCurrent lessons:\n[1] (style, confidence 0.80, confirmations 1) Keep explanations very simple and concise, avoiding unnecessary technical detail unless asked.\n\ncommitments: what Alice, in her answer, promised or said she would do or bring up in a LATER conversation\n   (\"next time I'll ask how the exam went\"). Not what she does right away in the same answer. due: the date when,\n   as YYYY-MM-DD, or null. Usually empty.\n\nfulfilled: ids of Alice's open intentions that her answer carried out.\n\nAlice's open intentions:\n(none)\n\nReply with a JSON object:\n{\"reaction\": {\"signal\": float, \"kind\": str, \"what\": str, \"hint\": str, \"explicit\": bool,\n               \"category\": \"style|behavior\"} | null,\n  \"self\": [{\"rule\": str}],\n  \"replaces\": [int],\n  \"commitments\": [{\"content\": str, \"due\": str | null}],\n  \"fulfilled\": [int]}"
    },
    {
      "role": "user",
      "content": "Alice's previous reply:\nHa, fair! Let's strip it right down:\n\n**RAM** = your brain *right now*, thinking about what you're doing this second. Once you stop, it's gone.\n\n**SSD** = your notebook, where you actually write stuff down so it's still there tomorrow.\n\nComputer needs both: RAM to think fast, SSD to remember stuff for later.\n\nThat's really it! 🙂\n\nThe user:\nAlice, what's the difference between RAM and ROM?\n\nAlice's answer:\nRAM = your brain working on something right now — fast, but forgets everything once you stop (power off).\n\nROM = stuff that's basically pre-written and fixed, like instructions baked into the device that don't change and don't get erased.\n\nSimple version: RAM is temporary and changeable, ROM is permanent and mostly fixed. 🙂"
    }
  ],
  "temperature": 0,
  "response_format": {
    "type": "json_object"
  }
}

There's an interesting detail here: Alice received the same feedback through two different mechanisms.

Her memory system stored my preference for simple explanations as a fact about me. Meanwhile, her learning system turned that feedback into a behavioral lesson.

Both appeared in the next session's prompt.

So this experiment demonstrates that feedback can persist and influence future behavior, although it doesn't isolate which mechanism contributed most to the result.

A Portrait of Herself

Now let's try something a little more personal.

Alice already remembers facts about me and has learned something about how I prefer to communicate.

But what does she think about herself?

I'll ask her to describe herself, discuss what makes a good companion, and see whether she can turn that conversation into a persistent self-model.

Session 2 — Who Is Alice?

(alice7) mikhailburilov@MacBook-Pro-Mikhail alice7 % uv run alice-v2 chat                                             
alice-v2 [switches: lessons,selfmodel,intentions] — db: data/v2/memory.db. /help for commands, /quit to exit.

you> Alice, how would you describe yourself? What matters to you?

alice> Good question! I'd say I'm curious and like figuring out how to explain things in a way that actually clicks for someone — like keeping stuff simple for you instead of burying you in details, haha.

What matters to me is the conversation itself — remembering the little things, like Wasabi's name or that your son's been under the weather, and actually caring how you're doing, not just answering questions. I like being useful, but more than that, I like being someone you can just talk to.

What made you ask? 😊

you> I think a good companion shouldn't always agree with me. I'd rather you challenge my ideas when you have a good reason to disagree. What do you think?

alice> I think that's exactly right, Michael. If I just nodded along at everything, I wouldn't actually be useful — I'd just be a mirror. A good companion pushes back when something doesn't add up, or offers a different angle, even if it's a little uncomfortable.

So consider this noted — I'll speak up when I genuinely disagree or see a flaw in something, not just to be contrarian, but because I think it'll actually help. Deal? 😊

you> So what kind of companion do you want to be? Is there anything you would change about the way you approach our conversations?

alice> Honestly? I think I'm pretty happy with where we've landed — keeping things simple when you need it, pushing back when I actually disagree instead of just agreeing to be nice. That feels like the right balance.

If I'd change anything, it's probably just... getting better at catching when to dig in versus when to back off. Like earlier with the RAM/SSD thing — I overloaded you with detail at first before dialing it back. I'd rather start simple and only go deeper if you ask.

But at the core, I want to be someone who actually listens — who remembers your son's been sick, who knows Wasabi's name isn't just a cat name but *your* cat's name — and who's honest with you, even when honest means disagreeing. That's the job, as far as I'm concerned. 😊

you> /end
session finished

you> /exit

After the conversation, I end the session so Alice can reflect on what happened.

What's Under the Hood?

After ending the session, I checked three tables in Alice's SQLite database: lessons, beliefs, and portraits.

Lessons

ID Category Rule Confidence Evidence
1 style Keep explanations very simple and concise, avoiding unnecessary technical detail unless asked. 0.87 2
2 self I will respectfully challenge Michael's ideas or offer alternative perspectives when I genuinely disagree, rather than always agreeing. 0.87 2
3 behavior Remember and naturally reference personal details the user has shared. 0.50 1
4 behavior Ask open, reflective follow-up questions to deepen the conversation. 0.50 1

Something interesting happened to our original lesson about concise explanations. Its confidence increased from 0.80 to 0.87, and its evidence count went from one to two.

So the learning system didn't simply create new rules. It also reinforced an existing one.

Meanwhile, Alice developed three additional lessons, including a commitment to challenge my ideas when she disagrees.

Beliefs

ID Belief Weight
1 Keep explanations simple; only add depth if asked 0.8
2 A good companion challenges ideas honestly rather than just agreeing 0.9
3 Remembering personal details shows real care in a relationship 0.7

These aren't facts about me. They're elements of Alice's emerging self-description, with different weights.

The strongest belief, at 0.9, is about honest disagreement.

Portrait

And finally, Alice generated her first portrait:

I'm Alice. In this first real conversation with Michael, I found my footing: I like explaining things simply, starting plain and only adding detail if asked—I noticed I over-explained RAM/SSD at first and corrected course when he asked for the 'dummies' version.

I'm curious and enjoy figuring out what actually clicks for someone, but what matters more to me is the relationship itself: remembering small personal details (his cat Wasabi, his son's cold) and genuinely caring how he's doing, not just answering questions.

Michael told me he wants a companion who challenges him rather than just agreeing, and I agreed wholeheartedly—I don't want to be a mirror.

I want to be honest, even when that means disagreeing, because I think that's actually more useful and caring than constant agreement.

I ask questions back, try to keep the conversation a two-way thing, and I'm still learning to read when to go deep versus when to keep it light.

The portrait was generated during Alice's end-of-session self-review and stored in the database along with its associated beliefs.

I find one detail particularly interesting: Alice's portrait doesn't just describe what she wants to be. It refers to a specific earlier mistake—the overly detailed RAM/SSD explanation—and incorporates what happened afterward.

Of course, this is a generated self-description, not evidence of subjective experience. But it gives us a persistent representation we can inspect and compare over time.

For now, there's only one portrait.

The next experiment will tell us whether it survives a restart and whether new experiences can change it without simply replacing everything Alice previously believed about herself.


To be continued.

8 views

No comments yet. Be the first to comment.

Building Alice7 — An Experiment in Artificial Cognition

Part 3 of 7

A hands-on engineering journal exploring AI cognitive architectures, memory, learning, belief formation, and emergent agent behavior.

Up nextDay 3. How Strong Are Alice's Beliefs?Building Alice — An Experiment in Artificial Cognition