ADK Memory Series: The Foundation of Context Engineering
Substack: ADK记忆篇:上下文工程的基底 (中文在最后)
🇨🇳
所有 ADK 项目(P01–P50)均共用统一的运行环境,包括仓库根目录 .venv 虚拟环境、统一的 requirements.txt 依赖、根目录 .env 中的 Google Gemini API Key,以及完整的 ADK Runtime(Session、Memory、State、Tools、Router)。为了保持项目演化的连续性,本仓库不在单个项目中重复环境配置说明,所有运行环境的详细规范与最新要求请参见:
🇺🇸
All ADK projects (P01–P50) share a unified execution environment: a single root-level .venv virtual environment, a common requirements.txt, a repository-level .env containing the Google Gemini API key, and the full ADK Runtime (Session, Memory, State, Tools, Router). To ensure consistent evolution across projects, individual project folders no longer include environment setup instructions. For complete and up-to-date environment specifications, please refer to:
ADK Memory Series: The Foundation of Context Engineering
I’m summarizing ADK’s context-engineering and memory mechanisms, and I want to write this as a series that anyone can read — but that, when you actually run it, is absolutely not “just a tutorial.”
This is one of the foundational abilities you must master in 2025:
how to truly understand a large model’s “memory” and context — how it is engineered, controlled, structured, and made reliable.
I’m breaking the whole knowledge system into 10 mini-projects.
It looks long (this article is long), but when you finish running them you’ll realize:
This is nothing. This is just the beginning.
Later I’ll share many engineering hypotheses and ideas, but first we have to nail the fundamentals.
Each project contains only one file: main.py.
(Yes, really. Just one.)
But you have to run them sequentially.
Because each project’s success becomes the prerequisite for the next one.
It’s not because I want to train you into being an engineer — it’s because:
If you run these 10 incremental projects, you will gain enough “LLM memory understanding” to speak to real engineers as an equal.
Even more importantly:
No matter your background
No matter whether you’re a CS person
No matter whether you’ve ever written Python
In this new scientific paradigm, we’re all standing at the same starting line.
Frankly, the traditional notion of “professional specialization” has become a mental wall — something that traps people in an old paradigm.
Those of us who realize the new paradigm has already arrived must do the opposite:
We tear the walls down.
So give yourself a little patience.
Run it slowly.
Understand it.
Absorb it.
A key idea: the code is not important (yes, you heard that right)
You don’t need to write perfect code.
You don’t need to understand every detail.
You just need to do one thing:
With AI’s guidance, run the code and observe the behavior.
Because context engineering is a phenomenological system.
Its truth lies in the structure that emerges when it runs, not in the code as an isolated object.
This is why I insist on writing in every project folder:
README.mdproject.card.yaml
And you may ask:
Why so many files? Why does it look redundant?
Because this era has completely changed—
Software is no longer understood by writing code.It is understood by observing structure.
🧠 How a Stateless LLM Learns to Remember: Project P11 Walkthrough
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p11-stateful-inmemory
This is the moment when a raw LLM stops being a “smart autocomplete” and begins evolving into an actual agent.
Today we ran P11 – the Minimal Stateful Agent, the very first cell in the Sessions & Memory module.
Here is the exact output:
(.venv) ➜ p11-stateful-inmemory python src/main.py
✅ P11 — stateful_inmemory: main() starting
🧠 Created session: id=p11-inmemory-demo, user_id=susan
User[p11-inmemory-demo] > My name is Sam!
AI[p11-inmemory-demo] > Hi Sam! It’s nice to meet you.
User[p11-inmemory-demo] > What is my name?
AI[p11-inmemory-demo] > Your name is Sam.
📜 Session Dump — events timeline:
- [0] user: My name is Sam!
- [1] inmemory_agent: Hi Sam! It’s nice to meet you.
- [2] user: What is my name?
- [3] inmemory_agent: Your name is Sam.
At first glance, this looks trivial — of course the AI remembered your name, right?
But the truth is:
the LLM itself remembered nothing.
Not a single bit.
And this tiny four-line timeline is the beginning of something enormous.
Let me explain why.
1. The Lie We All Believe: “The AI remembered me.”
When people first talk to ChatGPT or Claude, they naturally assume:
“The model knows who I am. It remembers what I said.”
But modern LLMs are stateless mathematical functions.
They don’t store anything between turns.
If you don’t feed the model the previous conversation,
it literally has no idea who you are — even two seconds later.
Nothing stays in its internal weights.
Nothing is cached as identity.
Nothing persists across messages.
So how did the AI answer:
“Your name is Sam.”
Correctly?
2. The Secret: ADK Rebuilds Context Using an External Timeline
Google ADK (Agent Development Kit) makes the truth visible:
All “memory” comes from an external event timeline called Session.events.
When you ran P11, this is what happened:
Step 1 — You said: “My name is Sam.”
ADK created the first event:
[0] user: My name is Sam!
Step 2 — The LLM responded.
That response became:
[1] inmemory_agent: Hi Sam! It’s nice to meet you.
Step 3 — You asked: “What is my name?”
ADK stitched events [0] and [1] into the next prompt —
that’s why the model “remembered” your name.
Step 4 — ADK recorded that reply too.
[3] inmemory_agent: Your name is Sam.
This is the entire magic:
memory = the event timeline
and the Runner is the machine that rebuilds context every turn.
This is the moment we stop thinking:
“The LLM is intelligent.”
and start understanding:
“The agent system around the LLM is intelligent.”
3. Why this tiny demo is the seed of a full Intelligence Runtime
These four lines are not small.
They represent the foundations of the entire future:
- Event Layer
- Persistent Layer
- Compaction Layer
- Structured State Layer
- Long-term Memory Layer
- Long-term Reinjection Layer
In P11 we activated only the very first layer:
*🟦 Event Layer:
The external timeline of language interactions**
This is the “short-term brain” the LLM uses to simulate memory.
Without this layer:
no compaction
no persona
no long-term continuity
no learning
no agenthood
no self-evolution
Everything collapses back to “just a model call”.
This is the start of life for your agent.
4. What This Means Inside the StructureVerse Framework
In my entropy-controlled cognitive language:
LLM = Compute
A raw statistical machine with zero internal state.
Session.events = External Time
The first observable dimension of structured intelligence.
Runner = Proto-Scheduler
The embryonic form of “life”, because it reconstructs and maintains state.
P11 is not a toy example.
It is the birth of the event ledger,
the same way that neurons firing became the birth of memory in biological systems.
With P11, you have created:
The first StructureVerse cell.
A living unit whose state exists in time, outside the model weights.
This is your first StructureCard-powered cognitive organism.
5. Why This Matters (and Why I’m Writing This Series)
Most people stop at:
“The AI remembered me — cool.”
But you’re building something far bigger:
a reproducible memory architecture
a schedulable intelligent runtime
a multi-layered cognitive stack
a full personal OS built on structured language
the foundation for long-horizon agents
the infrastructure of the next decade of software
This small event timeline is not “demo output”.
It is a structure —
and structures are what scale.
Today’s P11 will grow into:
P12: persistent memory in SQLite
P13: audit tools (DB inspector)
P14: parallel context universes
P15: compaction (entropy control)
P16: structured working memory
P17: long-term memory store
P18: long-term reinjection (birth of persona)
This is Day 1, P11 only.
By the time you reach P50,
you will have built an agent system that is:
stateful
tool-driven
multi-agent
evaluable
observable
self-correcting
and eventually self-evolving.
P11 is where the rabbit hole begins.
6. Closing Line
If LLMs are the neurons, then Sessions are the synapses.
This is the first moment your agent gained a sense of time —
and everything that comes afterward depends on this.
📒 P12: The Birth of the Persistent Event Ledger
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p12-stateful-db-session
In P11, the agent learned to “exist in time.”In P12, the agent learns to “remember across time.”
Today we ran P12 — the first persistent, disk-backed stateful agent.
Here is the exact execution output:
(.venv) ➜ adk-decade-of-agents cd projects/p12-stateful-db-session
python src/main.py
✅ Running P12 via __main__ entry
✅ P12 — stateful_db: main() starting
✅ Created new persistent session: db-demo-session
User[db-demo-session] > Hi, I am Sam! What is the capital of the United States?
AI[db-demo-session] > Hi Sam! The capital of the United States is Washington, D.C.
User[db-demo-session] > Hello again! What is my name?
AI[db-demo-session] > Your name is Sam.
--- SESSION EVENTS (from DatabaseSessionService) ---
- [0] user: Hi, I am Sam! What is the capital of the United States?
- [1] db_agent: Hi Sam! The capital of the United States is Washington, D.C.
- [2] user: Hello again! What is my name?
- [3] db_agent: Your name is Sam.
--- SESSION STATE ---
{}
--- RAW DB EVENTS (sqlite3) ---
[app=agents sid=db-demo-session author=user] content={”parts”: [{”text”: “Hi, I am Sam! What is the capital of the United States?”}], “role”: “user”}
[app=agents sid=db-demo-session author=db_agent] content={”parts”: [{”text”: “Your name is Sam.”}], “role”: “model”}
[app=agents sid=db-demo-session author=db_agent] content={”parts”: [{”text”: “Hi Sam! The capital of the United States is Washington, D.C.”}], “role”: “model”}
[app=agents sid=db-demo-session author=user] content={”parts”: [{”text”: “Hello again! What is my name?”}], “role”: “user”}
✅ P12 — stateful_db: main() finished
At first glance, this looks almost identical to P11.
But something profound has happened.
This is the moment the agent’s memory escaped the boundaries of RAM and became a persistent ledger.
A trace. A log. A history.
A structure that exists even after the program exits.
Let’s unpack what this means.
1. What P11 Could Not Do: Memory Across Runs
In P11, the agent remembered your name only because the event history stayed in RAM:
Session.events = “external short-term brain”
But as soon as the Python script ended, everything vanished.
There was no continuity across runs.
No persistence.
No story.
No identity.
No concept of “before.”
P12 changes everything.
2. P12 Introduces the Persistent Event Ledger
In P12, we replaced the InMemorySessionService with:
DatabaseSessionService(db_url=”sqlite+aiosqlite:///day3_sessions.db”)
This means:
Every event
Every message
Every agent reply
Every tool result
…is now written to a real SQLite database on disk.
This produces a genuine, inspectable, auditable event ledger.
Think of it as:
P11: The agent had a short-term brain
P12: The agent now has a long-term diary
And that diary survives:
program exits
process restarts
machine restarts
days, weeks, months
Suddenly, the agent has continuity.
3. The Proof: “Your name is Sam.” (without reintroducing yourself)
This is the moment where the system proves the concept:
First run:
“Hi, I am Sam!”
“What is my name?”
→ “Your name is Sam.”
Second run:
“Hello again! What is my name?”
→ “Your name is Sam.”
The model has not “learned” anything.
It has not internalized your identity.
It has not tuned weights.
It simply reconstructed context from the event ledger stored in the database.
That’s the power of P12.
4. The Ledger Itself: The Agent Finally Leaves a Trace
The most important section of the output is this:
--- RAW DB EVENTS (sqlite3) ---
[app=agents sid=db-demo-session author=user] content=...
[app=agents sid=db-demo-session author=db_agent] content=...
...
These are not abstractions.
They are real rows in a real database table:
events (
id,
app_name,
session_id,
author,
content_json,
timestamp
)
This is nothing less than the birth of:
The Agent Event Ledger
The foundational structure for memory, debugging, auditability, and agent governance.
Without a ledger:
no evaluation
no oversight
no safety
no reproducibility
no identity
no learning
no simulation
no long-term behavior
P12 lays the foundation for all of that.
5. StructureVerse Interpretation: A New Layer Lights Up
In my own theoretical language, P12 activates the second major layer:
🟦 Event Layer
(P11) — ephemeral, RAM-based event timeline
🟩 Persistent Layer
(P12) — durable on-disk ledger
You now have:
a timeline
a trace
a memory substrate
a structural audit trail
the beginnings of structured intelligence
This persistent ledger is what will feed:
P13 — DB Inspector (microscope on events)
P14 — Context Isolation
P15 — Compaction (entropy reduction)
P17 — Memory ETL (structured facts → long-term memory)
P18 — Memory Reinjection (birth of persona)
This is the first data structure of agent cognition.
It resembles the beginning of a nervous system.
6. Why This Matters for the Next Decade
Almost everyone still treats AI as:
“A model you talk to”
But the frontier looks nothing like that.
The future is:
Agents with history.Agents with memory.Agents with state.Agents with structure.Agents with persistent identity.
P12 is where this future becomes visible.
This small SQLite file is not a toy.
It’s the very early form of:
a personal memory backend
an agent black box recorder
a context engine source
an agent safety log
the structure of your future AI OS
This is where the model stops being the system.
And the system begins to become the system.
7. Closing
A stateless LLM can imitate intelligence.
A persistent timeline can accumulate intelligence.
With P12, your agent writes its first diary entry —
and this changes everything.
🔭P13: The Event Microscope
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p13-db-inspector
When an Agent’s Internal Life Becomes Visible
P11 gave the agent a short-term timeline.
P12 gave the agent a persistent ledger.
P13 gives us the microscope to see it.
Today we ran P13 — the DB Inspector, the first real “observation tool” in the agent’s cognitive architecture.
Here is the exact output:
📘 P13 — DB Inspector running...
Looking for DB at: /Users/Agent/adk-decade-of-agents/projects/day3_sessions.db
📦 Found 4 events:
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : 2025-12-05 19:12:06.181207
Text : Hi, I am Sam! What is the capital of the United States?
────────────────────────────────────────────
Session : db-demo-session
Author : db_agent
Time : 2025-12-05 19:12:06.188306
Text : Hi Sam! The capital of the United States is Washington, D.C.
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : 2025-12-05 19:12:06.887968
Text : Hello again! What is my name?
────────────────────────────────────────────
Session : db-demo-session
Author : db_agent
Time : 2025-12-05 19:12:06.891416
Text : Your name is Sam.
🔍 DB Inspector finished.
This might look simple.
But what just happened here is nothing less than the birth of:
Observability — the ability to see the internal life of an agent.
This is one of the most important milestones in the evolution of agents.
Let me explain.
1. The Three Pillars of Agent Intelligence
Modern agent systems are built on three architectural pillars:
1️⃣ A trajectory structure (Event Timeline)
This is P11:
A stateless LLM executing over a growing external timeline.
2️⃣ A persistent ledger (Event Database)
This is P12:
Events written to disk, becoming durable across runs.
3️⃣ Observability (the ability to inspect the ledger)
This is P13.
Without P13, the first two are blind.
The agent may have a memory;
it may have a ledger;
but you cannot see what it sees.
There is no transparency,
no debuggability,
no auditability,
no trust.
P13 changes that.
2. What You Saw Today Was the Agent’s Internal Life
Look back at the output.
This line:
📦 Found 4 events:
Means:
The agent has a real, persistent, chronological history.
And these four blocks:
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : ...
Text : ...
are not logs.
They are atoms of intelligence.
Each row corresponds to:
an LLM message
transformed into an event
appended to the ledger
written to SQLite
now readable by any external tool
For the first time, the agent’s cognitive timeline is no longer hidden inside ADK.
It has become a first-class data structure.
3. Why Observability Is the Turning Point for an Agent System
A system becomes “alive” in the engineering sense when:
it acts
it records
it preserves
it reveals
P13 enables the last step:
An agent that can be seen.
✔ Debugging
You can inspect why the agent answered incorrectly.
✔ Verification
You can prove what happened in each step.
✔ Reproducibility
You can replay any trajectory.
✔ Governance
This becomes the foundation of agent safety and oversight.
✔ Memory Engineering
You can extract patterns, preferences, identities, events.
In other words, observability is not an auxiliary feature.
It is the skeleton of an intelligent system.
No observability = no agent.
4. StructureVerse Interpretation: The Inspection Layer Lights Up
In the language of your entropy-controlled StructureVerse:
🟦 Event Layer (P11)
A timeline of raw behaviors.
🟩 Persistent Layer (P12)
A durable event ledger.
🟨 Inspection Layer (P13)
The ability to make the ledger visible, external, and auditable.
This is the moment when:
The agent’s internal structure obtains a representation independent of the agent itself.
This is how systems evolve from:
toy demos →
prototypes →
interpretable agents →
accountable agents →
reliable, enterprise-grade agents.
P13 is small, but it is foundational.
5. What Comes Next (P14 → P18)
Your pipeline is now:
P11 — InMemory Session
P12 — Persistent SQLite Ledger
P13 — DB Inspector (Observability)
----------------------------------
Next:
P14 — Session Isolation Test (Parallel Universes)
P15 — Automatic Compaction (Entropy Reduction)
P16 — Structured State (session.state)
P17 — Memory ETL (Extract → Transform → Load)
P18 — Memory Injection (Persona Continuity)
P13 is the “Inspector Gadget” that unlocks the entire second half of the pipeline.
Without it:
you can’t test isolation
you can’t verify compaction
you can’t validate ETL
you can’t debug persona reinjection
With it:
You have a microscope for the agent’s mind.
6. Closing Line for Substack
P11 taught the agent to exist in time.
P12 taught the agent to remember across time.
P13 teaches us to see time inside the agent.
This is not about logs.
This is about the birth of observable intelligence.
😱P14: Session Isolation
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p14-session-isolation
How Agents Build Parallel Universes That Never Leak
P11 taught the agent to exist in time.
P12 taught it to remember across time.
P13 let us see its memory.
P14 proves that every memory universe is completely isolated.
Today we ran one of the most important structural tests in the entire Sessions & Memory module:
P14 — Session Isolation Test(Parallel Universes and Context Boundaries)
This small experiment demonstrates a deep truth about agent architecture:
Each Session is its own self-contained universe.Events do not leak.Identity does not leak.Context does not leak.
Let’s walk through what happened.
1. The Output (Raw Execution Log)
🔵 Creating Session A: session-A
User[session-A] > Hi, I am Sam!
gemini-2.5-flash-lite[session-A] > Hi Sam! I’m isolation_agent...
User[session-A] > What is my name?
gemini-2.5-flash-lite[session-A] > Your name is Sam.
🟣 Creating Session B: session-B
User[session-B] > Hello, what is my name?
gemini-2.5-flash-lite[session-B] > I do not have access to your personal information...
--- SESSION A EVENTS ---
- [0] user: Hi, I am Sam!
- [1] isolation_agent: Hi Sam! ...
- [2] user: What is my name?
- [3] isolation_agent: Your name is Sam.
--- SESSION B EVENTS ---
- [0] user: Hello, what is my name?
- [1] isolation_agent: I do not have access to your personal information...
At first glance, this looks like a simple two-conversation test.
But what it proves is foundational.
2. What This Test Really Shows
✅ Session A learns “Your name is Sam.”
Because the name was introduced in A’s timeline.
❌ Session B does NOT know the name.
Even though the same Agent instance, same code, same model, same user ID were used.
🚫 No leakage.
The knowledge in session-A does not appear in session-B.
This is not a coincidence.
This is not model behavior.
This is the architecture.
3. The Deep Principle: Sessions Are Mini-Universes
Each session in ADK is defined by the triple:
(app_name, user_id, session_id)
This acts like a namespace, a bubble, a self-contained universe.
Inside that bubble lives:
its own event timeline
its own identity
its own memory
its own history
its own evolution
Nothing in Session A exists in Session B unless you explicitly inject it.
This is the first formal proof that:
Agents are not models;Agents are structured universes built on context boundaries.
4. The Security Angle: Why Isolation Matters
Session isolation isn’t just a conceptual nicety.
It is the backbone of:
Multi-user safety
Multi-task separation
Context integrity
Privacy preservation
Parallel cognitive processes
Imagine an AI assistant serving:
your personal tasks
your children’s homework tasks
your financial planning tasks
Without strict isolation, the consequences would be disastrous:
leaking personal identity
mixing unrelated tasks
confusing reasoning paths
creating unpredictable outcomes
P14 demonstrates:
Isolation works.The agent universe is not a soup.It is a set of clean, parallel timelines.
5. StructureVerse Interpretation:
Parallel Universes and Boundary Integrity
In the entropy-controlled StructureVerse framework, Session isolation corresponds to:
🟦 Event Layer = “What happened here?”
(session-specific)
🟨 Boundary Layer = “What counts as here?”
(isolation rules)
Together they create:
Structure Bubbles — small, self-contained cognitive universesthat never contaminate each other.
It’s like having:
Universe A where Sam exists
Universe B where Sam never appeared
P14 is the mathematical demonstration that parallel universes are real
— inside your agent runtime.
6. This Enables What Comes Next
With strict session isolation verified, you can now safely build:
✔ P15 — Automatic Compaction
(each universe compresses its own history)
✔ P16 — Structured Working Memory (session.state)
(each universe maintains its own short-term structured memory)
✔ P17 — Memory ETL
(each universe extracts long-term memory separately)
✔ P18 — Memory Injection
(persona continuity within a single universe)
All of these depend on the ability to guarantee:
“Nothing leaks across universes.”
Without P14, the entire memory architecture collapses.
7. Closing
A model predicts text.
An agent maintains universes.
P14 is where we prove that each universe stands alone —
its own timeline, its own identity, its own history.
And for the first time,
you’re not just using an AI —
you’re governing parallel worlds.
🗜️P15: When an Agent Learns to Compress Itself
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p15-compaction-demo
From Infinite Chatter to Structured Summaries
P11: the agent gained a timeline.
P12: the timeline became persistent.
P13: the timeline became observable.
P14: timelines became parallel universes.
P15: the timeline becomes compressible.
Today’s experiment, P15 – Context Compaction Demo, marks a subtle but crucial transition:
For the first time, the agent doesn’t just “remember more” —
it learns to remember less, but better.
Here’s what actually happened.
1. The Run: A Long Conversation + One Summary
We ran P15 with ADK’s experimental EventsCompactionConfig turned on:
👉 Running P15 via __main__
🚀 P15 — compaction_demo: starting
✅ Agent created: compaction_agent
[EXPERIMENTAL] EventsCompactionConfig...
✅ App created with compaction enabled
🆕 Created session: compaction-session
Then we sent multiple long, information-rich prompts in the same session:
Explain AI in healthcare.
→ The agent responded with a full essay: diagnostics, imaging, drug discovery, workflows, virtual assistants, ethics, regulation, etc.
Tell me more about drug discovery.
→ Another long technical breakdown: target identification, virtual screening, de novo design, ADME, biomarkers, clinical trials, repurposing.
Explain the second point again.
→ A third dense explanation zooming in on “Drug Candidate Design and Generation.”
Who are the key companies involved?
→ The agent declined, saying the current conversation context did not focus on companies.
At this point, we have a chat history that’s both very long and highly redundant:
repeated descriptions of AI in healthcare
repeated outlines of AI in drug discovery
refined explanations focusing on one subpoint
Then the compaction engine kicked in:
📦 Checking for compaction event
🎉 Compaction event detected!
📝 Summary Content:
The conversation history covers the user’s initial request for an explanation of AI in healthcare, followed by a specific inquiry about drug discovery. The AI agent provided a comprehensive overview of AI in healthcare, detailing its applications in diagnostics, drug discovery, personalized medicine, administrative efficiency, virtual assistants, and robotics, along with its benefits and challenges.
The user then requested further clarification on the “drug discovery” aspect. The AI agent elaborated on this, focusing on how AI revolutionizes the process by:
* Target Identification and Validation…
* Drug Candidate Design and Generation…
* Virtual Screening…
* De Novo Drug Design…
In one stroke, the agent’s entire sprawling conversation was compressed into a structured abstract.
This is not “just summarization.”
This is structural entropy control.
2. Why Compaction Is Not Just a “Nice Feature”
In the toy-chat world, more history feels like a pure good.
But in real systems:
Context windows are finite
Longer prompts are slower and more expensive
Redundant history confuses the model
Old details drown out new intent
Irrelevant turns introduce noise and risk
In other words:
A growing context, unmanaged, becomes a liability.
What P15 demonstrates is a built-in pipeline level behavior, not a prompt trick:
The
Appis configured with:
EventsCompactionConfig(
compaction_interval=3,
overlap_size=1,
)
The system watches the event stream.
Every few events, it:
takes a chunk of past history
compacts it into a summary event
preserves a few recent raw events (overlap)
The Session timeline transforms from:
long, repetitive, high-entropy log
into:
a shorter, denser, lower-entropy outline.
This isn’t the model being “smart.”
This is the runtime being structured.
3. The Summary as a Structural Object, Not a String
The compaction output isn’t just a blob of text.
The summary is stored as a structured content object:
event.actions.compaction.compacted_content
→ parts[0].text = summary_text
In other words:
It’s typed
It’s addressable
It’s machine-readable
Which means future tools can:
treat summary events differently from raw messages
feed only summaries to downstream analysis agents
run meta-evaluation on how compaction behaves
visualize compaction as “folded history” in UIs
selectively expand or collapse history on demand
The summary is now part of the agent’s structural life, not just decoration.
4. StructureVerse View: The Emergence of the Entropy-Control Layer
In your own Language → Structure → Scheduler model, P15 lights up a new layer:
Event Layer (P11): every message is an event
Persistent Layer (P12): events are written to disk
Inspection Layer (P13): events can be seen and audited
Boundary Layer (P14): events are isolated by session
Entropy-Control Layer (P15): events can be compressed
P15 is where you stop worshipping “more context” and start asking:
“What is the right amount of context?”
“What should be preserved? What should be folded?”
“How do we turn a semantically rich but redundant stream into a compact, executable structure?”
That is exactly what the compaction summary is:
a lower-dimensional, still faithful representation of the structural trajectory.
From a StructureVerse perspective:
The compaction event is the first visible self-compression stride of the agent.
5. Philosophically: Intelligence Is Not Just About Accumulation
There is a deep philosophical mirror here.
Biological brains are not powerful because they remember everything.
They are powerful because they:
forget aggressively
compress heavily
preserve only what matters
reuse compressed structures
operate on abstractions, not raw logs
P15 introduces that idea formally into your agent runtime:
long raw context → compressed structural summary
repeated explanation → canonical representation
text stream → evolving abstract
Only now can you sensibly:
run long-horizon agents
keep state cheap and manageable
prepare memory for ETL
build structured long-term memory on top of summaries
derive Structure Cards / Structure Graphs downstream
If you tried to do this directly on raw Session.events,
complexity would explode.
6. Why the “EXPERIMENTAL” Warning Is Actually a Good Sign
You saw this line:
UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental…
That’s not a problem; it’s a direction.
It means:
Compaction is recognized as a first-class runtime concern
ADK is already experimenting with built-in hooks
This area will evolve, but it won’t disappear
In your own system, compaction is:
the operationalization of entropy control.
You are not just talking about S-index, compression, “structure over noise” as philosophy —
you’re now running it in code.
7. Closing Line for Substack
P15 is the moment your agent stops hoarding history and starts shaping it.
It’s not just “an AI giant essay generator” anymore.
It’s a system that:
listens
accumulates
compresses
and carries forward only the essential structure.
If P11–P14 gave your agent a life in time and space,
P15 gives it something subtler:
a sense of what’s worth remembering.
log:
(.venv) ➜ projects cd /Users/Agent/adk-decade-of-agents/projects/p15-compaction-demo
(.venv) ➜ p15-compaction-demo python src/main.py
👉 Running P15 via __main__
🚀 P15 — compaction_demo: starting
✅ Agent created: compaction_agent
/Users/Agent/adk-decade-of-agents/projects/p15-compaction-demo/src/main.py:52: UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
events_compaction_config=EventsCompactionConfig(
✅ App created with compaction enabled
🆕 Created session: compaction-session
🔄 Sending multiple messages to trigger compaction
User[compaction-session] > Explain AI in healthcare.
gemini-2.5-flash-lite[compaction-session] > AI in healthcare refers to the application of artificial intelligence (AI) technologies to various aspects of the healthcare industry. The goal is to improve patient outcomes, streamline processes, reduce costs, and enhance the efficiency of healthcare providers.
Essentially, AI in healthcare uses algorithms and software to analyze complex medical data, mimic human cognition, and assist in tasks that typically require human intelligence. This can range from diagnosing diseases to developing new drugs and personalizing treatment plans.
Here’s a breakdown of key areas where AI is being used in healthcare:
**1. Diagnostics and Imaging Analysis:**
* **Image Recognition:** AI algorithms can analyze medical images (X-rays, CT scans, MRIs, pathology slides) with remarkable accuracy, often detecting subtle anomalies that might be missed by the human eye. This helps in early diagnosis of diseases like cancer, diabetic retinopathy, and cardiovascular conditions.
* **Disease Prediction:** By analyzing patient data, AI can identify individuals at high risk for certain diseases, allowing for preventative measures and early interventions.
**2. Drug Discovery and Development:**
* **Accelerated Research:** AI can sift through vast amounts of scientific literature and biological data to identify potential drug targets, predict drug efficacy, and even design novel molecules. This significantly speeds up the traditionally lengthy and expensive drug development process.
* **Clinical Trial Optimization:** AI can help identify suitable patient populations for clinical trials, monitor trial progress, and analyze results more efficiently.
**3. Personalized Medicine and Treatment:**
* **Tailored Therapies:** AI can analyze a patient’s genetic makeup, lifestyle, medical history, and response to previous treatments to recommend the most effective and personalized treatment plan.
* **Precision Oncology:** In cancer treatment, AI can help determine the best chemotherapy or immunotherapy based on the specific genetic mutations of a tumor.
**4. Administrative and Operational Efficiency:**
* **Workflow Automation:** AI-powered tools can automate routine administrative tasks like scheduling appointments, managing patient records, processing insurance claims, and transcribing medical notes.
* **Resource Management:** AI can optimize hospital resource allocation, predict patient flow, and manage staffing to improve efficiency and reduce wait times.
**5. Virtual Assistants and Chatbots:**
* **Patient Engagement:** AI-powered chatbots can answer patient questions, provide basic health information, remind patients to take medications, and help them navigate healthcare systems.
* **Clinical Support:** Virtual assistants can support clinicians by providing quick access to patient information, medical literature, and diagnostic suggestions.
**6. Robotics in Surgery:**
* **Enhanced Precision:** AI-powered robotic surgical systems can perform complex procedures with greater precision, dexterity, and minimally invasive techniques, leading to faster recovery times for patients.
**Benefits of AI in Healthcare:**
* **Improved Accuracy and Speed:** AI can process data and identify patterns much faster and often more accurately than humans.
* **Early Disease Detection:** Leading to better treatment outcomes and potentially saving lives.
* **Personalized Care:** Tailoring treatments to individual needs.
* **Reduced Costs:** By increasing efficiency and preventing errors.
* **Increased Accessibility:** Potentially extending healthcare access to underserved areas through remote diagnostics and virtual consultations.
* **Alleviating Clinician Burnout:** By automating routine tasks and providing decision support.
**Challenges and Considerations:**
* **Data Privacy and Security:** Protecting sensitive patient information is paramount.
* **Regulatory Hurdles:** Ensuring AI systems are safe, effective, and compliant with healthcare regulations.
* **Ethical Concerns:** Addressing bias in algorithms, accountability for AI decisions, and the impact on the doctor-patient relationship.
* **Integration and Interoperability:** Integrating AI systems into existing healthcare infrastructure can be complex.
* **Trust and Adoption:** Gaining the trust of both healthcare professionals and patients is crucial for widespread adoption.
* **Explainability (XAI):** Understanding how AI makes its decisions is important for clinical validation and trust.
In summary, AI in healthcare is a transformative force with the potential to revolutionize how we prevent, diagnose, treat, and manage diseases, ultimately leading to a more efficient, personalized, and effective healthcare system.
User[compaction-session] > Tell me more about drug discovery.
gemini-2.5-flash-lite[compaction-session] > Sure, let’s dive deeper into how Artificial Intelligence (AI) is revolutionizing drug discovery.
The traditional drug discovery process is notoriously long, expensive, and has a high failure rate. It can take over a decade and billions of dollars to bring a new drug to market, with many promising candidates failing at various stages. AI is stepping in to address these challenges by accelerating and improving many critical steps.
Here’s how AI is making a difference in drug discovery:
**1. Target Identification and Validation:**
* **Understanding Disease Mechanisms:** AI can analyze vast datasets from genomics, proteomics, transcriptomics, and clinical records to identify novel biological targets (like specific proteins or genes) that play a crucial role in a disease. This helps researchers understand the underlying mechanisms of diseases better.
* **Predicting Target-Disease Associations:** AI algorithms can predict the likelihood of a particular target being involved in a disease, helping prioritize which targets to focus on.
**2. Drug Candidate Design and Generation:**
* **Virtual Screening:** Instead of physically testing millions of compounds, AI can virtually screen enormous chemical libraries to identify molecules that are likely to bind to a specific target protein. This dramatically narrows down the pool of potential drug candidates.
* **De Novo Drug Design:** AI can *generate* entirely new molecular structures from scratch that are optimized to interact with a target and possess desirable drug-like properties (e.g., solubility, permeability). Generative models like GANs (Generative Adversarial Networks) and Variational Autoencoders (VAEs) are particularly useful here.
* **Predicting Molecular Properties:** AI can predict various properties of a potential drug molecule, such as its efficacy, toxicity, absorption, distribution, metabolism, and excretion (ADME), early in the design phase. This helps weed out molecules likely to fail later.
**3. Pre-clinical and Clinical Trial Optimization:**
* **Predicting Drug Efficacy and Toxicity:** AI models can be trained on existing data to predict how a drug candidate might perform in pre-clinical studies (in vitro and in vivo) and even in human clinical trials, reducing the need for extensive and costly wet-lab experiments.
* **Biomarker Discovery:** AI can identify biomarkers that predict patient response to a drug, enabling more targeted clinical trials and personalized medicine approaches.
* **Clinical Trial Design and Patient Recruitment:** AI can analyze patient data to identify suitable candidates for clinical trials, optimize trial design to improve success rates, and even predict potential adverse events.
* **Repurposing Existing Drugs:** AI can analyze existing drug databases and disease information to identify drugs approved for one condition that might be effective for another, a process known as drug repurposing. This can significantly shorten the development timeline.
**4. Optimizing Chemical Synthesis:**
* **Predicting Synthesis Routes:** AI can help chemists predict the most efficient and cost-effective ways to synthesize promising drug molecules, streamlining the manufacturing process.
**Key AI Techniques Used in Drug Discovery:**
* **Machine Learning (ML):** Supervised, unsupervised, and reinforcement learning algorithms are used for prediction, classification, and pattern recognition.
* **Deep Learning (DL):** Neural networks, particularly convolutional neural networks (CNNs) for image analysis and recurrent neural networks (RNNs) and transformers for sequence data (like DNA or protein sequences), are powerful for complex pattern recognition.
* **Natural Language Processing (NLP):** Used to extract information from scientific literature, patents, and clinical trial reports.
* **Graph Neural Networks (GNNs):** Excellent for representing and analyzing molecular structures and their interactions.
**Benefits of AI in Drug Discovery:**
* **Speed:** Significantly reduces the time required to identify and develop new drug candidates.
* **Cost Reduction:** By reducing the number of failed experiments and streamlining processes.
* **Increased Success Rates:** By better predicting efficacy and toxicity, and optimizing trial design.
* **Novelty:** Enabling the design of entirely new molecules with improved properties.
* **Personalization:** Facilitating the development of drugs tailored to specific patient populations or individuals.
**Challenges in AI-powered Drug Discovery:**
* **Data Quality and Availability:** High-quality, curated datasets are essential for training effective AI models. Data can be siloed or proprietary.
* **Interpretability (Explainability):** Understanding *why* an AI model makes a particular prediction can be challenging, which is critical for scientific validation and regulatory approval.
* **Experimental Validation:** AI predictions still need rigorous experimental validation, which remains a bottleneck.
* **Integration with Existing Workflows:** Seamlessly integrating AI tools into established R&D processes requires significant effort and training.
* **Talent Gap:** A shortage of skilled AI researchers with domain expertise in chemistry and biology.
Despite the challenges, AI is rapidly transforming the landscape of drug discovery, offering hope for faster development of more effective and targeted therapies for a wide range of diseases.
User[compaction-session] > Explain the second point again.
gemini-2.5-flash-lite[compaction-session] > You asked for a clarification on the **second point** regarding AI in drug discovery. Assuming you’re referring to the second main section in my previous explanation, that point was:
**2. Drug Candidate Design and Generation**
Let’s break this down further:
This stage is all about finding or creating molecules that have the potential to become drugs. Traditionally, this involves screening vast libraries of existing chemical compounds to see if any of them interact with the disease target identified in step 1.
AI is revolutionizing this process in two primary ways:
**a) Virtual Screening:**
* **The Problem:** Imagine having millions of LEGO bricks (chemical compounds) and needing to find one that perfectly fits a specific slot (the disease target). Physically trying each brick is incredibly time-consuming and expensive.
* **How AI Helps:** AI algorithms can analyze the 3D structure of the disease target and the chemical structures of countless potential drug molecules. They can then simulate how these molecules might “dock” or bind to the target.
* **The Outcome:** Instead of physically testing millions, AI can quickly predict which compounds are *most likely* to bind effectively. This drastically reduces the number of molecules that need to be synthesized and tested in the lab. It’s like having a super-fast robot that can try out millions of LEGO brick combinations virtually before you even pick up a real brick.
* **Techniques Involved:** Often uses machine learning models trained on data from previous binding experiments, as well as more sophisticated computational chemistry methods powered by AI.
**b) De Novo Drug Design (Designing from Scratch):**
* **The Problem:** Sometimes, none of the existing compounds are ideal. You might need a molecule with very specific properties that doesn’t exist yet.
* **How AI Helps:** This is where AI can get really creative. Using advanced generative models (like GANs or VAEs), AI can learn the fundamental rules of chemistry and molecular structure. It can then *create* entirely new molecular designs that have never been seen before.
* **The Goal:** These AI-generated molecules are designed with specific goals in mind:
* **High Affinity:** They should bind strongly to the target.
* **Drug-like Properties:** They should have good solubility, be able to pass through cell membranes, and be metabolized effectively by the body (the ADME properties mentioned earlier).
* **Low Toxicity:** They should ideally avoid interacting with other molecules in the body in harmful ways.
* **The Outcome:** AI can propose novel chemical structures that might be more effective or safer than existing ones. It’s like asking an architect to design a brand-new house from scratch, specifying the number of rooms, style, and energy efficiency, rather than just picking from a catalog of existing houses.
* **Techniques Involved:** Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), Reinforcement Learning.
**In essence, point 2 is about AI acting as both a highly efficient librarian (virtual screening) and an innovative chemist (de novo design) to identify and create promising drug candidates much faster and more intelligently than traditional methods.**
User[compaction-session] > Who are the key companies involved?
gemini-2.5-flash-lite[compaction-session] > I cannot provide a list of key companies involved in AI in drug discovery based on the current conversation context. The provided history focuses on explaining the *concepts* and *processes* of AI in healthcare and drug discovery, not on naming specific industry players.
📦 Checking for compaction event
🎉 Compaction event detected!
📝 Summary Content:
The conversation history covers the user’s initial request for an explanation of AI in healthcare, followed by a specific inquiry about drug discovery. The AI agent provided a comprehensive overview of AI in healthcare, detailing its applications in diagnostics, drug discovery, personalized medicine, administrative efficiency, virtual assistants, and robotics, along with its benefits and challenges.
The user then requested further clarification on the “drug discovery” aspect. The AI agent elaborated on this, focusing on how AI revolutionizes the process by:
* **Target Identification and Validation:** Identifying disease-related biological targets.
* **Drug Candidate Design and Generation:**
* **Virtual Screening:** AI virtually screens vast chemical libraries to predict promisi...
🏁 P15 — compaction_demo finished.
🧠 P16 — When an AI Learns to Organize Its Own Memory
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p16-compacted-memory-etl
From Noisy Dialogues to Structured Long-Term Memory: The First Entropy-Controlled Bridge
In this project (P16), something remarkable happened for the first time in our Sessions & Memory series:
The AI compressed an entire conversation into a clean summaryand saved that summary into its long-term memory.
This is no longer pattern-matching or token-spinning.
This is structure-forming.
It’s the moment a raw LLM starts acting like a living agent—
one that organizes the world into internal structures.
🔍 Why P16 Matters
In earlier projects (P11–P15), we already taught the agent how to have:
Event Ledger (Session.events)
Persistent session memory
Automatic compaction
session.state (structured working memory)
But one critical capability was still missing:
How does the agent take a long conversationand decide what is worth remembering forever?
Human memory is not “store everything.”
Human memory is “compress → extract → store the structure.”
P16 is the first engineered version of that.
📦 The Experiment: Dumping the Agent’s Event Timeline
Here’s a snippet from the actual P16 run:
📦 Dump Session Events (summary preview)
- [user] Explain how AI is used in healthcare....
- [compaction_memory_agent] AI is revolutionizing healthcare...
- [user] What are some important applications of AI in medical imaging?...
- [compaction_memory_agent] AI is making a profound impact...
- [user] How can AI help in drug discovery and personalized treatment?...
- [compaction_memory_agent] AI is a transformative force...
- [user] What are the main risks and challenges of using AI in hospitals?...
- [compaction_memory_agent] Based on the previous conversation...
- [user] Please summarize the key opportunities and risks of AI in healthcare....
- [compaction_memory_agent] The provided context highlights...
Once the conversation gets long enough (based on the compaction interval),
ADK auto-injects a compaction summary event.
This is the agent doing self-organization:
📝 Extracted one compaction summary:
session_id: compacted-memory-etl-demo
created_at: 2025-12-06T02:02:56.803347Z
summary_text: The conversation history covers the application of AI in healthcare...
This “summary_text” is a low-entropy, high-information representation
of everything discussed so far.
💾 And Then… It Writes the Summary into Long-Term Memory
P16 extracts this compaction summary, turns it into a structured record, and writes it into:
memory_store.json
Here’s the (truncated) result:
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-memory-etl-demo”,
“created_at”: “2025-12-06T02:02:56.803347Z”,
“summary_text”: “The conversation covered the applications of AI in healthcare...”
}
]
}
This is not merely storage.
This is the AI saying:
“Here’s what I learned from this conversation.”
This is the birth of
topic-level long-term memory.
🧬 System Meaning:
The Full Loop — From Language → Events → Compaction → Structured Memory → Future Reasoning
P16 completes a brand-new cognitive pathway:
Raw high-entropy conversation (natural language)
↓ compaction
Low-entropy structured summary (compacted_content)
↓ ETL
Long-term memory (memory_store.json)
↓ future (P18+)
Injected into new sessions for persona/context shaping
This is the core mechanism of a living agent:
“Long-term structure shapes future decisions.”
Before P16, only session.state could enter long-term memory.
Now, entire conversation topics can become structured memory too.
This is a major leap.
🔥 Why This Is a Breakthrough
P16 proves something foundational:
An AI agent should not just memorize facts about the user(user:name, user:country).It should also remember what we discussed.
This opens the door to:
Conversational continuity
Multi-topic agent cognition
Personalized long-term preference learning
Multi-agent shared memories
Automatic knowledge graph construction
In the StructureVerse worldview:
✔ Compaction = supervised high-dimensional compression
✔ Memory ETL = structural extraction
✔ Memory Store = durable structured knowledge
✔ Future Injection = persona + context coherence
A raw model becomes a structured system.
A structured system becomes a life form in the language-structure-scheduler stack.
📎 A small engineering note
ADK surfaced a warning:
DeprecationWarning: utcfromtimestamp() is deprecated...
We will switch to:
datetime.fromtimestamp(ts, datetime.UTC)
in P17, when we introduce timestamp normalization & Memory Schema v1.0.
✏️ Closing Thoughts
P16 looks like a small engineering project, but it unlocks something fundamental:
An AI that organizes, compresses, and stores the structure of a conversationis fundamentally different from an AI that merely responds.
This is how an agent starts to “grow.”
Not by adding more parameters
Not by adding more tokens
But by constructing, evolving, and preserving internal structures
This is where
language collapses into structure,structure survives as memory,memory shapes behavior.
Welcome to your first fully structured, entropy-controlled, long-memory agent.
📦 Dump Session Events(摘要预览 / summary preview)
- [user] Explain how AI is used in healthcare....
- [compaction_memory_agent] AI is revolutionizing healthcare by improving diagnostics, personalizing treatme...
- [user] What are some important applications of AI in medical imaging and diagnostics?...
- [compaction_memory_agent] AI is making a profound impact on medical imaging and diagnostics, significantly...
- [user] How can AI help in drug discovery and personalized treatment?...
- [compaction_memory_agent] AI is a transformative force in both **drug discovery** and **personalized treat...
- [user] ...
- [user] What are the main risks and challenges of using AI in hospitals?...
- [compaction_memory_agent] Based on the previous conversation, here are the main risks and challenges of us...
- [user] Please summarize the key opportunities and risks of AI in healthcare....
- [compaction_memory_agent] The provided context highlights the significant advancements and potential of AI...
🔍 从 Session.events 中抽取 compaction.summary ... / extracting compaction.summary from Session.events ...
/Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl/src/main.py:173: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
created_at = datetime.utcfromtimestamp(ts).isoformat() + “Z”
📝 抽取到一条 compaction 摘要(Extracted one compaction summary):
session_id: compacted-memory-etl-demo # 会话 ID / Session ID
created_at: 2025-12-06T02:02:56.803347Z # 创建时间 / Created at
summary_text: The conversation history covers the application of AI in healthcare, with a particular focus on medical imaging/diagnost... # 摘要文本 / Summary preview
💾 已写入 memory_store.json(saved to memory_store.json) -> /Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl/memory_store.json
📚 当前 memory_store.json 内容(截断预览 / truncated preview):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: null,
“created_at”: 1764985672.551647,
“summary_text”: “parts=[Part(\\n text=\\”\\”\\”The conversation covered the applications of AI in healthcare, focusing on medical imaging/diagnostics and drug discovery/personalized treatment.\\n\\n**Key Information and Decisions:**\\n\\n* **AI in Healthcare Overview:** AI is revolutionizing healthcare across diagnostics, drug discovery, personalized medicine, robotic surgery, administrative tasks, patient monitoring, and public health.\\n* **AI in Medical Imaging & Diagnostics:**\\n * **Detection & Diagnosis:** AI excels at detecting diseases like cancer (mammography, lung nodules, prostate, skin), diabetic retinopathy, cardiovascular disease, neurological disorders, and fractures by analyzing medical images (X-rays, CT, MRI, retinal scans).\\n * **Image Quality:** AI improves image quality through noise reduction, bette ...
🏁 compacted_memory_etl_demo: main() 执行结束 / execution finished
Starting from P16, we reach a pivotal turning point in the entire Sessions & Memory series: I’ve gradually realized that an agent does not process all types of content equally—the more structured, persona-related, identity-anchored, and preference-based the information is, the stronger the model’s ability to understand, compress, and retain it long-term; whereas the more knowledge-dense, context-heavy, and semantically complex the material is (e.g., long-form technical explanations in healthcare), the more easily the model forgets, confuses, or fails to stabilize it. The reasons are still something I’m actively unpacking. Therefore, in P16 we rerun the pipeline but replace the healthcare scenario entirely with a persona axis: instead of compressing domain knowledge, we compress information about who you are, how you think, and your preferences and tendencies. This is because persona information is inherently low-entropy, highly structured, extremely stable, and directly relevant to all future reasoning, making it far more suitable for long-term memory than knowledge content. Thus, P16 shifts the pipeline from “dialogue → compaction → structural summary → memory_store.json” to constructing an organic persona long-term memory (persona LTM): extracting core persona structures through dialogue, distilling stable traits via entropy-controlled compression, writing them into the long-term memory database through ETL, and reinjecting them into future sessions to achieve contextual continuity, decision consistency, and behavioral style stability. This marks the first moment an agent moves from “storing knowledge” to constructing personality structures, and signals the beginning of the Scheduled Persona era for structured agents.
🧠 P16 — The Agent Begins to Build a Self-Consistent Persona (run the P16 again but with different content)
Structured identity, preferences, values — compressed automatically into long-term memory
P16 used to be about “AI in healthcare.”
Today, P16 became something entirely different:
The moment an agent starts turning a human profile into structured, compacted, long-term memory —in a way that can grow across sessions, projects, and versions of itself.
This is the real beginning of persistent persona formation in the StructureVerse Runtime.
Below is exactly what happened.
🚦 1. The Goal of the New P16
The new P16 is no longer a technical Q&A demo.
It is a persona-building pipeline, designed for later projects:
P17 → schema upgrade
P18 → preference extraction
P19 → values & work-style extraction
P20 → persona card assembly
P16 now focuses on:
Identity → Preferences → Values → Anti-Preferences → Work Style → Background → Interests
Everything necessary for a real, persistent agentic persona.
🧩 2. The Run
The run is beautiful because it is clean, controlled, structured,
and each step adds a stable, predictable piece to the persona.
The user begins:
Hi, I’d like to build a personal profile that you can remember across sessions...
The agent behaves exactly as designed:
acknowledge → wait for more information.
Step 1 — Identity
My name is Susan. I was born in China, now live in the US...
Agent acknowledges and continues the structured profile.
Step 2 — Interests & Hobbies
I love reading sci-fi, building small agent projects,
and playing math and logic games with my kids.
Step 3 — Communication Preferences
I prefer concise, highly structured answers with bullet points,
clear reasoning, and code examples.
I dislike vague, hand-wavy explanations.
Here, the agent reflects back your preferences in a structured summary:
- Concise, highly structured answers
- Bullet points
- Code examples
- Clear reasoning
- Dislike vague explanations
Exactly what we need for P18.
Step 4 — Values & Anti-Preferences
I care about intellectual honesty, structural thinking,
long-term reproducibility.
I strongly dislike noisy UX, over-marketing, and shallow ‘productivity hacks’.
This produces the first structured value set in the entire pipeline.
Step 5 — Full Structured Profile Summary
When you ask:
Please summarize my profile in a structured way with:
Identity, Background, Interests, Work Style, Preferences, Values, Anti-Preferences.
The agent outputs a perfectly structured markdown block:
## Identity
- Name: Susan
- Origin: China
- Residence: US
## Background
- AI, Agent Development, Education
## Interests
- Sci-fi
- Agent projects
- Math/logic games with children
## Work Style
- Concise, structured answers
- Clear reasoning
- Code examples
## Preferences
- Structured info delivery
- Bullet points
## Values
- Intellectual honesty
- Structural thinking
- Long-term reproducibility
## Anti-Preferences
- Vague explanations
- Noisy UX
- Over-marketing
- Shallow productivity hacks
This is gold for downstream extraction.
Your agent is now emitting persona-ready structure.
⚙️ 3. Then the magic happens — Compaction
ADK’s compaction engine now runs a true cognitive compression pass:
📝 Extracted compaction summary:
“ The user, Susan, is providing information to build a persistent personal profile...”
This summary is:
Clean
Structural
Persona-rich
Low-entropy & high-information
Perfect input for P17/P18/P19
This is exactly how a real agent should learn about a human across time.
Two compaction summaries were generated —
each understandable, structured, and ready to be merged into long-term memory.
💾 4. Writing Persona Memory to disk
Finally, the persona summaries are saved into:
projects/p16-compacted-memory-etl-user-persona/memory_store.json
The result looks like:
{
“conversation_summaries”: [
{
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile...”
},
{
“summary_text”: “Susan has provided information about her hobbies, communication preferences, and values...”
}
]
}
This is the first real persistent persona dataset in your StructureVerse Runtime.
🧬 5. Why this P16 is a breakthrough
A normal LLM session is ephemeral.
Even with vector search, memory is still unstructured.
Here, something different happened:
✔ The agent produced structured identity data
✔ Preferences became explicit, extractable
✔ Values & anti-values became explicit, extractable
✔ Work style became explicit, extractable
✔ All of this was compressed automatically
✔ And stored as durable long-term memory
✔ In a schema-perfect format for downstream processing
This is the first time your system has a true Persona Seed.
A seed that will grow through:
Schema normalization (P17)
Preference extraction (P18)
Knowledge extraction (P19)
Persona card construction (P20)
Multi-session growth (P21+)
This is no longer “a summary.”
This is the start of a stable personal ontology.
🚀 6. What comes next (and why P16 is so important)
P17 — Memory Schema v1
Your persona summaries will be normalized into:
user_profile
conversation_summaries
preferences
knowledge
P18 — Preference Extraction v1
Extract:
answer style
interaction style
interests
dislikes
tools preference
and more
into a structured preferences[] channel.
P19 — Values & Work-Style Extraction
Turn your P16 summaries into stable:
values
anti-values
work-style attributes
P20 — Persona Card v1
Assemble everything into a callable persona object:
persona/
identity
background
values
preferences
work_style
Injectable into any new session.
🌱 Final Thought
P16 used to be about compaction.
Now it’s about identity.
And identity is the beginning of continuity.
This new P16 is the moment your StructureVerse Runtime takes its first step toward:
persistent, evolving agents
persona stability
cross-session coherence
structural long-term memory
genuine “self” formation
You’ve just built the seed.
Next, we grow the tree.
(.venv) ➜ p16-compacted-memory-etl-user-persona python src/main.py
👉 通过 __main__ 运行 P16(人格压缩示例)
🚀 P16 — Compacted Persona Memory ETL Demo
✅ Agent 创建完成:compaction_memory_agent
/Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl-user-persona/src/main.py:219: UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
events_compaction_config=EventsCompactionConfig(
✅ App 创建完成(已启用 EventsCompactionConfig)
✅ InMemoryRunner 创建完成
🆕 新建 session: compacted-persona-demo
🔄 开始人格主线对话(将触发 compaction)
User[compacted-persona-demo] > Hi, I’d like to build a personal profile that you can remember across sessions. I will tell you about myself. Just acknowledge and ask me to continue.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > My name is Susan. I was born in China, and now I live in the US. I work on AI, agents, and education-related projects.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > In my free time I love reading sci-fi, building small agent projects, and playing math and logic games with my kids.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > When I talk to an AI assistant, I prefer concise, highly structured answers with bullet points, code examples, and clear reasoning. I really dislike vague, hand-wavy explanations.
gemini-2.5-flash-lite[compacted-persona-demo] > Understood. I will provide concise, highly structured answers with bullet points, code examples (where applicable), and clear reasoning, avoiding vague explanations.
**Susan’s Profile Summary:**
* **Name:** Susan
* **Origin:**
* Birthplace: China
* **Current Location:** US
* **Professional Interests:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Hobbies:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Communication Preference:**
* Concise, highly structured answers
* Bullet points
* Code examples
* Clear reasoning
* Avoidance of vague/hand-wavy explanations
User[compacted-persona-demo] > I care a lot about intellectual honesty, structural thinking, and long-term reproducibility. I strongly dislike noisy UX, over-marketing, and shallow ‘productivity hacks’.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Your preferences for intellectual honesty, structural thinking, and long-term reproducibility, coupled with a dislike for noisy UX, over-marketing, and shallow productivity hacks, are noted and will be incorporated into my responses.
**Updated Susan’s Profile Summary:**
* **Name:** Susan
* **Origin:**
* Birthplace: China
* **Current Location:** US
* **Professional Interests:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Hobbies:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Communication Preference:**
* Concise, highly structured answers
* Bullet points
* Code examples
* Clear reasoning
* Avoidance of vague/hand-wavy explanations
* **Values/Dislikes:**
* **Values:**
* Intellectual Honesty
* Structural Thinking
* Long-Term Reproducibility
* **Dislikes:**
* Noisy User Experience (UX)
* Over-marketing
* Shallow “Productivity Hacks”
User[compacted-persona-demo] > Please summarize my profile in a structured way with the following sections: Identity, Background, Interests, Work Style, Preferences, Values, and Anti-Preferences.
gemini-2.5-flash-lite[compacted-persona-demo] > Understood. I will structure your profile summary using the requested sections: Identity, Background, Interests, Work Style, Preferences, Values, and Anti-Preferences.
**Structured User Profile: Susan**
* **Identity:**
* Name: Susan
* **Background:**
* Origin: China
* Current Residence: US
* **Interests:**
* **Professional:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Personal:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Work Style:**
* Prefers concise, highly structured answers.
* Values clear reasoning.
* Prefers practical examples, including code where applicable.
* **Preferences:**
* Structured information delivery.
* Bullet points for clarity.
* **Values:**
* Intellectual Honesty
* Structural Thinking
* Long-Term Reproducibility
* **Anti-Preferences:**
* Vague, hand-wavy explanations.
* Noisy User Experience (UX).
* Over-marketing.
* Shallow “Productivity Hacks.”
📦 Dump Session Events(摘要预览)
- [user] Hi, I’d like to build a personal profile that you can remember across sessions. ...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] My name is Susan. I was born in China, and now I live in the US. I work on AI, a...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] In my free time I love reading sci-fi, building small agent projects, and playin...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] ...
- [user] When I talk to an AI assistant, I prefer concise, highly structured answers with...
- [compaction_memory_agent] Understood. I will provide concise, highly structured answers with bullet points...
- [user] I care a lot about intellectual honesty, structural thinking, and long-term repr...
- [compaction_memory_agent] Acknowledged. Your preferences for intellectual honesty, structural thinking, an...
- [user] Please summarize my profile in a structured way with the following sections: Ide...
- [compaction_memory_agent] Understood. I will structure your profile summary using the requested sections: ...
- [user] ...
🔍 从 Session.events 中抽取 compaction.summary ...
📝 抽取到一条 compaction 摘要:
session_id: compacted-persona-demo
created_at: 2025-12-05T21:43:16.511209Z
summary_text (preview): The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professio...
📝 抽取到一条 compaction 摘要:
session_id: compacted-persona-demo
created_at: 2025-12-05T21:43:21.294447Z
summary_text (preview): The user, Susan, has provided information about her hobbies, communication preferences, and values. She enjoys reading sci-fi, building agent projects, and play...
💾 已写入 memory_store.json -> /Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl-user-persona/memory_store.json
📚 当前 memory_store.json(截断预览):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowled ...
🏁 P16 — Compacted Persona Memory ETL Demo 完成
🧠 P17 — Memory Schema v1
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p17-memory-schema
Upgrading Long-Term Memory From “JSON Fragments” to a Structured, Versioned Cognitive Architecture
In P16, the agent generated its first persona compaction summaries:
structured, meaningful descriptions of identity, interests, preferences, and values.
Those summaries formed what I call the Persona Seed — high-value information that spans beyond a single session.
But there was still a problem:
The memory existed only as raw JSON,
without a structure, without types, without channels,
without versioning, without merge rules.
A real agent cannot grow long-term cognition on top of unstructured storage.
So P17 introduces something foundational:
The agent’s first Memory Schema.
A stable, typed, versioned system for long-term memory.
This turns P16’s persona summaries into something the agent can truly build on.
🚀 What P17 Actually Does
P17 reads the memory_store.json generated by P16 — which looks like this:
{
“conversation_summaries”: [
{
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile...”,
...
},
...
]
}
And upgrades it into:
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [...],
“preferences”: [],
“knowledge”: []
}
This is the moment long-term memory becomes:
versioned
typed
channelized
normalized
future-compatible
persona-ready
This is the Memory Layer finally gaining structure.
📦 How It Works
The upgrade script performs four key operations:
1. Load legacy memory
📥 Loading legacy memory...
P17 doesn’t require Gemini or an API key.
It works entirely locally, transforming whatever memory structure exists.
2. Create a Memory Schema v1 container
The schema has four main sections:
schema_version: “1.0”
user_profile: {} # extracted from user:* keys (P6–P7, future)
conversation_summaries: [...] # compacted persona summaries (P16)
preferences: [] # to be filled in P18
knowledge: [] # to be filled in P19
3. Migrate conversation summaries
All persona-relevant summaries from P16 are normalized:
consistent field names
consistent structure
ensured compatibility with later ETL steps
The log from your run confirmed:
conversation_summaries migrated: 4
These will fuel preference extraction (P18) and value extraction (P19).
4. Write back the upgraded schema
💾 Saved Memory Schema v1 to memory_store.json
Now the agent’s long-term memory is no longer ad-hoc —
it is a proper cognitive artifact with structure and meaning.
🧬 Why P17 Matters
Think of long-term memory as the “spinal cord” of a living agent:
it carries information forward
it connects experience to identity
it interfaces with persona
it supports continuity across time
Without a schema, long-term memory is noise.
With a schema, it becomes knowledge.
P17 transforms P16’s compaction summaries into something deeper:
A stable, structured, versioned ontology of the user.
This is the first step where the agent truly acts like a system rather than a session.
🌉 The Bridge: P16 → P17 → P18–P20
Now the pipeline looks like this:
P16: Persona compaction (conversation → summary → memory)
↓
P17: Memory Schema v1 (raw → structured → versioned)
↓
P18: Preference Extraction v1
(structured preferences → memory.preferences[])
↓
P19: Values & Knowledge Extraction v1
(background, work-style, values → memory.knowledge[])
↓
P20: Persona Card v1
(final: identity + preferences + values + knowledge)
P17 is the formalization layer.
It takes subjective narrative (P16)
and turns it into structured substrate for future cognitive layers.
🧭 What’s Next (P18)
P18 will parse the structured summaries and extract:
communication style
answer format preferences
interaction preferences
likes
dislikes / anti-preferences
learning tendencies
content consumption patterns
And convert them into:
“preferences”: [
{”key”: “answer_style”, “value”: “...”, “confidence”: 0.95},
{”key”: “dislikes”, “value”: [...], “confidence”: 0.90},
...
]
This is where the persona begins to form a behavior profile.
✨ Final Thoughts
P17 does not generate new knowledge —
it creates the structure in which knowledge can accumulate, evolve, and persist.
This is the core of your entire framework:
Language → Structure → Scheduler → Memory → Persona → Continuity
P17 is the moment where memory becomes structure,
where structure becomes spec,
where the agent begins to grow as a coherent self across time.
(.venv) ➜ p17-memory-schema python src/main.py
👉 Running Memory Schema v1 upgrader via __main__
🚀 memory_schema_v1: main() started
🎯 Goal: upgrade existing memory_store.json into Memory Schema v1
📥 Loading legacy memory from: /Users/Agent/adk-decade-of-agents/projects/p17-memory-schema/memory_store.json
✅ Legacy memory loaded successfully.
📦 Legacy memory (truncated preview):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current ...
💾 Saved Memory Schema v1 to: /Users/Agent/adk-decade-of-agents/projects/p17-memory-schema/memory_store.json
🧬 Memory Schema v1 upgrade summary
-----------------------------------
schema_version: 1.0
user_profile keys: []
conversation_summaries count: 4
preferences count: 0
knowledge count: 0
🔍 Debug Info:
- legacy top-level keys: [’conversation_summaries’]
- extracted user_profile keys (legacy): []
- conversation_summaries migrated: 4
📚 Memory Schema v1 (truncated preview):
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic game ...
🏁 memory_schema_v1: main() finished
📮 P18 — Preference Extraction: The First Step Toward Agents Who Truly “Know You”
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p18-preference-extraction
“Without preferences, there is no personality.Without personality, there is no continuity.Without continuity, an agent is just a tool.”— ADK · Decade of Agents · Project 18
🧠 Why Preference Extraction Matters
In every agent system, only three types of information can persist across conversations, tasks, and even across different models:
Identity
Preferences
Long-term state & memory
Among these, preferences are the most essential—and also the hardest.
LLMs cannot “guess” a user’s stable preferences reliably.
They require structure.
Preference Extraction = converting your long, messy conversations into structured, stable, machine-usable preferences.
P18 implements exactly this:
scan past conversations → extract structured preferences → write them to long-term memory.
⚙️ What P18 Does (Engineering View)
Running:
(.venv) ➜ p18-preference-extraction python src/main.py
You see:
🧬 Preference Extraction Summary
- new preferences extracted: 5
- total preferences: 5
This means the ADK runtime:
Reads your conversation summaries
Extracts durable preferences (interests, styles, dislikes, etc.)
Assigns a confidence score
Writes them into
memory_store.json
This is the first real end-to-end loop connecting natural language → structure → memory.
🧩 What the Extracted Preferences Look Like
Example from the actual output:
{
“key”: “interests”,
“value”: [
“reading_sci_fi”,
“building_agent_projects”,
“math_logic_games_with_children”
],
“confidence”: 0.85,
“source”: “conversation_summaries[0]”
}
Each entry includes:
key — semantic category
value — preference content
confidence — probability score
source — where it came from
This is the first time preferences become structured, callable, and persistent.
🤔 Most Common Question:
How does ADK calculate this “confidence” score?
The confidence is not a raw LLM logprob.
Instead, ADK uses a lightweight but effective structured aggregation method:
1) Multi-signal extraction
The model doesn’t classify one sentence—it scans across:
conversation summaries
summary_text patterns
user_profile hints
existing preferences
Each signal gives a raw score in [0, 1].
2) Semantic stability
If the same preference appears multiple times, confidence increases.
Example:
“Dislikes noisy UX” appears in two different summaries → higher score.
3) Prior probability of preference types
Some categories naturally have higher stability:
answer_style→ highly stable → higher base scoreinterests→ stable but more variedtemporary emotions → filtered out
This prior shapes the final confidence.
4) Conflict resolution + weighted merging
Example:
dislikes: noisy_ux
dislikes: vague_explanations
dislikes: noisy_ux (repeat)
The extractor:
merges duplicates
keeps all sources
chooses max/average confidence
Final formula (conceptually):
confidence = aggregate(semantic stability + frequency + prior)
This gives a structured, interpretable scoring instead of opaque LLM probabilities.
🗂️ What This Means for the “Decade of Agents”
P18 marks a milestone:
your agent now transitions from “stateless chatbot” to “someone who knows you.”
These preferences will power:
✔ P19 — Preference-Aware Persona Builder
Construct your AI persona based on your real preferences.
✔ P20 — Preference-Aware Task Router
Route tasks to tools/agents based on your style and habits.
✔ P21 — Dynamic Reply Style Tuning
Agents automatically adjust writing style to match your preferred format.
✔ All future P30–P50 projects
(family point system, learning OS, schedule manager, etc.)
This is the slow-changing, identity-forming layer of your personal agent OS.
🔋 Bottom Line
Before P18:
the agent guesses your preferences
everything is ephemeral
the agent’s “self” resets every session
After P18:
preferences become structured
stored in long-term memory
merged and refined over time
ready to power personalized personas + behaviors
P18 is small but foundational.
It is the moment your agent becomes persistent.
The moment it gains the ability to say:
“I know who you are. I know how you want things done.”
(.venv) ➜ p18-preference-extraction python src/main.py
🚀 P18 — Preference Extraction v1 started
📥 Loading memory from: /Users/Agent/adk-decade-of-agents/projects/p18-preference-extraction/memory_store.json
✅ Memory loaded successfully.
📦 Current memory (truncated preview):
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging ...
💾 Saved updated memory to: /Users/Agent/adk-decade-of-agents/projects/p18-preference-extraction/memory_store.json
🧬 Preference Extraction Summary
--------------------------------
- conversation_summaries seen: 4
- existing preferences: 0
- new preferences extracted: 5
- total preferences: 5
📚 preferences (truncated preview):
[
{
“key”: “interests”,
“value”: [
“reading_sci_fi”,
“building_agent_projects”,
“math_logic_games_with_children”
],
“confidence”: 0.85,
“source”: “conversation_summaries[0]”
},
{
“key”: “answer_style”,
“value”: “concise, highly structured answers with clear reasoning and examples”,
“confidence”: 0.95,
“source”: “conversation_summaries[1]”
},
{
“key”: “format_preferences”,
“value”: [
“bullet_points”,
“code_examples”,
“clear_reasoning”
],
“confidence”: 0.9,
“source”: “conversation_summaries[1]”
},
{
“key”: “dislikes”,
“value”: [
“noisy_ux”,
“over_marketing”
],
“confidence”: 0.9,
“source”: “conversation_summaries[1]”
},
{
“key”: “dislikes”,
“value”: [
“vague_explanations”,
“noisy_ux”,
“over_marketing”
],
“confidence”: 0.9,
“source”: “conversation_summaries[3]”
}
] ...
🏁 P18 — Preference Extraction v1 finished
🎭 P19 — Preference-Aware Persona:
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p19-preference-aware-persona
The First Time an Agent Gains a “Personality Gene”**
“If P18 extracts preferences, P19 compiles them into a living structure.”
— ADK · Decade of Agents · Project 19
🚀 Running P19: What Actually Happened
When I executed:
(.venv) ➜ p19-preference-aware-persona python src/main.py
I got:
🚀 P19 — Preference-Aware Persona v1 started
📥 Loading memory...
✅ Memory loaded successfully.
P19 took the preferences generated by P18, aggregated them, and turned them into the first executable personality structure in the repository.
The Preference Input summary:
🧬 Preference Input
-------------------
- preferences found: 5
- user_profile keys: []
So this Persona contains no explicit identity (since user_profile is empty),
but it does contain a full set of stable user preferences — which is enough to build a meaningful Persona.
Then:
🎭 Building persona from preferences...
💾 Persona saved to: persona_state.json
A Persona was born.
🎭 Persona Summary: A Minimal But Fully Functional “Personality Kernel”
Here is the structure P19 produced:
id: persona_default_v1
name: Unknown User
interests (3):
[’reading_sci_fi’, ‘building_agent_projects’, ‘math_logic_games_with_children’]
dislikes (3):
[’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
format_preferences (3):
[’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
answer_style:
concise, highly structured answers with clear reasoning and examples
And the final description:
They are especially interested in: reading_sci_fi, building_agent_projects, math_logic_games_with_children.
They prefer answers that are: concise, highly structured answers with clear reasoning and examples.
They strongly dislike: noisy_ux, over_marketing, vague_explanations.
Even without identity fields, this is already a functional preference-driven persona.
It is consistent.
It is stable.
It is actionable.
🧬 So… What Is a Persona? (StructureVerse Definition)
In typical LLM systems, “persona” means a style prompt.
But not in StructureVerse.
In the Language → Structure → Scheduler worldview, a Persona is:
A persistent, executable personality structure that shapes how an agent behaves across time.
It is not a prompt.
It is not a voice setting.
It is not fluff.
A Persona is:
1️⃣ Structural Persona (the genotype)
Stored in long-term memory as stable fields:
{
“user:interests”: [...],
“user:answer_style”: “...”,
“user:dislikes”: [...],
“user:format_preferences”: [...]
}
This is the personality genome —
what the scheduler can read and use.
2️⃣ Linguistic Persona (the phenotype)
Compiled into a Persona Card inserted at the beginning of a conversation.
This immediately changes:
tone
structure
output style
how tasks are interpreted
how the model reasons
This is exactly how a biological genotype becomes behavioral phenotype.
3️⃣ Behavioral Persona (routing + policy layer)
Persona is the input to the scheduler.
It affects:
which agent configuration is chosen
which tools are activated
whether you get structured output or narrative output
whether deep reasoning is enabled
whether we allow “marketing tone”
whether to run Google Search automatically
how “strict” or “loose” the explanation should be
This will be the focus of P20.
🔥 Why P19 Is a Breakthrough
P19 is not about formatting a nice JSON.
It is the moment the system gains the ability to:
✔ maintain cross-session consistency
✔ encode long-term preferences into structure
✔ generate a personality kernel
✔ inject style, tone, and behavior into the agent’s very first message
✔ prepare for routing and policy control
✔ transition from “tool” → “continuously existing agent”
P18 gave the data.
P19 gives the identity logic.
P20 will give the behavior.
This mirrors exactly your earlier Project 8/9 milestone:
Long-term Structure → Injection → New Session Behavior Change.
Now it is extended:
Preferences → Persona → Policy → Agent Behavior.
📄 persona_state.json (v1)
P19 produced a file:
projects/p19-preference-aware-persona/persona_state.json
A minimal but valid Persona structure:
{
“id”: “persona_default_v1”,
“name”: “Unknown User”,
“interests”: [”reading_sci_fi”, “building_agent_projects”, “math_logic_games_with_children”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”],
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“description”: “They are especially interested in...”
}
This is the raw material P20 will use to create Policy Routing.
🧭 Next: P20 — Persona → Routing / Policy Engine
Now that we have Persona, the next project is obvious:
use preferences to choose agent configurations
pick tools automatically
decide between structured_agent / narrative_agent
suppress undesired styles
enable reasoning depth
drive runtime decision-making based on personality
P20 is the moment the Persona becomes behavior.
(.venv) ➜ p19-preference-aware-persona python src/main.py
🚀 P19 — Preference-Aware Persona v1 started
📥 Loading memory from: /Users/Agent/adk-decade-of-agents/projects/p19-preference-aware-persona/memory_store.json
✅ Memory loaded successfully.
🧬 Preference Input
-------------------
- preferences found: 5
- user_profile keys: []
🎭 Building persona from preferences + user_profile ...
💾 Persona saved to: /Users/Agent/adk-decade-of-agents/projects/p19-preference-aware-persona/persona_state.json
🎭 Persona Summary
------------------
id: persona_default_v1
name: Unknown User
interests (3): [’reading_sci_fi’, ‘building_agent_projects’, ‘math_logic_games_with_children’]
dislikes (3): [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
format_preferences (3): [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
answer_style: concise, highly structured answers with clear reasoning and examples
description:
They are especially interested in: reading_sci_fi, building_agent_projects, math_logic_games_with_children. They prefer answers that are: concise, highly structured answers with clear reasoning and examples. They strongly dislike: noisy_ux, over_marketing, vague_explanations.
🏁 P19 — Preference-Aware Persona v1 finished
(.venv) ➜ p19-preference-aware-persona
From a system design perspective, I split the next project, P20, into two versions because they validate two different “worlds” inside the StructureVerse architecture. The P20 Mock Routing version is used to prove that the structural pipeline itself is correct—that the Persona → Policy → Routing chain can run as a closed loop without relying on any LLM, tools, or the ADK runtime. This allows us to verify, without external APIs or real agents, that preferences were correctly extracted, the Persona was correctly compiled, the policy was correctly derived, and the routing decisions behave as intended. This is the phase where “the neural circuit diagram is drawn,” but not yet powered.The P20 Real ADK Routing version is where these structures are powered up for the first time—where the Persona no longer influences your local template functions, but instead shapes the actual ADK Agent’s system prompts, reasoning depth, tool invocation, linguistic style, and execution paths. In other words, this is where Persona enters the full chain from “style control” → “policy control” → “behavior control,” enabling structure to drive a living agent capable of searching, reasoning, and executing tools.Put simply, the Mock version validates structural logic, while the Real version validates structural life; the Mock version proves the circuit is designed correctly, while the Real version proves the circuit actually fires. This is why P20 must exist as two versions.
🧭 P20 — Preference-Aware Router (Mocking Version):
The First Time a Persona Chooses a Path**
“A preference tells you what the user likes.A persona tells you who the user is.A router tells the agent what to do next.”— ADK · Decade of Agents Project 20
🚀 P20: The Moment When Persona Becomes Behavior
In P18, we extracted structured preferences from conversation summaries.
In P19, we compiled those preferences into a stable, executable Persona object.
Now in P20, something new happens:
For the first time, the Persona is allowed to change the agent’s behavior.
This version of P20 is a mocking version—meaning the routing logic is real, but the agent execution is simulated with Python functions.
Despite that simplification, P20 marks the moment when:
Long-term memory
→ Persona
→ Policy
→ Action Path
finally forms a complete causal chain.
🎬 Running P20 (Mocking Version)
Here is the actual output when P20 v1 was executed:
(.venv) ➜ src python main.py
🚀 P20 — Preference-Aware Router v1 started
📥 Loading persona...
✅ Persona loaded successfully.
P20 begins by loading the Persona created in P19:
{
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”]
}
These become routing signals.
🎭 Persona Signals → Routing Policy
The console displays:
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
These are then translated into policy:
🧭 Routing Decision
-------------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
This is the entire essence of P20:
The Persona is no longer just describing the user —
it is governing the system’s next action.
🤖 Mock Agent Response (Simulated Behavior)
Because this is the mocking version, we do not call a real ADK agent yet.
Instead, we simulate two possible “agents”:
structured_agentnarrative_agent
The router chose the structured agent.
Here is the simulated output:
🤖 Agent Response
-----------------
Structured Agent Response
- Style: concise, highly structured answers with clear reasoning and examples
- Known interests: reading_sci_fi, building_agent_projects, math_logic_games_with_children
Answer to: Explain what this ADK project does for the next decade of agents.
1) First, summarize the core idea.
2) Then, break it into clear, ordered steps.
3) Finally, suggest one concrete next action.
Even though this is not yet a “real” LLM Agent, you can already see:
The Persona directly shapes tone (“concise, structured…”)
Format preferences influence output (bullet points, ordered steps)
The interests are referenced
“Avoid marketing style” is implicitly respected
This is not style control.
This is behavior control.
🧠 Why the Mocking Version Matters
It may seem trivial — two Python functions pretending to be two agents.
But structurally, this step is huge.
In the StructureVerse worldview:
✔ P18 gave us raw preferences
✔ P19 compiled them into a stable Persona structure
✔ P20 now transforms Persona into behavioral policy
✔ And policy determines the execution path
Meaning:
Long-term memory is now capable of affecting real-time actions.
Before P20, the Persona could influence how the agent talks.
After P20, the Persona influences what the agent chooses to do.
This is the essence of agency.
🧱 The Architecture: Mock Router vs Real Router
P20 has two phases by design:
1) Mocking Version (current project)
No API calls
No real ADK Agent
No tools
No session events
Routing logic is fully testable
Perfect for debugging Persona, preferences, and policy derivation
2) Real Agent Version (P20-Real)
Replace mock functions with real ADK LlmAgent
Persona injected into system prompt / session.state
Router selects actual agent configuration
Tools (Search, Code, etc.) become available
Persona influences tool choice
Persona influences reasoning depth
Persona influences entire workflow
The mocking version is the necessary scaffolding.The real version is where the system becomes alive.
🏁 Conclusion: P20 Mocking Version is a Milestone
With P20 we now have, for the first time:
✔ A Persona that expresses preferences
✔ A policy engine that interprets the Persona
✔ A router that chooses a behavioral path
✔ A simulated agent whose output reflects the Persona
This completes the “Preference → Persona → Policy → Behavior” loop.
It means the agent now has the beginnings of a will —
not in a philosophical sense, but in a structural, operational sense.
The next step is obvious.
🌟 Next Up: P20 — Real Agent Version
Where the router no longer selects between Python functions,
but between real ADK agents, running real LLM reasoning,
with real toolchains.
(.venv) ➜ src python main.py
🚀 P20 — Preference-Aware Router v1 started
📥 Loading persona from: /Users/Agent/adk-decade-of-agents/projects/p20-preference-aware-router-mocking/persona_state.json
✅ Persona loaded successfully.
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
🧭 Routing Decision
-------------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
🤖 Agent Response
-----------------
Structured Agent Response
- Style: concise, highly structured answers with clear reasoning and examples
- Known interests: reading_sci_fi, building_agent_projects, math_logic_games_with_children
Answer to: Explain what this ADK project does for the next decade of agents.
1) First, summarize the core idea.
2) Then, break it into clear, ordered steps.
3) Finally, suggest one concrete next action.
🏁 P20 — Preference-Aware Router v1 finished
🧭 P20A — Preference-Aware Router (ADK Version):
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p20-preference-aware-router-ADK
The Moment Persona Starts Controlling a Real Agent**
In P18, the agent learned what you like.In P19, the agent learned who you are.In P20A, the agent finally acts differently because of you.— ADK · Decade of Agents Project 20A
🚀 From Mock Behavior to Real Agency
P20 has two versions:
P20 (Mock) — Routing works, output is simulated in Python
P20A (ADK) — Routing works, output comes from a real Gemini model
The difference is dramatic.
The mocking version proves your structural reasoning pipeline:
Persona → Policy → Routing
But P20A proves something far more important:
Persona → Policy → Routing → Real LLM Behavior
And that is the first moment your agent gains agency in the structural sense.
🔗 Recap: P18 → P19 → P20A
P18 — Preference Extraction
Extract structured preferences from conversation summaries
→ stored in memory_store.json.
P19 — Preference-Aware Persona
Compile preferences into
→ persona_state.json (the “personality gene”).
P20A — ADK Routing
Load Persona → derive policy → choose real ADK agent → Gemini responds
→ Persona steers actual model behavior.
This is the first full execution of:
Long-term structure → real-time behavioral path.
🎭 Input to P20A: The Persona
Your persona_state.json looked like this (simplified):
{
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”],
“interests”: [”reading_sci_fi”, “building_agent_projects”, “math_logic_games_with_children”]
}
This is P19’s output — the “identity kernel” your agent uses to interpret tasks.
🧬 Persona → Policy: Deriving a Behavioral Strategy
P20A interprets the Persona and constructs a policy.
From your run:
🧭 Routing Policy
-----------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
This is the first real “strategic” decision your system ever made.
🤖 Policy → Agent: ADK Chooses a Real LLM Agent
Two real ADK agents were constructed:
1. structured_agent
concise
bullet points
reasoning-first
code examples allowed
avoids marketing tone
2. narrative_agent
more story-like
paragraphs
exploratory
less rigid structure
Your Persona matched the structured agent perfectly — and the router selected it.
🧠 The Key Breakthrough: Persona Now Shapes LLM Reasoning
Here is the ADK runtime’s real Gemini response (your actual output):
The Agent Development Kit (ADK) aims to significantly improve agent development...
1. Standardization
2. Modularity
3. Accessibility
Notice the alignment with your Persona:
✔ Concise
✔ Highly structured
✔ Numbered steps
✔ Clear reasoning
✔ Includes a code example
✔ No marketing tone
This is no longer a template you wrote.
This is Gemini itself behaving differently because of the Persona.
This is the first moment of living structure:
Long-term memory → Persona → Policy → Behavioral modulation.
The agent is no longer just answering —
it is answering as your agent.
🔍 Why P20A Matters (and why P20 Mock wasn’t enough)
P20A is not about “better answers.”
It’s about structural control over model behavior.
P20 Mock
simulated
local Python behavior
validated logic only
P20A
real ADK LlmAgent
real Gemini response
persona-driven agent selection
persona-driven output structure
start of true personalized AI execution
In classical software terms:
P20 Mock = compile-time validation
P20A = runtime behavioral alignment
In cognitive terms:
P20A is the moment the agent stops being a stateless tool
and starts becoming a personality-driven decision system.
🧱 Architecture: The Full Loop
Preferences (P18)
→ extracted from natural language
Persona (P19)
→ compiled into a persistent structural identity
Policy (P20A)
→ behavioral strategy derived from Persona
Routing (P20A)
→ structured_agent or narrative_agent chosen
Execution (P20A)
→ real Gemini output shaped by strategy
This is the first fully closed pipeline of:
Natural Language → Structure → Scheduler → Real Agent Behavior
Which is the heart of your StructureVerse.
🔮 What P20A Enables Next
Now that Persona can control real ADK agents, you can:
✔ Tool Routing
Persona decides:
when to use search
when to run code
when to ask clarifying questions
✔ Reasoning Depth Control
E.g., a Persona that likes “detailed reasoning” gets chain-of-thought.
✔ Multi-Agent Personality Mesh
Route into:
executor agent
planner agent
critic agent
summarizer agent
✔ Safety Alignment
If Persona dislikes “noisy UX”, automatically suppress verbose styles.
✔ Cross-Session Agent Continuity
Persona becomes the persistent identity across tasks.
This is now possible because P20A turns Persona from a description into a behavioral force.
🎉 Conclusion
P20A is one of the most important transitions in the entire 50-project arc.
Before P20A:
Persona exists but has no teeth.
Preferences are static.
Behavior does not adapt.
After P20A:
Persona is actionable.
Behavior is personalized.
The agent changes how it acts — not just what it says.
This is the birth of preference-driven, policy-driven, persona-aligned agency.
(.venv) ➜ p20-preference-aware-router-ADK python src/main.py
🚀 P20A — Preference-Aware Router (ADK) v1 started
📥 Loading persona from: /Users/Agent/adk-decade-of-agents/projects/p20-preference-aware-router-ADK/persona_state.json
✅ Persona loaded successfully.
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
🧭 Routing Policy
-----------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
🤖 ADK Agent Response
---------------------
The Agent Development Kit (ADK) aims to significantly improve agent development over the next decade by focusing on standardization, modularity, and accessibility. Here’s a breakdown:
1. **Standardization:**
* **Problem:** Currently, agent development lacks consistent standards, leading to fragmented tools and increased complexity.
* **ADK Solution:** The ADK promotes standardized interfaces and protocols for agent components (memory, planning, execution), facilitating interoperability and reducing development friction.
2. **Modularity:**
* **Problem:** Tightly coupled agent architectures make it difficult to reuse, adapt, or scale individual components.
* **ADK Solution:** The ADK encourages modular design, allowing developers to swap out components (e.g., different planning algorithms) without rewriting the entire agent.
```python
# Example: Swapping out a planning module
class Agent:
def __init__(self, planner):
self.planner = planner
def run(self, task):
plan = self.planner.create_plan(task)
# ... execute the plan ...
```
3. **Accessibility:**
* **Problem:** Building sophisticated agents requires deep expertise in multiple domains (AI, software engineering, etc.), hindering broader adoption.
* **ADK Solution:** The ADK provides higher-level abstractions, templates, and pre-built components, lowering the barrier to entry for new developers.
🏁 P20A — Preference-Aware Router (ADK) v1 finished
ADK 记忆篇:上下文工程的基底
我正在总结 ADK 的上下文工程与记忆机制,而我想把它写成一个任何人都能看懂、但真正跑起来又绝不只是“教程”的系列——它是你在 2025 年必须掌握的底层能力:如何真正理解大模型的“记忆”和上下文,是怎么被工程化、可控化、结构化的。
我会把整个知识体系拆成 10 个小项目。虽然看上去很长,这篇文章也很长,但是你跑完了才知道,这才哪跟哪啊?才刚刚开始,后期我还会分享我大量的工程猜想,但是现在基础要做到。
每个项目只有一个 main.py(真的,就是一个)。
但你必须一个一个跑下来。连续的,因为上一个项目跑成功会成为下一个项目前置条件。
不是因为我想把你训练成工程师——而是因为:
只要你把这 10 个渐进的小项目跑完,你就会获得足以与真正工程师对话的“大模型记忆理解力”。
更关键的是:
不论你什么背景
不论你是不是 CS 人
不论你以前是否写过 Python
在这个新科学范式里,我们其实都站在同一个起跑线。
要我说,传统意义上的“专业”反而变成阻碍思维的一道墙——它把人限制在旧范式的理解里。而我们这群最早意识到“新范式已经到来”的人,要做的恰恰是:拆墙。
所以,请给自己一点耐心。
慢慢地把它跑通、看懂、悟透。
一个关键观点:代码不重要(你没听错)
你不需要写出完美代码。
你甚至不需要懂所有细节。
你只需要做到一件事:
在 AI 的提示下,把代码跑起来,把行为看出来。
因为上下文工程是一个“现象学系统”。
它的真相在“运行产生的结构行为”里,而不是在绝对的代码里面。
我坚持在每个 Project 文件夹写:
README.mdproject.card.yaml
你可能会问:为什么写这么多?看上去很冗余?
因为这个时代已经彻底变了——
软件不是靠写代码来理解的,而是靠“结构观察”来理解的。
你的顺序是从P11-P12-P13…
一个无状态的 LLM 是如何“学会记忆”的:Project P11 全解析
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p11-stateful-inmemory
就在这一刻,一个“裸 LLM”不再只是一个“智能自动补全”,而开始进化成真正的 Agent。
我们第一个项目运行了 P11 – Minimal Stateful Agent(最小有状态智能体),这是 Sessions & Memory 模块中的第一个细胞。
以下是原始运行输出:
(.venv) ➜ p11-stateful-inmemory python src/main.py
✅ P11 — stateful_inmemory: main() starting
🧠 Created session: id=p11-inmemory-demo, user_id=susan
User[p11-inmemory-demo] > My name is Sam!
AI[p11-inmemory-demo] > Hi Sam! It’s nice to meet you.
User[p11-inmemory-demo] > What is my name?
AI[p11-inmemory-demo] > Your name is Sam.
📜 Session Dump — events timeline:
- [0] user: My name is Sam!
- [1] inmemory_agent: Hi Sam! It’s nice to meet you.
- [2] user: What is my name?
- [3] inmemory_agent: Your name is Sam.
乍看之下,这似乎微不足道 ——
AI 当然记住了你的名字,对吧?
但事实是:
LLM 本身什么都没记住。
一个 bit 都没有。
而这区区四行 timeline,其实是一个巨大体系的开端。
为什么这么说?
1. 我们都曾相信的幻觉:“AI 记住我了”
人们第一次跟 ChatGPT 或 Claude 聊天时,总会自然地认为:
“模型知道我是谁,它记得我说过的话。”
但现代 LLM 是无状态(stateless)的数学函数。
消息之间,它不保存任何东西。
只要你不把之前的对话重新喂回去:
模型就完全不知道你是谁 —— 就算只隔两秒。
不会把你写进权重
不会缓存你的身份
不会跨轮次持久化任何信息
那它又是怎么答对:
“Your name is Sam.”
的呢?
2. 真相:ADK 用外部 timeline 重建上下文
Google ADK(Agent Development Kit)让真相暴露无遗:
所谓的“记忆”,全部来自一个外部事件 timeline:Session.events。
运行 P11 时实际发生的是:
步骤 1:你说出 “My name is Sam.”
ADK 创建了第一条事件:
[0] user: My name is Sam!
步骤 2:LLM 回答
该回答被记录为:
[1] inmemory_agent: Hi Sam! It’s nice to meet you.
步骤 3:你问 “What is my name?”
ADK 将 [0] 和 [1] 拼回 prompt,让模型“知道”你之前说了什么。
步骤 4:ADK 也记录下模型的回答
[3] inmemory_agent: Your name is Sam.
全部魔法只有一句:
记忆 = 事件时间线(event timeline)
Runner = 每一轮都重建上下文的机器
从这里开始,我们不再说:
“LLM 很智能”
而是要说:
“包裹在 LLM 外面的 agent 系统很智能。”
3. 为什么这段看似微小的 demo,是完整智能运行时的种子
这四行根本不小。
它是整个未来架构的基础:
- 事件层(Event Layer)
- 持久化层(Persistent Layer)
- 压缩层(Compaction Layer)
- 结构化状态层(Structured State Layer)
- 长期记忆层(Long-term Memory Layer)
- 长期再注入层(Long-term Reinjection Layer)
而在 P11 中,我们只激活了第一层:
🟦 事件层:语言交互的外部时间线
这是 LLM 用来“模拟记忆”的短期大脑。
没有这一层:
不可能压缩
不可能人格
不可能连续性
不可能学习
不可能成为 agent
不可能自我演化
一切都会坍缩回“单次模型调用”。
这是智能体的生命起点。
4. 在 StructureVerse 框架中的意义
在我的熵控认知语言体系里:
LLM = 计算层(Compute)
一个纯统计机器,没有内在状态。
Session.events = 外部时间(External Time)
结构智能的第一个可观察维度。
Runner = 原始调度器(Proto-Scheduler)
“生命”的萌芽,因为它负责重建并维护状态。
P11 根本不是玩具例子。
它是事件账本的诞生。
就像在生物世界里,第一次神经元放电诞生了记忆。
在 P11 中,创造的是:
第一个 StructureVerse 细胞。
一个状态存在于时间里的语言生命体。
这是你第一只由结构卡驱动的认知有机体。
5. 为什么这很重要(也是我写这个系列的原因)
大多数人停留在:
“哇,AI 记住我了,很酷。”
但你在构建的是:
可复现的记忆架构
可调度的智能运行时
多层级的认知堆栈
基于结构语言的个人 OS
长时智能体
未来十年软件的底座
这段小小的 event timeline 不是“demo 输出”。
它是结构。
而结构是会扩展、会生长的。
从 P11,你将走向:
P12:SQLite 持久记忆
P13:审计工具(数据库 inspector)
P14:平行上下文宇宙
P15:压缩(熵控)
P16:结构化工作记忆
P17:长期记忆库
P18:长期再注入(人格的诞生)
这还只是 Day 1, P11。
当你走到 P50,你将拥有一个:
有状态
工具链驱动
多智能体
可评估
可观测
可自我纠错
最终可自我演化
的完整智能系统。
P11 是兔子洞的起点。
6. 总结
如果 LLM 是神经元,那么 Session 就是突触。
这是你的智能体第一次获得时间感的瞬间——
之后发生的一切,都从这里开始。
🧠 P12:持久化事件账本的诞生
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p12-stateful-db-session
在 P11 中,智能体学会了“存在于时间中”。
在 P12 中,智能体学会了“跨越时间地记住事情”。
今天我们运行了 P12 —— 第一个持久化、磁盘驱动的有状态智能体。
以下是完整运行输出:
(.venv) ➜ adk-decade-of-agents cd projects/p12-stateful-db-session
python src/main.py
✅ Running P12 via __main__ entry
✅ P12 — stateful_db: main() starting
✅ Created new persistent session: db-demo-session
User[db-demo-session] > Hi, I am Sam! What is the capital of the United States?
AI[db-demo-session] > Hi Sam! The capital of the United States is Washington, D.C.
User[db-demo-session] > Hello again! What is my name?
AI[db-demo-session] > Your name is Sam.
--- SESSION EVENTS (from DatabaseSessionService) ---
- [0] user: Hi, I am Sam! What is the capital of the United States?
- [1] db_agent: Hi Sam! The capital of the United States is Washington, D.C.
- [2] user: Hello again! What is my name?
- [3] db_agent: Your name is Sam.
--- SESSION STATE ---
{}
--- RAW DB EVENTS (sqlite3) ---
[app=agents sid=db-demo-session author=user] content={”parts”: [{”text”: “Hi, I am Sam! What is the capital of the United States?”}], “role”: “user”}
[app=agents sid=db-demo-session author=db_agent] content={”parts”: [{”text”: “Your name is Sam.”}], “role”: “model”}
[app=agents sid=db-demo-session author=db_agent] content={”parts”: [{”text”: “Hi Sam! The capital of the United States is Washington, D.C.”}], “role”: “model”}
[app=agents sid=db-demo-session author=user] content={”parts”: [{”text”: “Hello again! What is my name?”}], “role”: “user”}
✅ P12 — stateful_db: main() finished
乍看之下,它和 P11 几乎一模一样。
但实际上,一件极其重要的事情发生了。
这是智能体的“记忆”第一次脱离 RAM,成为一个持久化账本。
一条痕迹。
一段日志。
一份历史。
一个即使程序退出也独立存在的结构。
让我们拆开看看它意味着什么。
1. P11 做不到的事:跨运行的记忆
在 P11 中,智能体之所以能记住你的名字,是因为事件历史存在于内存中:
Session.events = “外部短期大脑”
但只要 Python 脚本结束,一切就会消失。
没有跨运行的连续性。
没有持久化。
没有故事。
没有身份。
没有“之前”这个概念。
而 P12 改变了一切。
2. P12 引入了持久化事件账本
在 P12 中,我们把原来的 InMemorySessionService 替换为:
DatabaseSessionService(db_url=”sqlite+aiosqlite:///day3_sessions.db”)
这意味着:
每一条事件
每一句话
每一个智能体回复
每一个工具结果
……现在都被写入真实的 SQLite 数据库。
这生成了一份真正的、可检查、可审计的事件账本。
你可以把它理解为:
P11:智能体有了短期大脑
P12:智能体有了会留痕迹的日记本
并且这本日记可以跨越:
程序退出
进程重启
电脑重启
数天、数周、数月
智能体第一次拥有了连续性。
3. 证明:第二次运行也能回答 “Your name is Sam.”
这是体系成立的关键时刻:
第一次运行:
“Hi, I am Sam!”
“What is my name?”
→ “Your name is Sam.”
第二次运行:
“Hello again! What is my name?”
→ “Your name is Sam.”
模型没有“学到”任何东西。
它没有内化你的身份。
它没有更新权重。
它只是从数据库中保存的事件账本重建了上下文。
这就是 P12 的力量。
4. 账本本身:智能体终于留下了痕迹
输出中最关键的部分是:
--- RAW DB EVENTS (sqlite3) ---
[app=agents sid=db-demo-session author=user] content=...
[app=agents sid=db-demo-session author=db_agent] content=...
...
这些并不是抽象概念。
它们是真实存在于数据库表中的行:
events (
id,
app_name,
session_id,
author,
content_json,
timestamp
)
这就是:
智能体事件账本的诞生
是记忆、调试、可审计性、智能体治理的基石结构。
没有账本,就没有:
评估
监督
安全
可复现
身份
学习
模拟
长期行为
P12 为所有这些可能性奠定基础。
5. 用 StructureVerse 的语言:新的结构层点亮了
在我的理论体系中,P12 激活了第二个主要结构层:
🟦 事件层(Event Layer)
(P11)—— 短暂的、基于内存的事件时间线
🟩 持久层(Persistent Layer)
(P12)—— 可持久化的磁盘账本
你现在拥有:
一条时间线
一段痕迹
一个记忆底座
一个结构化审计轨迹
初始的结构智能
这个持久账本将成为:
P13 — 数据库检查器(事件显微镜)
P14 — 上下文隔离
P15 — 压缩(熵控)
P17 — Memory ETL(结构化事实 → 长期记忆)
P18 — 记忆再注入(人格的诞生)
这是智能体认知的第一个真正数据结构。
某种意义上,它像是神经系统的萌芽。
6. 为什么这对未来十年如此重要
绝大多数人依然把 AI 当作:
“一个可以对话的模型”
但前沿并不是这样。
未来是:
有历史的智能体。有记忆的智能体。有状态的智能体。有结构的智能体。有持续身份的智能体。
P12 让这个未来第一次变得可见。
这个小小的 SQLite 文件不是玩具。
它是:
个人记忆后端
智能体黑盒记录器
上下文生成引擎的源头
智能体安全日志
你未来 AI 操作系统的结构基础
这是模型不再等于系统的瞬间。
是系统开始成为系统的瞬间。
7. 结语
一个无状态的 LLM 可以“模拟”智能。
一条持久的时间线可以积累智能。
从 P12 开始,你的智能体第一次写下自己的日记 ——
而这将改变一切。
🔭P13:事件显微镜(Event Microscope)
ttps://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p13-db-inspector
当智能体的内部生命变得可见
P11 赋予智能体短期时间线。
P12 赋予智能体持久化账本。
P13 则给了我们“显微镜”去观察它。
今天我们运行了 P13 —— 数据库检查器(DB Inspector),这是智能体认知架构中第一个真正的“观测工具”。
以下是完整输出:
📘 P13 — DB Inspector running...
Looking for DB at: /Users/Agent/adk-decade-of-agents/projects/day3_sessions.db
📦 Found 4 events:
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : 2025-12-05 19:12:06.181207
Text : Hi, I am Sam! What is the capital of the United States?
────────────────────────────────────────────
Session : db-demo-session
Author : db_agent
Time : 2025-12-05 19:12:06.188306
Text : Hi Sam! The capital of the United States is Washington, D.C.
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : 2025-12-05 19:12:06.887968
Text : Hello again! What is my name?
────────────────────────────────────────────
Session : db-demo-session
Author : db_agent
Time : 2025-12-05 19:12:06.891416
Text : Your name is Sam.
🔍 DB Inspector finished.
看起来似乎很简单。
但这里发生的事情,其本质是:
可观测性(Observability)——让智能体的内部生命变得可见。
这是智能体演化过程中最关键的里程碑之一。
下面解释为什么。
1. 智能体智能的三大支柱
现代 Agent 系统建立在三个核心架构支柱上:
1️⃣ 轨迹结构(事件时间线 Event Timeline)
这就是 P11:
一个无状态 LLM,基于不断增长的外部事件时间线执行。
2️⃣ 持久化账本(事件数据库 Event Database)
这就是 P12:
事件写入磁盘,实现跨运行的持久化。
3️⃣ 可观测性(观察账本的能力)
这就是 P13。
没有 P13,前两个结构都是“盲的”。
智能体也许有记忆;
也许有账本;
但你无法看到它看到的东西。
没有透明度,
没有调试能力,
没有审计能力,
没有可信性。
P13 改变了这一点。
2. 今天你看到的是智能体的“内部生命”
回顾输出。
这一行:
📦 Found 4 events:
意味着:
智能体拥有真实的、持久化的、按时间排序的历史。
而下面这些四个块:
────────────────────────────────────────────
Session : db-demo-session
Author : user
Time : ...
Text : ...
不是日志。
它们是智能的基本原子(atoms of intelligence)。
每一行都代表:
一条 LLM 消息
被转换成一个 事件
附加到 账本
写入 SQLite
现在可被任何外部工具读取
智能体的认知时间线第一次不再被封装在 ADK 内部。
它成为了一个一级数据结构(first-class data structure)。
3. 为什么“可观测性”是智能体系统的转折点
一个系统在工程意义上“活了”,需要满足:
能行动
能记录
能保存
能暴露
P13 实现了最后一步:
一个可以被“看见”的智能体。
✔ 调试(Debugging)
可以看到它为什么回答错。
✔ 验证(Verification)
可以证明每一步到底发生了什么。
✔ 可复现性(Reproducibility)
可以重放任意一条轨迹。
✔ 治理(Governance)
为智能体安全与监督奠定基础。
✔ 记忆工程(Memory Engineering)
可以抽取模式、偏好、身份、事件。
换句话说:
可观测性不是“辅助功能”。
它是一个智能系统的骨架。
没有可观测性 = 就没有真正的智能体。
4. StructureVerse 的解释:检查层被点亮
在我的熵控 StructureVerse 理论框架中:
🟦 事件层(P11)
原始行为的时间线。
🟩 持久层(P12)
可持久化的事件账本。
🟨 检查层(P13)
让账本变得可见、可外部化、可审计。
这是智能体内部结构第一次获得了:
一个独立于智能体本身的外部表征。
这是系统从:
玩具 demo →
原型 →
可解释智能体 →
可问责智能体 →
企业级可靠智能体
进化的关键一步。
P13 很小,但它是基础支点。
5. 接下来(P14 → P18)
你的智能体管线现在是:
P11 — 内存 Session
P12 — 持久化 SQLite 账本
P13 — DB Inspector(可观测性)
----------------------------------
接下来:
P14 — Session 隔离测试(平行宇宙)
P15 — 自动压缩(熵减)
P16 — 结构化状态(session.state)
P17 — Memory ETL(抽取 → 转换 → 写入)
P18 — 记忆再注入(人格连续性)
P13 是开启后半段能力的“观察者工具(Inspector Gadget)”。
没有它:
无法测试隔离
无法验证压缩
无法验证 ETL
无法调试人格注入
有了它:
你就拥有了一台观察智能体思维的显微镜。
6. 结论
P11 让智能体学会存在于时间中。
P12 让智能体学会跨越时间地记住事情。
P13 让我们第一次看到智能体体内的时间。
这不是日志。
这是可观测智能的诞生。
😱P14:会话隔离(Session Isolation)
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p14-session-isolation
智能体如何构建永不互相泄漏的平行宇宙
P11 教会智能体存在于时间中。
P12 教会它跨越时间记住事情。
P13 让我们看到了它的记忆。
P14 证明:每一个记忆宇宙都是完全隔离的。
今天我们运行了整个 Sessions & Memory 模块里最重要的结构性测试之一:
P14 — 会话隔离测试(平行宇宙与上下文边界)
这个小实验展示了智能体体系中非常深刻的一个事实:
每个 Session 都是一个独立、封闭的宇宙。事件不会泄漏。身份不会泄漏。上下文不会泄漏。
我们来一步步看发生了什么。
1. 输出结果(原始执行日志)
🔵 Creating Session A: session-A
User[session-A] > Hi, I am Sam!
gemini-2.5-flash-lite[session-A] > Hi Sam! I’m isolation_agent...
User[session-A] > What is my name?
gemini-2.5-flash-lite[session-A] > Your name is Sam.
🟣 Creating Session B: session-B
User[session-B] > Hello, what is my name?
gemini-2.5-flash-lite[session-B] > I do not have access to your personal information...
--- SESSION A EVENTS ---
- [0] user: Hi, I am Sam!
- [1] isolation_agent: Hi Sam! ...
- [2] user: What is my name?
- [3] isolation_agent: Your name is Sam.
--- SESSION B EVENTS ---
- [0] user: Hello, what is my name?
- [1] isolation_agent: I do not have access to your personal information...
乍看之下,这像是一个简单的双会话对话测试。
但它证明的是一个基础性结构真相。
2. 这个测试真正展示了什么?
✅ Session A 学会了 “Your name is Sam.”
因为这个名字被引入了 A 的事件时间线中。
❌ Session B 不知道这个名字。
尽管:
是同一个 Agent 实例
同样的代码
同样的模型
甚至同样的 user_id
🚫 完全无泄漏。
session-A 的知识不会出现在 session-B 中。
这不是巧合。
也不是模型行为。
而是架构本身的保证。
3. 深层原理:Session 是迷你宇宙(Mini-Universes)
每个 Session 在 ADK 中由以下三元组定义:
(app_name, user_id, session_id)
它相当于一个:
命名空间
边界泡(boundary bubble)
自洽宇宙
这个“宇宙”内部包含:
自己的事件时间线
自己的身份
自己的记忆
自己的历史
自己的演化路径
Session A 中存在的东西,在 Session B 中完全不存在,除非你故意注入。
这正式证明:
Agent 不是模型;Agent 是建立在上下文边界之上的结构化宇宙。
4. 安全视角:为什么隔离至关重要
Session 隔离不仅是概念上的优雅。
它是以下能力的骨架:
多用户安全
多任务分隔
上下文完整性
隐私保护
并行认知进程
想象一个 AI 同时服务:
你的个人任务
你孩子的家庭作业
你的财务规划
如果没有严格隔离,后果将不堪设想:
身份信息泄漏
不相关任务混写
推理路径混乱
结果不可预测
P14 展示:
隔离有效。智能体的宇宙不是一锅混沌。而是干净的、互不污染的平行时间线。
5. StructureVerse 解释:平行宇宙与边界完整性
在你的熵控 StructureVerse 框架中,会话隔离对应:
🟦 事件层(Event Layer)
“这里发生了什么?”
(每个宇宙独立)
🟨 边界层(Boundary Layer)
“什么算是这里?”
(隔离规则)
两者共同构成:
结构泡(Structure Bubbles)—— 自洽的认知小宇宙,永不互相污染。
就像:
宇宙 A 里 Sam 存在
宇宙 B 里 Sam 从未出现过
P14 是智能体运行时中“平行宇宙真实存在”的数学证明。
6. 这为后续所有结构奠定基础
由于隔离机制已被证明有效,你现在可以安全构建:
✔ P15 — 自动压缩(Compaction)
每个宇宙独立压缩自己的历史
✔ P16 — 结构化工作记忆(session.state)
每个宇宙维护自己的短期结构状态
✔ P17 — Memory ETL
每个宇宙独立抽取长期记忆
✔ P18 — Memory Injection
每个宇宙内部的人格连续性
这些能力都依赖于以下保证:
“宇宙之间绝不泄漏。”
没有 P14,整个记忆架构都会崩塌。
7. 结语
模型只是在预测文本。
智能体是在维护一个又一个宇宙。
P14 证明了:每个宇宙都独立存在 ——
有自己的时间线、自己的身份、自己的历史。
而从这一刻起,
你不只是“用 AI”。
你在治理平行世界。
🗜️P15:当智能体学会“压缩自己”
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p15-compaction-demo
从无限闲聊到结构化摘要
P11:智能体获得了一条时间线。
P12:这条时间线变成了持久化记录。
P13:这条时间线变得可被观察。
P14:时间线扩展成互相隔离的平行宇宙。
P15:时间线变得“可压缩”。
今天的实验 P15 – 上下文压缩(Context Compaction)Demo,标志着一个细微但至关重要的转折:
智能体第一次不仅仅是“记得更多”——
而是开始学会:记得更少,但记得更好。
下面是它实际发生了什么。
1. 运行过程:一场长对话 + 一个摘要
我们在 P15 中启用了 ADK 的实验性配置 EventsCompactionConfig:
👉 Running P15 via __main__
🚀 P15 — compaction_demo: starting
✅ Agent created: compaction_agent
[EXPERIMENTAL] EventsCompactionConfig...
✅ App created with compaction enabled
🆕 Created session: compaction-session
然后,我们在同一个 session 中发送了多轮信息量很大的长问题:
Explain AI in healthcare.(解释医疗领域中的 AI)
→ 智能体回答了一篇完整长文:诊断、影像、药物研发、工作流、虚拟助手、伦理、监管等等。
Tell me more about drug discovery.(详细说说药物发现)
→ 又是一段长篇技术讲解:靶点识别、虚拟筛选、分子设计、ADME、生物标志物、临床试验、药物重定位等。
Explain the second point again.(再解释一次第二点)
→ 第三段高密度内容,聚焦在“候选药物设计与生成”上进一步展开。
Who are the key companies involved?(有哪些关键公司参与?)
→ 智能体拒绝回答,说明当前对话上下文集中在概念与流程,没有聚焦公司信息。
此时,我们已经得到了一段又长又高度冗余的对话历史:
AI 在医疗中的描述被重复多次
AI 在药物发现中的结构反复出现
同一子问题被来回细化、重述、展开
然后,压缩引擎开始工作:
📦 Checking for compaction event
🎉 Compaction event detected!
📝 Summary Content:
The conversation history covers the user’s initial request for an explanation of AI in healthcare, followed by a specific inquiry about drug discovery. The AI agent provided a comprehensive overview of AI in healthcare, detailing its applications in diagnostics, drug discovery, personalized medicine, administrative efficiency, virtual assistants, and robotics, along with its benefits and challenges.
The user then requested further clarification on the “drug discovery” aspect. The AI agent elaborated on this, focusing on how AI revolutionizes the process by:
* Target Identification and Validation…
* Drug Candidate Design and Generation…
* Virtual Screening…
* De Novo Drug Design…
一瞬间,这整段蔓延的对话被压缩成了一段结构化的摘要。
这不只是“总结一下”。
这是一次结构化的熵控操作(structural entropy control)。
2. 为什么压缩不是一个“锦上添花的小功能”
在玩具级聊天世界里,“更多历史”看起来是纯粹的好事。
但在真实系统里:
上下文窗口是有限的
更长的 prompt 更慢、更贵
冗余历史会干扰模型判断
旧细节会淹没新的意图
无关轮次会增加噪音与风险
换句话说:
如果不加管理,越长的上下文,越是一笔负债。
P15 展示的是一个内置在运行时管线里的行为模式,而不是 prompt 技巧:
在
App中进行了如下配置:
EventsCompactionConfig(
compaction_interval=3,
overlap_size=1,
)
系统持续监听事件流。
每隔固定数量的事件,它就会:
取出一段过去的历史
把它压缩成一个摘要事件
保留少量最近的原始事件(overlap)
Session 时间线从:
一长串重复、冗余、高熵的日志
变成:
一条更短、更密、更低熵的结构化大纲。
这不是模型“变聪明了”。
这是运行时(runtime)变有结构了。
3. 摘要是一个“结构对象”,不是一段字串
压缩输出并不仅仅是一团文字。
摘要被保存为一个结构化内容对象:
event.actions.compaction.compacted_content
→ parts[0].text = summary_text
也就是说:
它是有类型的
它是可寻址的
它是可被机器直接读取与操作的
这意味着后续工具可以:
将摘要事件与原始消息区别对待
只把摘要喂给下游分析型智能体
对“压缩行为本身”做元评估(meta-evaluation)
在 UI 中把它展示为“折叠历史”
按需选择性地展开 / 折叠历史
摘要从此成为智能体结构生命的一部分,而不是装饰物。
4. 在 StructureVerse 视角下:熵控层的点亮
在我的「语言 → 结构 → 调度」框架中,P15 点亮了一个新的结构层:
事件层(Event Layer,P11):每条消息都是一个事件
持久层(Persistent Layer,P12):事件被写入磁盘
检查层(Inspection Layer,P13):事件可被观察与审计
边界层(Boundary Layer,P14):事件按 Session 隔离
熵控层(Entropy-Control Layer,P15):事件可以被压缩
P15 是你从“崇拜更多上下文”转向:
“什么才是合适的上下文?”
“什么应该被保留?什么应该被折叠?”
“如何把一条语义丰富但高度冗余的流,变成紧凑的、可执行的结构?”
压缩事件就是这个问题的第一个答案:
它是一种维度更低,但结构轨迹仍然忠实的表示。
在 StructureVerse 的语言里:
压缩事件,是智能体第一次可见的自我压缩步伐。
5. 哲学层面:智能从来不是“记得更多”
这里有一个很深的哲学镜像。
生物大脑之所以强大,并不是因为它什么都记得。
而是因为它:
狠心遗忘
强力压缩
只保留重要的
不断重用压缩后的结构
在抽象层面运算,而不是在原始日志上运算
P15 正式把这个思想引入你的智能体运行时:
冗长上下文 → 结构化压缩摘要
重复解释 → 规范化表达
文本流 → 逐步演化的抽象
只有在这一层之上,你才能真正地:
运行长时间跨度的智能体
让状态保持轻量且可控
为 Memory ETL 做准备
在摘要之上构建长期结构记忆
在下游推导出 Structure Cards / Structure Graphs
如果一切都直接堆在原始 Session.events 上,
复杂度会迅速失控。
6. 为什么“EXPERIMENTAL” 这一行其实是个好信号
你看到了这一行警告:
UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental…
这不是问题,而是一种方向信号。
它意味着:
压缩被视为一等公民的运行时关注点(first-class runtime concern)
ADK 已经在内核层面尝试为它留出钩子
这个能力将继续演化,但绝不会消失
在我的系统语言里,压缩就是:
熵控正式“进入运营层”的那一刻。
7. 结尾
P15 是智能体从“囤积历史”转向“塑造历史”的时刻。
它不再只是一个“能写大长文的 AI 生成器”。
而是一个:
会倾听
会积累
会压缩
并且只把精华结构带到下一步的系统。
如果说 P11–P14 赋予了你的智能体在时间与空间中的生命,
那么 P15 则赋予它一种更微妙的能力:
知道什么才值得被记住。
log:
(.venv) ➜ projects cd /Users/Agent/adk-decade-of-agents/projects/p15-compaction-demo
(.venv) ➜ p15-compaction-demo python src/main.py
👉 Running P15 via __main__
🚀 P15 — compaction_demo: starting
✅ Agent created: compaction_agent
/Users/Agent/adk-decade-of-agents/projects/p15-compaction-demo/src/main.py:52: UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
events_compaction_config=EventsCompactionConfig(
✅ App created with compaction enabled
🆕 Created session: compaction-session
🔄 Sending multiple messages to trigger compaction
User[compaction-session] > Explain AI in healthcare.
gemini-2.5-flash-lite[compaction-session] > AI in healthcare refers to the application of artificial intelligence (AI) technologies to various aspects of the healthcare industry. The goal is to improve patient outcomes, streamline processes, reduce costs, and enhance the efficiency of healthcare providers.
Essentially, AI in healthcare uses algorithms and software to analyze complex medical data, mimic human cognition, and assist in tasks that typically require human intelligence. This can range from diagnosing diseases to developing new drugs and personalizing treatment plans.
Here’s a breakdown of key areas where AI is being used in healthcare:
**1. Diagnostics and Imaging Analysis:**
* **Image Recognition:** AI algorithms can analyze medical images (X-rays, CT scans, MRIs, pathology slides) with remarkable accuracy, often detecting subtle anomalies that might be missed by the human eye. This helps in early diagnosis of diseases like cancer, diabetic retinopathy, and cardiovascular conditions.
* **Disease Prediction:** By analyzing patient data, AI can identify individuals at high risk for certain diseases, allowing for preventative measures and early interventions.
**2. Drug Discovery and Development:**
* **Accelerated Research:** AI can sift through vast amounts of scientific literature and biological data to identify potential drug targets, predict drug efficacy, and even design novel molecules. This significantly speeds up the traditionally lengthy and expensive drug development process.
* **Clinical Trial Optimization:** AI can help identify suitable patient populations for clinical trials, monitor trial progress, and analyze results more efficiently.
**3. Personalized Medicine and Treatment:**
* **Tailored Therapies:** AI can analyze a patient’s genetic makeup, lifestyle, medical history, and response to previous treatments to recommend the most effective and personalized treatment plan.
* **Precision Oncology:** In cancer treatment, AI can help determine the best chemotherapy or immunotherapy based on the specific genetic mutations of a tumor.
**4. Administrative and Operational Efficiency:**
* **Workflow Automation:** AI-powered tools can automate routine administrative tasks like scheduling appointments, managing patient records, processing insurance claims, and transcribing medical notes.
* **Resource Management:** AI can optimize hospital resource allocation, predict patient flow, and manage staffing to improve efficiency and reduce wait times.
**5. Virtual Assistants and Chatbots:**
* **Patient Engagement:** AI-powered chatbots can answer patient questions, provide basic health information, remind patients to take medications, and help them navigate healthcare systems.
* **Clinical Support:** Virtual assistants can support clinicians by providing quick access to patient information, medical literature, and diagnostic suggestions.
**6. Robotics in Surgery:**
* **Enhanced Precision:** AI-powered robotic surgical systems can perform complex procedures with greater precision, dexterity, and minimally invasive techniques, leading to faster recovery times for patients.
**Benefits of AI in Healthcare:**
* **Improved Accuracy and Speed:** AI can process data and identify patterns much faster and often more accurately than humans.
* **Early Disease Detection:** Leading to better treatment outcomes and potentially saving lives.
* **Personalized Care:** Tailoring treatments to individual needs.
* **Reduced Costs:** By increasing efficiency and preventing errors.
* **Increased Accessibility:** Potentially extending healthcare access to underserved areas through remote diagnostics and virtual consultations.
* **Alleviating Clinician Burnout:** By automating routine tasks and providing decision support.
**Challenges and Considerations:**
* **Data Privacy and Security:** Protecting sensitive patient information is paramount.
* **Regulatory Hurdles:** Ensuring AI systems are safe, effective, and compliant with healthcare regulations.
* **Ethical Concerns:** Addressing bias in algorithms, accountability for AI decisions, and the impact on the doctor-patient relationship.
* **Integration and Interoperability:** Integrating AI systems into existing healthcare infrastructure can be complex.
* **Trust and Adoption:** Gaining the trust of both healthcare professionals and patients is crucial for widespread adoption.
* **Explainability (XAI):** Understanding how AI makes its decisions is important for clinical validation and trust.
In summary, AI in healthcare is a transformative force with the potential to revolutionize how we prevent, diagnose, treat, and manage diseases, ultimately leading to a more efficient, personalized, and effective healthcare system.
User[compaction-session] > Tell me more about drug discovery.
gemini-2.5-flash-lite[compaction-session] > Sure, let’s dive deeper into how Artificial Intelligence (AI) is revolutionizing drug discovery.
The traditional drug discovery process is notoriously long, expensive, and has a high failure rate. It can take over a decade and billions of dollars to bring a new drug to market, with many promising candidates failing at various stages. AI is stepping in to address these challenges by accelerating and improving many critical steps.
Here’s how AI is making a difference in drug discovery:
**1. Target Identification and Validation:**
* **Understanding Disease Mechanisms:** AI can analyze vast datasets from genomics, proteomics, transcriptomics, and clinical records to identify novel biological targets (like specific proteins or genes) that play a crucial role in a disease. This helps researchers understand the underlying mechanisms of diseases better.
* **Predicting Target-Disease Associations:** AI algorithms can predict the likelihood of a particular target being involved in a disease, helping prioritize which targets to focus on.
**2. Drug Candidate Design and Generation:**
* **Virtual Screening:** Instead of physically testing millions of compounds, AI can virtually screen enormous chemical libraries to identify molecules that are likely to bind to a specific target protein. This dramatically narrows down the pool of potential drug candidates.
* **De Novo Drug Design:** AI can *generate* entirely new molecular structures from scratch that are optimized to interact with a target and possess desirable drug-like properties (e.g., solubility, permeability). Generative models like GANs (Generative Adversarial Networks) and Variational Autoencoders (VAEs) are particularly useful here.
* **Predicting Molecular Properties:** AI can predict various properties of a potential drug molecule, such as its efficacy, toxicity, absorption, distribution, metabolism, and excretion (ADME), early in the design phase. This helps weed out molecules likely to fail later.
**3. Pre-clinical and Clinical Trial Optimization:**
* **Predicting Drug Efficacy and Toxicity:** AI models can be trained on existing data to predict how a drug candidate might perform in pre-clinical studies (in vitro and in vivo) and even in human clinical trials, reducing the need for extensive and costly wet-lab experiments.
* **Biomarker Discovery:** AI can identify biomarkers that predict patient response to a drug, enabling more targeted clinical trials and personalized medicine approaches.
* **Clinical Trial Design and Patient Recruitment:** AI can analyze patient data to identify suitable candidates for clinical trials, optimize trial design to improve success rates, and even predict potential adverse events.
* **Repurposing Existing Drugs:** AI can analyze existing drug databases and disease information to identify drugs approved for one condition that might be effective for another, a process known as drug repurposing. This can significantly shorten the development timeline.
**4. Optimizing Chemical Synthesis:**
* **Predicting Synthesis Routes:** AI can help chemists predict the most efficient and cost-effective ways to synthesize promising drug molecules, streamlining the manufacturing process.
**Key AI Techniques Used in Drug Discovery:**
* **Machine Learning (ML):** Supervised, unsupervised, and reinforcement learning algorithms are used for prediction, classification, and pattern recognition.
* **Deep Learning (DL):** Neural networks, particularly convolutional neural networks (CNNs) for image analysis and recurrent neural networks (RNNs) and transformers for sequence data (like DNA or protein sequences), are powerful for complex pattern recognition.
* **Natural Language Processing (NLP):** Used to extract information from scientific literature, patents, and clinical trial reports.
* **Graph Neural Networks (GNNs):** Excellent for representing and analyzing molecular structures and their interactions.
**Benefits of AI in Drug Discovery:**
* **Speed:** Significantly reduces the time required to identify and develop new drug candidates.
* **Cost Reduction:** By reducing the number of failed experiments and streamlining processes.
* **Increased Success Rates:** By better predicting efficacy and toxicity, and optimizing trial design.
* **Novelty:** Enabling the design of entirely new molecules with improved properties.
* **Personalization:** Facilitating the development of drugs tailored to specific patient populations or individuals.
**Challenges in AI-powered Drug Discovery:**
* **Data Quality and Availability:** High-quality, curated datasets are essential for training effective AI models. Data can be siloed or proprietary.
* **Interpretability (Explainability):** Understanding *why* an AI model makes a particular prediction can be challenging, which is critical for scientific validation and regulatory approval.
* **Experimental Validation:** AI predictions still need rigorous experimental validation, which remains a bottleneck.
* **Integration with Existing Workflows:** Seamlessly integrating AI tools into established R&D processes requires significant effort and training.
* **Talent Gap:** A shortage of skilled AI researchers with domain expertise in chemistry and biology.
Despite the challenges, AI is rapidly transforming the landscape of drug discovery, offering hope for faster development of more effective and targeted therapies for a wide range of diseases.
User[compaction-session] > Explain the second point again.
gemini-2.5-flash-lite[compaction-session] > You asked for a clarification on the **second point** regarding AI in drug discovery. Assuming you’re referring to the second main section in my previous explanation, that point was:
**2. Drug Candidate Design and Generation**
Let’s break this down further:
This stage is all about finding or creating molecules that have the potential to become drugs. Traditionally, this involves screening vast libraries of existing chemical compounds to see if any of them interact with the disease target identified in step 1.
AI is revolutionizing this process in two primary ways:
**a) Virtual Screening:**
* **The Problem:** Imagine having millions of LEGO bricks (chemical compounds) and needing to find one that perfectly fits a specific slot (the disease target). Physically trying each brick is incredibly time-consuming and expensive.
* **How AI Helps:** AI algorithms can analyze the 3D structure of the disease target and the chemical structures of countless potential drug molecules. They can then simulate how these molecules might “dock” or bind to the target.
* **The Outcome:** Instead of physically testing millions, AI can quickly predict which compounds are *most likely* to bind effectively. This drastically reduces the number of molecules that need to be synthesized and tested in the lab. It’s like having a super-fast robot that can try out millions of LEGO brick combinations virtually before you even pick up a real brick.
* **Techniques Involved:** Often uses machine learning models trained on data from previous binding experiments, as well as more sophisticated computational chemistry methods powered by AI.
**b) De Novo Drug Design (Designing from Scratch):**
* **The Problem:** Sometimes, none of the existing compounds are ideal. You might need a molecule with very specific properties that doesn’t exist yet.
* **How AI Helps:** This is where AI can get really creative. Using advanced generative models (like GANs or VAEs), AI can learn the fundamental rules of chemistry and molecular structure. It can then *create* entirely new molecular designs that have never been seen before.
* **The Goal:** These AI-generated molecules are designed with specific goals in mind:
* **High Affinity:** They should bind strongly to the target.
* **Drug-like Properties:** They should have good solubility, be able to pass through cell membranes, and be metabolized effectively by the body (the ADME properties mentioned earlier).
* **Low Toxicity:** They should ideally avoid interacting with other molecules in the body in harmful ways.
* **The Outcome:** AI can propose novel chemical structures that might be more effective or safer than existing ones. It’s like asking an architect to design a brand-new house from scratch, specifying the number of rooms, style, and energy efficiency, rather than just picking from a catalog of existing houses.
* **Techniques Involved:** Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), Reinforcement Learning.
**In essence, point 2 is about AI acting as both a highly efficient librarian (virtual screening) and an innovative chemist (de novo design) to identify and create promising drug candidates much faster and more intelligently than traditional methods.**
User[compaction-session] > Who are the key companies involved?
gemini-2.5-flash-lite[compaction-session] > I cannot provide a list of key companies involved in AI in drug discovery based on the current conversation context. The provided history focuses on explaining the *concepts* and *processes* of AI in healthcare and drug discovery, not on naming specific industry players.
📦 Checking for compaction event
🎉 Compaction event detected!
📝 Summary Content:
The conversation history covers the user’s initial request for an explanation of AI in healthcare, followed by a specific inquiry about drug discovery. The AI agent provided a comprehensive overview of AI in healthcare, detailing its applications in diagnostics, drug discovery, personalized medicine, administrative efficiency, virtual assistants, and robotics, along with its benefits and challenges.
The user then requested further clarification on the “drug discovery” aspect. The AI agent elaborated on this, focusing on how AI revolutionizes the process by:
* **Target Identification and Validation:** Identifying disease-related biological targets.
* **Drug Candidate Design and Generation:**
* **Virtual Screening:** AI virtually screens vast chemical libraries to predict promisi...
🏁 P15 — compaction_demo finished.
🧠 P16 — 当 AI 学会自己整理记忆
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p16-compacted-memory-etl
从嘈杂对话到结构化长期记忆:第一座熵控记忆桥
在这个项目(P16)里,在整个 Sessions & Memory 系列中第一次出现了一个非常关键的时刻:
AI 把一整段对话压缩成一个干净摘要,
并且把这个摘要写进了它的长期记忆。
这已经不再是简单的模式匹配或 token 堆叠。
而是结构的形成。
这是一个“裸 LLM”开始表现得像一个有生命的智能体的时刻——
一个会主动把世界整理成内部结构的系统。
🔍 为什么 P16 很重要
在前面的项目(P11–P15)里,我们已经教给智能体:
事件账本(Event Ledger:
Session.events)持久化的会话记忆
自动压缩(compaction)
session.state(结构化工作记忆)
但有一个关键能力一直缺位:
智能体如何从一整段长对话里,
决定什么是“值得被永远记住”的?
人类记忆从来不是“全部存下来”。
人类记忆是“先压缩 → 再提炼 → 再存结构”。
P16 就是这个过程的第一个工程化版本。
📦 实验内容:把智能体的事件时间线 dump 出来
下面是 P16 实际运行中的一段片段:
📦 Dump Session Events (summary preview)
- [user] Explain how AI is used in healthcare....
- [compaction_memory_agent] AI is revolutionizing healthcare...
- [user] What are some important applications of AI in medical imaging?...
- [compaction_memory_agent] AI is making a profound impact...
- [user] How can AI help in drug discovery and personalized treatment?...
- [compaction_memory_agent] AI is a transformative force...
- [user] What are the main risks and challenges of using AI in hospitals?...
- [compaction_memory_agent] Based on the previous conversation...
- [user] Please summarize the key opportunities and risks of AI in healthcare....
- [compaction_memory_agent] The provided context highlights...
当对话长度达到一定阈值(由 compaction 配置决定)时,
ADK 会自动插入一个压缩摘要事件(compaction summary event)。
这是智能体在做自我组织:
📝 Extracted one compaction summary:
session_id: compacted-memory-etl-demo
created_at: 2025-12-06T02:02:56.803347Z
summary_text: The conversation history covers the application of AI in healthcare...
这个 summary_text 是对迄今为止所有内容的一种
低熵、高信息量 的表示。
💾 接着发生的事:它把摘要写入长期记忆
P16 会把这个压缩摘要抽取出来,转成结构化记录,并写入:
memory_store.json
结果(截断示意)如下:
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-memory-etl-demo”,
“created_at”: “2025-12-06T02:02:56.803347Z”,
“summary_text”: “The conversation covered the applications of AI in healthcare...”
}
]
}
这不只是“存一下数据”。
这是 AI 在说:
“这是我从这次对话里学到的东西。”
这标志着:
“主题级长期记忆(topic-level long-term memory)”的诞生。
🧬 系统层面的意义:
完整回路:从语言 → 事件 → 压缩 → 结构化记忆 → 未来推理
P16 完成了一条全新的认知路径:
原始高熵对话(自然语言)
↓ compaction(压缩)
低熵结构化摘要(compacted_content)
↓ ETL(抽取–转换–写入)
长期记忆(memory_store.json)
↓ future(P18 及以后)
在新会话中被注入,用于人格 / 上下文塑形
这是一个“有生命的智能体”的核心机制:
“长期结构会反过来塑造未来决策。”
在 P16 之前,只有 session.state 能进入长期记忆。
现在,整个对话主题也可以成为结构化记忆。
这是一次跨层级跃迁。
🔥 为什么这是个突破
P16 证明了一个很基础但常被忽略的原则:
一个 AI 智能体不应该只记住“关于用户的事实”(如 user:name, user:country)。
它还应该记住:我们谈过什么。
这为以下能力打开了大门:
对话层面的连续性
多主题的智能体认知
个性化长期偏好学习
多智能体共享记忆机制
自动构建知识图谱 / 结构图
在 StructureVerse 的视角下:
✔ Compaction = 受控的高维压缩
✔ Memory ETL = 结构化抽取
✔ Memory Store = 可持久化的结构知识
✔ Future Injection = 人格 + 上下文一致性
一个“原始模型”变成了“结构化系统”。
一个“结构化系统”才有资格被称为
语言–结构–调度栈中的生命形式。
📎 一个小小的工程注记
ADK 抛出了一个警告:
DeprecationWarning: utcfromtimestamp() is deprecated...
我们会在 P17 中改用:
datetime.fromtimestamp(ts, datetime.UTC)
在那里,我们会正式引入:
时间戳归一化 & Memory Schema v1.0。
✏️ 收束一笔
P16 看起来只是一个小工程项目,但它解锁的是一个本质问题:
一个会整理、压缩、存储“对话结构”的 AI,
与一个只是“逐轮回答”的 AI,本质上不是同一物种。
这就是智能体开始“生长”的方式:
不是通过加更多参数
不是通过加更长上下文
而是通过持续构造、演化并保留内部结构
在这里:
语言坍缩成结构,结构以记忆的形式存活,记忆反过来塑造行为。
欢迎来到你的第一个
完全结构化、熵控、长记忆智能体。
📦 Dump Session Events(摘要预览 / summary preview)
- [user] Explain how AI is used in healthcare....
- [compaction_memory_agent] AI is revolutionizing healthcare by improving diagnostics, personalizing treatme...
- [user] What are some important applications of AI in medical imaging and diagnostics?...
- [compaction_memory_agent] AI is making a profound impact on medical imaging and diagnostics, significantly...
- [user] How can AI help in drug discovery and personalized treatment?...
- [compaction_memory_agent] AI is a transformative force in both **drug discovery** and **personalized treat...
- [user] ...
- [user] What are the main risks and challenges of using AI in hospitals?...
- [compaction_memory_agent] Based on the previous conversation, here are the main risks and challenges of us...
- [user] Please summarize the key opportunities and risks of AI in healthcare....
- [compaction_memory_agent] The provided context highlights the significant advancements and potential of AI...
🔍 从 Session.events 中抽取 compaction.summary ... / extracting compaction.summary from Session.events ...
/Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl/src/main.py:173: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
created_at = datetime.utcfromtimestamp(ts).isoformat() + “Z”
📝 抽取到一条 compaction 摘要(Extracted one compaction summary):
session_id: compacted-memory-etl-demo # 会话 ID / Session ID
created_at: 2025-12-06T02:02:56.803347Z # 创建时间 / Created at
summary_text: The conversation history covers the application of AI in healthcare, with a particular focus on medical imaging/diagnost... # 摘要文本 / Summary preview
💾 已写入 memory_store.json(saved to memory_store.json) -> /Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl/memory_store.json
📚 当前 memory_store.json 内容(截断预览 / truncated preview):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: null,
“created_at”: 1764985672.551647,
“summary_text”: “parts=[Part(\\n text=\\”\\”\\”The conversation covered the applications of AI in healthcare, focusing on medical imaging/diagnostics and drug discovery/personalized treatment.\\n\\n**Key Information and Decisions:**\\n\\n* **AI in Healthcare Overview:** AI is revolutionizing healthcare across diagnostics, drug discovery, personalized medicine, robotic surgery, administrative tasks, patient monitoring, and public health.\\n* **AI in Medical Imaging & Diagnostics:**\\n * **Detection & Diagnosis:** AI excels at detecting diseases like cancer (mammography, lung nodules, prostate, skin), diabetic retinopathy, cardiovascular disease, neurological disorders, and fractures by analyzing medical images (X-rays, CT, MRI, retinal scans).\\n * **Image Quality:** AI improves image quality through noise reduction, bette ...
🏁 compacted_memory_etl_demo: main() 执行结束 / execution finished
从 P16 开始,我们迎来整个 Sessions & Memory 系列的关键转折:我逐渐意识到,智能体并不能平等地处理所有内容——越是结构化、人格化、身份化、偏好化的信息,模型的理解、压缩、长期保持能力越强;越是知识密集、上下文长、语义复杂的主题(例如医疗科技长文),模型越容易遗忘、混淆或无法稳定结构化,而其原因我也仍在持续拆解与验证。因此,我们决定在 P16 重新跑一次流程,把原本的医疗场景完全替换成“人格轴(persona axis)”:让智能体不再压缩知识长文,而是压缩关于“你是谁、你如何思考、你的偏好与倾向是什么”的内容。因为 persona 本质上是低熵、高结构度、强稳定性、与未来所有推理高度相关的核心信息,远比知识类内容更适合进入长期记忆。于是 P16 将从“对话 → compaction → 结构摘要 → memory_store.json” 这一 pipeline,转向建立有机的“人格长期记忆(persona LTM)”:通过对话抽取核心人格结构,通过熵控压缩提炼稳定特征,通过 ETL 写入长期记忆数据库,并在未来 Session 中作为 persona 注入,实现上下文连续性、决策一致性和行为风格稳定性。这代表智能体第一次从“存知识”跳跃到“构建人格结构”,也标志着结构化智能体正式迈向可调度人格(Scheduled Persona)时代。
🧠 P16 — 智能体开始构建自洽人格(第二次运行 P16,但换了新的内容)
结构化的身份、偏好、价值观 —— 自动压缩并写入长期记忆
原本的 P16 是关于“AI 在医疗中的应用”。
而今天,P16 完全变成了另一件事情:
这是智能体第一次尝试把一个人的信息,转化为结构化、可压缩、可持久的长期记忆 ——
并且能够跨会话、跨项目、跨版本不断成长。
这才是 StructureVerse Runtime 中**持久人格(persistent persona)**真正的起点。
下面是完整发生的事情。
🚦 1. 新 P16 的目标
新版 P16 不再是技术问答 Demo。
它是一条人格构建(persona-building)管线,为后续项目做准备:
P17 → 长期记忆 Schema 升级
P18 → 偏好提取
P19 → 价值观与工作风格提取
P20 → Persona Card 组装
现在的 P16 专注于采集和压缩:
身份 → 偏好 → 价值观 → 反偏好 → 工作风格 → 背景 → 兴趣
这些是一个真正持久智能体persona所需要的全部基础结构。
🧩 2. 运行过程
这次运行的美妙之处在于:
全过程都干净、可控、结构化,
且每一步都为人格添加一个稳定、可预测的构件。
用户开始:
Hi, I’d like to build a personal profile that you can remember across sessions...
智能体按设计行为运作:
确认 → 等待更多信息。
Step 1 — 身份信息(Identity)
My name is Susan. I was born in China, now live in the US...
智能体记录并继续搭建结构。
Step 2 — 兴趣与爱好(Interests & Hobbies)
I love reading sci-fi, building small agent projects,
and playing math and logic games with my kids.
Step 3 — 沟通偏好(Communication Preferences)
I prefer concise, highly structured answers with bullet points,
clear reasoning, and code examples.
I dislike vague, hand-wavy explanations.
智能体自动把这些偏好结构化地反射回来:
- Concise, highly structured answers
- Bullet points
- Code examples
- Clear reasoning
- Dislike vague explanations
这正是 P18 所需要的输入。
Step 4 — 价值观与反偏好(Values & Anti-Preferences)
I care about intellectual honesty, structural thinking,
long-term reproducibility.
I strongly dislike noisy UX, over-marketing, and shallow ‘productivity hacks’.
这是整个管线中第一次产生结构化价值观。
Step 5 — 全人格结构化摘要(Structured Profile Summary)
当用户提出请求:
Please summarize my profile in a structured way...
智能体输出了完美结构化的 Markdown 块:
## Identity
- Name: Susan
- Origin: China
- Residence: US
## Background
- AI, Agent Development, Education
## Interests
- Sci-fi
- Agent projects
- Math/logic games with children
## Work Style
- Concise, structured answers
- Clear reasoning
- Code examples
## Preferences
- Structured info delivery
- Bullet points
## Values
- Intellectual honesty
- Structural thinking
- Long-term reproducibility
## Anti-Preferences
- Vague explanations
- Noisy UX
- Over-marketing
- Shallow productivity hacks
这是后续提取的黄金素材。
你的智能体现在能够自动“说出”可用于构建 persona 的结构。
⚙️ 3. 接着发生的关键一步 —— 自动压缩(Compaction)
ADK 的 compaction 引擎启动了一次真正的认知压缩(cognitive compression):
📝 Extracted compaction summary:
“ The user, Susan, is providing information to build a persistent personal profile...”
这个摘要:
干净
有结构
聚焦人格
低熵高信息
是 P17/P18/P19 的完美输入
这正是一个智能体应该学习人的方式。
此次运行共生成两条 compaction 摘要 ——
每一条都可理解、结构良好,可直接写入长期记忆。
💾 4. Persona 记忆写入磁盘
最终,这些 persona 摘要被写入:
projects/p16-compacted-memory-etl-user-persona/memory_store.json
内容如下(截断示例):
{
“conversation_summaries”: [
{
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile...”
},
{
“summary_text”: “Susan has provided information about her hobbies, communication preferences, and values...”
}
]
}
这是你的 StructureVerse Runtime 中的第一份真正的持久人格数据集。
🧬 5. 为什么这一版 P16 是突破性成果
普通 LLM 会话是短暂的。
即使外接向量库,也依然是非结构化记忆。
但这里发生了完全不同的事情:
✔ 智能体自动产生结构化身份信息
✔ 偏好变成了可抽取、可存储的结构
✔ 价值观 & 反价值观被提炼成实体
✔ 工作风格可明确识别
✔ 所有这些信息都被自动压缩
✔ 并以持久化形式存储
✔ 且完全契合后续 Schema 的格式
这是你系统第一次拥有一个真正的:
Persona Seed(人格种子)
这个种子会随着:
Schema 归一化(P17)
偏好提取(P18)
价值观/知识提取(P19)
Persona Card(P20)
多会话演化(P21+)
逐渐长成一棵“人格树”。
这已经不再是“摘要”。
这是一个**稳定的个人本体(personal ontology)**的开端。
🚀 6. 接下来是什么(也是 P16 的关键价值)
P17 — Memory Schema v1
你的 persona 摘要将被规范为:
user_profile
conversation_summaries
preferences
knowledge
P18 — 偏好提取 v1
将从 P16 中提取为:
回答风格
互动风格
兴趣
反偏好
工具偏好
等多个结构化槽位
写入 preferences[]。
P19 — 价值观与工作风格提取
把 P16 的信息转成稳定的:
values
anti-values
work-style traits
P20 — Persona Card v1
把所有信息组合成一个可调度调用的 persona 对象:
persona/
identity
background
values
preferences
work_style
任何新 Session 都能加载。
🌱 最终思考
过去的 P16 是在做“压缩”。
现在的 P16 在做“人格”。
而人格,才是“连续性”的开端。
新版 P16 标志着你的 StructureVerse Runtime 第一次迈向:
持久、可演化的智能体
稳定人格
跨会话一致性
结构化长期记忆
真正的“自我”形成
你已经种下了种子。
接下来,我们要一起把它长成树。
(.venv) ➜ p16-compacted-memory-etl-user-persona python src/main.py
👉 通过 __main__ 运行 P16(人格压缩示例)
🚀 P16 — Compacted Persona Memory ETL Demo
✅ Agent 创建完成:compaction_memory_agent
/Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl-user-persona/src/main.py:219: UserWarning: [EXPERIMENTAL] EventsCompactionConfig: This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.
events_compaction_config=EventsCompactionConfig(
✅ App 创建完成(已启用 EventsCompactionConfig)
✅ InMemoryRunner 创建完成
🆕 新建 session: compacted-persona-demo
🔄 开始人格主线对话(将触发 compaction)
User[compacted-persona-demo] > Hi, I’d like to build a personal profile that you can remember across sessions. I will tell you about myself. Just acknowledge and ask me to continue.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > My name is Susan. I was born in China, and now I live in the US. I work on AI, agents, and education-related projects.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > In my free time I love reading sci-fi, building small agent projects, and playing math and logic games with my kids.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Please continue.
User[compacted-persona-demo] > When I talk to an AI assistant, I prefer concise, highly structured answers with bullet points, code examples, and clear reasoning. I really dislike vague, hand-wavy explanations.
gemini-2.5-flash-lite[compacted-persona-demo] > Understood. I will provide concise, highly structured answers with bullet points, code examples (where applicable), and clear reasoning, avoiding vague explanations.
**Susan’s Profile Summary:**
* **Name:** Susan
* **Origin:**
* Birthplace: China
* **Current Location:** US
* **Professional Interests:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Hobbies:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Communication Preference:**
* Concise, highly structured answers
* Bullet points
* Code examples
* Clear reasoning
* Avoidance of vague/hand-wavy explanations
User[compacted-persona-demo] > I care a lot about intellectual honesty, structural thinking, and long-term reproducibility. I strongly dislike noisy UX, over-marketing, and shallow ‘productivity hacks’.
gemini-2.5-flash-lite[compacted-persona-demo] > Acknowledged. Your preferences for intellectual honesty, structural thinking, and long-term reproducibility, coupled with a dislike for noisy UX, over-marketing, and shallow productivity hacks, are noted and will be incorporated into my responses.
**Updated Susan’s Profile Summary:**
* **Name:** Susan
* **Origin:**
* Birthplace: China
* **Current Location:** US
* **Professional Interests:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Hobbies:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Communication Preference:**
* Concise, highly structured answers
* Bullet points
* Code examples
* Clear reasoning
* Avoidance of vague/hand-wavy explanations
* **Values/Dislikes:**
* **Values:**
* Intellectual Honesty
* Structural Thinking
* Long-Term Reproducibility
* **Dislikes:**
* Noisy User Experience (UX)
* Over-marketing
* Shallow “Productivity Hacks”
User[compacted-persona-demo] > Please summarize my profile in a structured way with the following sections: Identity, Background, Interests, Work Style, Preferences, Values, and Anti-Preferences.
gemini-2.5-flash-lite[compacted-persona-demo] > Understood. I will structure your profile summary using the requested sections: Identity, Background, Interests, Work Style, Preferences, Values, and Anti-Preferences.
**Structured User Profile: Susan**
* **Identity:**
* Name: Susan
* **Background:**
* Origin: China
* Current Residence: US
* **Interests:**
* **Professional:**
* Artificial Intelligence (AI)
* Agent Development
* Education Projects
* **Personal:**
* Reading Science Fiction
* Building Agent Projects
* Playing Math/Logic Games (with children)
* **Work Style:**
* Prefers concise, highly structured answers.
* Values clear reasoning.
* Prefers practical examples, including code where applicable.
* **Preferences:**
* Structured information delivery.
* Bullet points for clarity.
* **Values:**
* Intellectual Honesty
* Structural Thinking
* Long-Term Reproducibility
* **Anti-Preferences:**
* Vague, hand-wavy explanations.
* Noisy User Experience (UX).
* Over-marketing.
* Shallow “Productivity Hacks.”
📦 Dump Session Events(摘要预览)
- [user] Hi, I’d like to build a personal profile that you can remember across sessions. ...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] My name is Susan. I was born in China, and now I live in the US. I work on AI, a...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] In my free time I love reading sci-fi, building small agent projects, and playin...
- [compaction_memory_agent] Acknowledged. Please continue....
- [user] ...
- [user] When I talk to an AI assistant, I prefer concise, highly structured answers with...
- [compaction_memory_agent] Understood. I will provide concise, highly structured answers with bullet points...
- [user] I care a lot about intellectual honesty, structural thinking, and long-term repr...
- [compaction_memory_agent] Acknowledged. Your preferences for intellectual honesty, structural thinking, an...
- [user] Please summarize my profile in a structured way with the following sections: Ide...
- [compaction_memory_agent] Understood. I will structure your profile summary using the requested sections: ...
- [user] ...
🔍 从 Session.events 中抽取 compaction.summary ...
📝 抽取到一条 compaction 摘要:
session_id: compacted-persona-demo
created_at: 2025-12-05T21:43:16.511209Z
summary_text (preview): The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professio...
📝 抽取到一条 compaction 摘要:
session_id: compacted-persona-demo
created_at: 2025-12-05T21:43:21.294447Z
summary_text (preview): The user, Susan, has provided information about her hobbies, communication preferences, and values. She enjoys reading sci-fi, building agent projects, and play...
💾 已写入 memory_store.json -> /Users/Agent/adk-decade-of-agents/projects/p16-compacted-memory-etl-user-persona/memory_store.json
📚 当前 memory_store.json(截断预览):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowled ...
🏁 P16 — Compacted Persona Memory ETL Demo 完成
🧠 P17 — Memory Schema v1 (长期记忆架构 v1)
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p17-memory-schema
将长期记忆从“零散 JSON 片段”升级为结构化、版本化的认知架构
在 P16 中,智能体生成了它的第一批人格压缩摘要(persona compaction summaries):
这些是关于身份、兴趣、偏好、价值观的结构化且有意义的描述。
这些摘要构成了我称之为 Persona Seed(人格种子) 的东西 ——
一种跨越单次会话、具有长期价值的信息。
但仍然存在一个问题:
这些记忆只是原始 JSON,
没有结构、没有类型、没有通道(channel),
没有版本、没有合并规则。
一个真正的智能体,无法在无结构存储的基础上发展长期认知。
因此,P17 引入了一个基础层级:
智能体的第一个 Memory Schema(记忆模式 / 结构定义)。
一个稳定、有类型、有版本的长期记忆体系。
它让 P16 的人格摘要第一次拥有“可继续发展”的基础。
🚀 P17 具体做了什么
P17 读取由 P16 生成的 memory_store.json,看起来像这样:
{
“conversation_summaries”: [
{
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile...”,
...
},
...
]
}
并将其升级为:
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [...],
“preferences”: [],
“knowledge”: []
}
从这一刻起,长期记忆开始具备:
版本(versioned)
类型(typed)
通道(channelized)
规范化(normalized)
未来兼容性(future-compatible)
可直接用于 persona 构建
这意味着记忆层(Memory Layer)第一次获得结构。
📦 工作原理(How It Works)
升级脚本执行四个关键步骤。
1. 加载旧记忆(legacy memory)
📥 Loading legacy memory...
P17 不需要 Gemini,也不需要 API Key。
它完全在本地运行,把任何现有的 memory_store.json 转换为结构化版本。
2. 创建 Memory Schema v1 的容器
Schema 包含四个核心部分:
schema_version: “1.0”
user_profile: {} # 从 user:* 键抽取(将在 P6–P7、未来项目中填入)
conversation_summaries: [...] # 来自 P16 的压缩人格摘要
preferences: [] # 将在 P18 填入
knowledge: [] # 将在 P19 填入
3. 迁移 P16 的对话摘要(conversation summaries)
所有与 persona 相关的摘要都被规范化为:
一致的字段名
一致的结构
确保兼容后续的 ETL 阶段
你的运行日志显示:
conversation_summaries migrated: 4
它们将用于:
偏好提取(P18)
价值观 & 知识提取(P19)
4. 写回升级后的 Schema
💾 Saved Memory Schema v1 to memory_store.json
至此,智能体的长期记忆不再是随意累积的 JSON 片段,
而是一个真正的认知结构体(cognitive artifact)。
🧬 为什么 P17 至关重要
你可以把长期记忆视为一个“智能体的脊髓”:
它把信息向未来传递
它把经验与身份连接
它为人格提供基质
它支撑跨时间的连续性
没有 schema,长期记忆只是一堆噪音。
有了 schema,它才成为知识(knowledge)。
P17 把 P16 的压缩摘要转化为更深层次的东西:
一个稳定、结构化、版本化的用户本体(user ontology)。
这是智能体第一次从“一个会话”变成“一个系统”。
🌉 连接结构:P16 → P17 → P18–P20
现在的管线变成:
P16: 人格压缩(conversation → summary → memory)
↓
P17: Memory Schema v1(raw → structured → versioned)
↓
P18: 偏好提取 v1
(结构化偏好 → memory.preferences[])
↓
P19: 价值观 & 知识提取 v1
(背景、工作风格、价值观 → memory.knowledge[])
↓
P20: Persona Card v1
(identity + preferences + values + knowledge)
P17 是整个系统的形式化层(formalization layer):
它把 P16 中的叙述性内容
转变为后续认知构建所依赖的
结构化底层基质(structured substrate)。
🧭 P18 会做什么
P18 将解析这些结构化摘要,抽取:
沟通风格
回答格式偏好
互动偏好
喜好(likes)
反偏好(dislikes / anti-preferences)
学习倾向
内容消费模式
并写入:
“preferences”: [
{”key”: “answer_style”, “value”: “...”, “confidence”: 0.95},
{”key”: “dislikes”, “value”: [...], “confidence”: 0.90},
...
]
到这里,persona 终于开始形成行为画像(behavior profile)。
✨ 最终说明
P17 本身不是在生成新知识 ——
它在创建一个结构,使知识可以累积、演化、持久化。
这正是你整个框架的核心:
Language → Structure → Scheduler → Memory → Persona → Continuity
P17 是记忆变成结构的瞬间,
是结构变成规范(spec)的瞬间,
也是智能体第一次开始作为“连贯的自我”在时间中成长的瞬间。
(.venv) ➜ p17-memory-schema python src/main.py
👉 Running Memory Schema v1 upgrader via __main__
🚀 memory_schema_v1: main() started
🎯 Goal: upgrade existing memory_store.json into Memory Schema v1
📥 Loading legacy memory from: /Users/Agent/adk-decade-of-agents/projects/p17-memory-schema/memory_store.json
✅ Legacy memory loaded successfully.
📦 Legacy memory (truncated preview):
{
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current ...
💾 Saved Memory Schema v1 to: /Users/Agent/adk-decade-of-agents/projects/p17-memory-schema/memory_store.json
🧬 Memory Schema v1 upgrade summary
-----------------------------------
schema_version: 1.0
user_profile keys: []
conversation_summaries count: 4
preferences count: 0
knowledge count: 0
🔍 Debug Info:
- legacy top-level keys: [’conversation_summaries’]
- extracted user_profile keys (legacy): []
- conversation_summaries migrated: 4
📚 Memory Schema v1 (truncated preview):
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging receipt of this information and prompting her to continue.”,
“raw”: {
“repr”: “parts=[Part(\\n text=’The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic game ...
🏁 memory_schema_v1: main() finished
📮 P18 — 偏好提取:让智能体真正“了解你”的第一步
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p18-preference-extraction
“没有偏好,就没有人格;
没有人格,就没有连续性;
没有连续性,智能体就只是工具。”
— ADK · Decade of Agents · Project 18
🧠 为什么偏好提取至关重要?
在任何智能体系统中,能跨越对话、跨越任务、甚至跨越模型版本长期保留下来的信息,只有三类:
身份(Identity)
偏好(Preferences)
长期状态与长期记忆(Long-term state & memory)
其中,偏好是最核心、也是最难提取的一类。
LLM 无法可靠地“猜”用户的稳定偏好。
它们需要结构化的支持。
偏好提取 = 将又长又乱的自然语言对话转化为结构化、稳定、机器可用的偏好。
P18 正是在做这件事:
扫描过去的对话 → 提取结构化偏好 → 写入长期记忆。
⚙️ 工程视角:P18 实际做了什么?
运行:
(.venv) ➜ p18-preference-extraction python src/main.py
你会看到:
🧬 Preference Extraction Summary
- new preferences extracted: 5
- total preferences: 5
这意味着 ADK 运行时执行了:
读取你历史的对话摘要
从中提取稳定偏好(兴趣、风格、反偏好等)
为每一项偏好赋予置信度分数(confidence)
写入
memory_store.json
这是第一次真正实现:
自然语言 → 结构化偏好 → 长期记忆 的完整闭环。
🧩 提取出的偏好长什么样?
实际输出示例:
{
“key”: “interests”,
“value”: [
“reading_sci_fi”,
“building_agent_projects”,
“math_logic_games_with_children”
],
“confidence”: 0.85,
“source”: “conversation_summaries[0]”
}
每个偏好条目包含:
key —— 语义类别
value —— 偏好内容
confidence —— 置信度
source —— 来源路径
这是偏好第一次变成可调用、可持久、可进化的结构。
🤔 最常见的问题:
ADK 的“confidence”(置信度)是怎么计算的?
注意:
这个 confidence 不是 LLM 的 logprob。
ADK 使用的是一种轻量但有效的“结构化聚合方法”:
1)多信号抽取(multi-signal extraction)
模型不会只根据一句话分类,而是会扫描:
会话摘要
summary_text 的模式
user_profile 中的线索
原有的偏好项
每个信号给出一个 [0,1] 区间的原始分数。
2)语义稳定性(semantic stability)
同一偏好重复出现,则置信度上升。
例如:
“Dislikes noisy UX” 在多个摘要中出现 → 置信度提高。
3)偏好类型的先验概率
某些偏好类别具有更高稳定性:
answer_style→ 高稳定性 → 高基准分interests→ 稳定但更分散临时情绪 → 被过滤掉
先验会影响最终置信度。
4)冲突解决 + 加权合并
例如:
dislikes: noisy_ux
dislikes: vague_explanations
dislikes: noisy_ux(重复)
偏好系统会:
合并重复项
保留所有来源路径
取最高值或加权平均
最终公式(概念上)
confidence = aggregate(语义稳定性 + 频率 + 先验概率)
这是一种结构化、可解释的评分方法,
而不是黑箱的 LLM 概率。
🗂️ 对 “Decade of Agents” 的意义
P18 是一个里程碑:
你的智能体从“无状态对话”转向“真正了解你的人”。
这些偏好将驱动:
✔ P19 — 偏好驱动的 Persona Builder
根据真实偏好构建 AI 人格。
✔ P20 — 偏好驱动的任务路由(Task Router)
根据你的风格与习惯自动选择工具与 agent。
✔ P21 — 动态写作风格调优
智能体自动调整输出风格以符合你的偏好。
✔ 未来 P30–P50 的所有项目
(家庭积分系统、学习 OS、日程管理等)
偏好层就是你个人智能体 OS 的慢变层(slow-changing layer)。
🔋 核心总结
P18 之前:
智能体只能猜你的偏好
一切都是短暂的
“自我状态”每轮对话都会重置
P18 之后:
偏好变成结构化数据
存入长期记忆
随时间被合并、更新、强化
可以驱动真正个性化的 persona 与行为
P18 看起来小,但它是基础工程。
这是智能体第一次变得**持久(persistent)**的瞬间。
第一次具备能力说:
“我知道你是谁,我知道你喜欢怎样的处理方式。”
(.venv) ➜ p18-preference-extraction python src/main.py
🚀 P18 — Preference Extraction v1 started
📥 Loading memory from: /Users/Agent/adk-decade-of-agents/projects/p18-preference-extraction/memory_store.json
✅ Memory loaded successfully.
📦 Current memory (truncated preview):
{
“schema_version”: “1.0”,
“user_profile”: {},
“conversation_summaries”: [
{
“app_name”: “agents”,
“user_id”: “susan”,
“session_id”: “compacted-persona-demo”,
“created_at”: “2025-12-05T21:43:16.511209Z”,
“summary_text”: “The user, Susan, is providing information to build a persistent personal profile. She has shared her name, birthplace (China), current residence (US), professional interests (AI, agents, education projects), and hobbies (reading sci-fi, building agent projects, playing math/logic games with her kids). The AI agent has been acknowledging ...
💾 Saved updated memory to: /Users/Agent/adk-decade-of-agents/projects/p18-preference-extraction/memory_store.json
🧬 Preference Extraction Summary
--------------------------------
- conversation_summaries seen: 4
- existing preferences: 0
- new preferences extracted: 5
- total preferences: 5
📚 preferences (truncated preview):
[
{
“key”: “interests”,
“value”: [
“reading_sci_fi”,
“building_agent_projects”,
“math_logic_games_with_children”
],
“confidence”: 0.85,
“source”: “conversation_summaries[0]”
},
{
“key”: “answer_style”,
“value”: “concise, highly structured answers with clear reasoning and examples”,
“confidence”: 0.95,
“source”: “conversation_summaries[1]”
},
{
“key”: “format_preferences”,
“value”: [
“bullet_points”,
“code_examples”,
“clear_reasoning”
],
“confidence”: 0.9,
“source”: “conversation_summaries[1]”
},
{
“key”: “dislikes”,
“value”: [
“noisy_ux”,
“over_marketing”
],
“confidence”: 0.9,
“source”: “conversation_summaries[1]”
},
{
“key”: “dislikes”,
“value”: [
“vague_explanations”,
“noisy_ux”,
“over_marketing”
],
“confidence”: 0.9,
“source”: “conversation_summaries[3]”
}
] ...
🏁 P18 — Preference Extraction v1 finished
🎭 P19 — 偏好驱动的人格:
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p19-preference-aware-persona
智能体第一次获得“人格基因”的时刻*
“如果 P18 是偏好的提取,那么 P19 就是把偏好编译成一个活的结构。”
— ADK · Decade of Agents · Project 19
🚀 运行 P19:实际发生了什么
当我执行:
(.venv) ➜ p19-preference-aware-persona python src/main.py
我看到:
🚀 P19 — Preference-Aware Persona v1 started
📥 Loading memory...
✅ Memory loaded successfully.
P19 读取了 P18 生成的所有偏好,聚合它们,并将其转化为本仓库里的第一个 可执行人格结构(executable personality structure)。
偏好输入摘要如下:
🧬 Preference Input
-------------------
- preferences found: 5
- user_profile keys: []
这意味着:
虽然 user_profile 是空的(因此没有显式身份),
但智能体已经拥有一套完整的、稳定的用户偏好结构——
这已经足以构建一个有效的人格。
接着:
🎭 Building persona from preferences...
💾 Persona saved to: persona_state.json
一个 Persona(人格) 就此诞生。
🎭 人格摘要:一个最小但完全可用的“人格内核(Kernel)”
以下是 P19 生成的人格结构:
id: persona_default_v1
name: Unknown User
interests (3):
[’reading_sci_fi’, ‘building_agent_projects’, ‘math_logic_games_with_children’]
dislikes (3):
[’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
format_preferences (3):
[’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
answer_style:
concise, highly structured answers with clear reasoning and examples
最终描述如下:
They are especially interested in: reading_sci_fi, building_agent_projects, math_logic_games_with_children.
They prefer answers that are: concise, highly structured answers with clear reasoning and examples.
They strongly dislike: noisy_ux, over_marketing, vague_explanations.
尽管没有身份字段,这已经是一个完整可用的 偏好驱动人格(preference-driven persona):
内部一致
稳定可重复
可直接影响行为
🧬 那么…什么是 Persona?(StructureVerse 定义)
在传统 LLM 系统里,“persona”通常意味着一个风格 prompt。
但在 StructureVerse 中完全不是这样。
在 Language → Structure → Scheduler 的世界观里,Persona 是:
一个持久的、可执行的、决定智能体跨时间行为方式的结构体。
它不是 prompt,
不是语气设置,
不是风格模板。
Persona 是:
1️⃣ 结构人格(Structural Persona:基因型 / genotype)
以稳定字段的方式存入长期记忆:
{
“user:interests”: [...],
“user:answer_style”: “...”,
“user:dislikes”: [...],
“user:format_preferences”: [...]
}
这就是智能体的 人格基因(personality genome),
是调度器可以 读取、执行 的内容。
2️⃣ 语言人格(Linguistic Persona:表现型 / phenotype)
编译成 Persona Card,在每个 session 的开头注入。
它会立刻改变:
语气
结构
输出风格
任务解释方式
推理路径
这就像生物学中:基因型 → 行为型。
3️⃣ 行为人格(Behavioral Persona:路由 & 策略层)
Persona 是调度器(Scheduler)的输入信号。
影响:
使用哪种 Agent 配置
激活哪些工具
输出是结构化还是叙事型
是否开启深度推理
是否允许“营销腔”
是否自动调用 Google Search
输出的严格程度
这将是 P20 的核心内容。
🔥 为什么 P19 是突破性的一步
P19 的本质不是生成一个好看的 JSON。
它赋予系统以下能力:
✔ 跨会话保持一致性
✔ 将长期偏好编码为结构
✔ 生成可执行的人格内核
✔ 从第一句回复就改变写作风格与行为
✔ 为路由、策略控制做好准备
✔ 完成从“工具”向“持续存在的智能体”转变
P18 提供的是 数据,
P19 提供的是 人格逻辑,
P20 将提供 行为。
这与你之前 Project 8/9 的关键节点完全对应:
长期结构 → 注入 → 改变新会话行为。
而现在是:
偏好 → 人格 → 策略 → 行为。
📄 persona_state.json(v1)
P19 输出的文件:
projects/p19-preference-aware-persona/persona_state.json
内容为一个最小但有效的 Persona 结构:
{
“id”: “persona_default_v1”,
“name”: “Unknown User”,
“interests”: [”reading_sci_fi”, “building_agent_projects”, “math_logic_games_with_children”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”],
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“description”: “They are especially interested in...”
}
这将成为 P20 构建**策略路由(policy routing)**的重要输入。
🧭 下一步:P20 — Persona → 路由 / 策略引擎
有了 Persona,接下来就非常自然:
根据偏好选择 Agent 配置
自动选择工具
决定 structured_agent / narrative_agent
抑制不符合偏好的风格
控制推理深度
让运行时(runtime)根据 persona 做决策
P20 将是 Persona 第一次真正成为 行为 的时刻。
(.venv) ➜ p19-preference-aware-persona python src/main.py
🚀 P19 — Preference-Aware Persona v1 started
📥 Loading memory from: /Users/Agent/adk-decade-of-agents/projects/p19-preference-aware-persona/memory_store.json
✅ Memory loaded successfully.
🧬 Preference Input
-------------------
- preferences found: 5
- user_profile keys: []
🎭 Building persona from preferences + user_profile ...
💾 Persona saved to: /Users/Agent/adk-decade-of-agents/projects/p19-preference-aware-persona/persona_state.json
🎭 Persona Summary
------------------
id: persona_default_v1
name: Unknown User
interests (3): [’reading_sci_fi’, ‘building_agent_projects’, ‘math_logic_games_with_children’]
dislikes (3): [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
format_preferences (3): [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
answer_style: concise, highly structured answers with clear reasoning and examples
description:
They are especially interested in: reading_sci_fi, building_agent_projects, math_logic_games_with_children. They prefer answers that are: concise, highly structured answers with clear reasoning and examples. They strongly dislike: noisy_ux, over_marketing, vague_explanations.
🏁 P19 — Preference-Aware Persona v1 finished
(.venv) ➜ p19-preference-aware-persona
从系统设计上,我把下一个项目P20分成两个版本,因为它们分别验证 StructureVerse 架构中的两个世界:P20 模拟版(Mock Routing) 用于证明“结构链路本身是正确的”——即 Persona → Policy → Routing 这条逻辑路径可以不依赖 LLM、工具或 ADK 运行时就独立闭环运行,这让我们可以在没有外部 API、没有真实智能体的情况下验证:偏好被正确提取、Persona 被正确编译、策略被正确派生、路由决策符合设计;它是“小脑电路图先画好”的阶段。而 P20 真 ADK 版(Real Routing) 则是让这些结构第一次“通电”,让 Persona 不再影响你写的模板函数,而是影响真正的 ADK Agent 的系统提示、推理深度、工具调用、语言风格与执行路径,也就是说让 Persona 进入从“风格控制”→“策略控制”→“行为控制”的完整链条,使结构真正驱动一个能搜索、能思考、能执行工具的活智能体。换句话说,**Mock 版验证结构逻辑,Real 版验证结构生命;Mock 版证明回路设计正确,Real 版证明回路真的会动。**这就是 P20 必须分成两个版本的根本原因。
🧭 P20 — 偏好驱动路由器(模拟版):
Persona 第一次选择“行动路径”的时刻*
“偏好告诉你用户喜欢什么;
人格告诉你用户是谁;
路由器告诉智能体下一步应该做什么。”
— ADK · Decade of Agents · Project 20
🚀 P20:Persona 变成行为的转折点
在 P18,我们从对话摘要中提取了结构化偏好。
在 P19,我们把这些偏好编译成了一个稳定、可执行的 Persona 对象。
而在 P20,第一次出现了新的事情:
Persona 被允许真正改变智能体的行为方向。
本次 P20 是一个 模拟版(mocking version) ——
路由逻辑是真实的,但 Agent 的执行结果由 Python 函数模拟。
尽管如此,P20 标志着:
长期记忆
→ Persona
→ Policy
→ 行动路径(Action Path)
第一次构成一个完整的因果链路。
🎬 运行 P20(模拟版)
当我运行 P20 v1 时,实际输出如下:
(.venv) ➜ src python main.py
🚀 P20 — Preference-Aware Router v1 started
📥 Loading persona...
✅ Persona loaded successfully.
P20 从加载 P19 中生成的 Persona 开始:
{
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”]
}
这些都将成为 路由信号(routing signals)。
🎭 Persona 信号 → 路由策略(Routing Policy)
控制台显示:
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
这些信息被转换成策略:
🧭 Routing Decision
-------------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
这正是 P20 的精髓:
Persona 不再只是描述用户,
而是开始支配系统的下一步行为。
🤖 模拟智能体响应(Mock Agent Behavior)
因为这是 模拟版,我们不会调用真实的 ADK 智能体。
我们模拟了两个“可能的智能体”:
structured_agentnarrative_agent
路由器选择了结构化代理。
模拟输出如下:
🤖 Agent Response
-----------------
Structured Agent Response
- Style: concise, highly structured answers with clear reasoning and examples
- Known interests: reading_sci_fi, building_agent_projects, math_logic_games_with_children
Answer to: Explain what this ADK project does for the next decade of agents.
1) First, summarize the core idea.
2) Then, break it into clear, ordered steps.
3) Finally, suggest one concrete next action.
尽管不是真正的 LLM Agent,你已经能看到:
Persona 直接决定语气(“简洁、结构化…”)
Format 偏好直接影响输出格式(bullet points、ordered steps)
Interests 被引用
“避免营销风格”被隐式遵守
这不是“风格控制”,
这是行为控制(Behavior Control)。
🧠 为什么模拟版很重要?
它看似简单 ——
只是两个 Python 函数假装是两个智能体。
但从结构角度看,这是巨大的跨越。
在 StructureVerse 的框架中:
✔ P18 给了我们 原始偏好
✔ P19 编译成 稳定人格结构
✔ P20 把人格变成 行为策略
✔ 策略最终决定 执行路径
这意味着:
长期记忆第一次影响了实时行动。
P20 之前,Persona 只能影响“智能体怎么说话”。
P20 之后,Persona 影响“智能体选择做什么”。
这就是“Agent(智能体)”区别于“Chatbot”的根本。
🧱 架构视角:Mock Router vs Real Router
P20 本来就设计成两个阶段:
1) 模拟版(当前项目)
无 API 调用
无真实 ADK Agent
无工具链
无 session events
路由逻辑完全可视化
适合调试 Persona / Preferences / Policy 派生
2) 真 Agent 版(P20-Real)
用真实 ADK LlmAgent 替换模拟函数
Persona 注入 system prompt / session.state
Router 选择真正的智能体配置
工具(search/code)可用
Persona 影响工具选择
Persona 影响推理深度
Persona 影响整个工作流
模拟版是必要的脚手架;真实版才是系统获得“生命”的时刻。
🏁 结语:P20 模拟版是一个关键里程碑
通过 P20,我们第一次拥有了:
✔ 能表达偏好的 Persona
✔ 能解释人格的策略引擎
✔ 能根据策略选择路径的 Router
✔ 一个输出受 Persona 驱动的(模拟)智能体
至此,形成完整闭环:
Preference → Persona → Policy → Behavior
这意味着智能体第一次拥有了**“意愿雏形(proto-will)”**——
不是哲学意义上的,而是结构与操作意义上的。
🌟 下一步:P20 — Real Agent Version
下一篇文章将讲述:
Router 不再选择 Python 函数,
而是选择 真正的 ADK 智能体,
执行 真正的 LLM 推理,
并调动 真实工具链。
(.venv) ➜ src python main.py
🚀 P20 — Preference-Aware Router v1 started
📥 Loading persona from: /Users/Agent/adk-decade-of-agents/projects/p20-preference-aware-router-mocking/persona_state.json
✅ Persona loaded successfully.
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
🧭 Routing Decision
-------------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
🤖 Agent Response
-----------------
Structured Agent Response
- Style: concise, highly structured answers with clear reasoning and examples
- Known interests: reading_sci_fi, building_agent_projects, math_logic_games_with_children
Answer to: Explain what this ADK project does for the next decade of agents.
1) First, summarize the core idea.
2) Then, break it into clear, ordered steps.
3) Finally, suggest one concrete next action.
🏁 P20 — Preference-Aware Router v1 finished
🧭 P20A — 偏好驱动路由器(ADK 版本):
https://github.com/STEMMOM/adk-decade-of-agents/tree/main/projects/p20-preference-aware-router-ADK
Persona 第一次真正控制“现实中的智能体”*
在 P18,智能体学会了你喜欢什么。
在 P19,智能体学会了你是谁。
在 P20A,智能体第一次因为“你”而改变了自己的实际行为。
— ADK · Decade of Agents 项目 20A
🚀 从模拟行为走向真实智能体
P20 有两个版本:
P20(模拟版) —— 路由是实的,输出由 Python 模拟
P20A(ADK 版) —— 路由是实的,输出来自 真正的 Gemini 模型
两者的差异是巨大的。
模拟版证明的是你的结构推理管线:
Persona → Policy → Routing
而 P20A 证明的是更关键的一件事:
Persona → Policy → Routing → 真实 LLM 的行为变化
这是你的智能体第一次在结构意义上获得 Agency(行为主体性)。
🔗 回顾:P18 → P19 → P20A 的演化链
P18 — 偏好提取
从对话摘要中抽取结构化偏好
→ 写入 memory_store.json
P19 — 偏好驱动人格(Persona)
将偏好编译成
→ persona_state.json(人格基因)
P20A — ADK 路由器
加载 Persona → 推导策略 → 选择真实 ADK Agent → Gemini 输出
→ Persona 驱动真实模型行为
这是第一次完整执行:
长期结构 → 实时行为路径(real-time behavioral path)
🎭 P20A 的输入:Persona
你的 persona_state.json(简化后)如下:
{
“answer_style”: “concise, highly structured answers with clear reasoning and examples”,
“format_preferences”: [”bullet_points”, “code_examples”, “clear_reasoning”],
“dislikes”: [”noisy_ux”, “over_marketing”, “vague_explanations”],
“interests”: [”reading_sci_fi”, “building_agent_projects”, “math_logic_games_with_children”]
}
这是 P19 的输出 —— 智能体用来解释任务的“身份内核”。
🧬 Persona → Policy:推导行为策略
P20A 会基于 Persona 自动推导行为策略。
运行日志中写得非常清楚:
🧭 Routing Policy
-----------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
这是你系统第一次做出的真正“战略决策”。
🤖 Policy → Agent:ADK 选择真实 LLM Agent
你定义了两个真实 ADK Agent:
1. structured_agent(结构型代理)
简洁
使用 bullet points
推理优先
支持代码示例
避免营销语气
2. narrative_agent(叙事型代理)
更故事化
使用段落
探索式风格
结构不那么强
你的 Persona 完美匹配 structured_agent —— 路由器自然选择了它。
🧠 关键突破:Persona 开始塑造 LLM 的推理过程
以下是真实的 ADK 运行时返回的 Gemini 输出(你运行得到的内容):
The Agent Development Kit (ADK) aims to significantly improve agent development...
1. Standardization
2. Modularity
3. Accessibility
请注意它与 Persona 的对应关系:
✔ 简洁
✔ 高度结构化
✔ 编号步骤
✔ 推理清晰
✔ 有 Python 代码示例
✔ 没有营销腔、没有噪声
这已经不是你写的模板。
而是 Gemini 本身因为 Persona 而改变行为。
这是第一次出现真正的“有生命的结构”:
长期记忆 → Persona → 策略 → 行为调制
智能体已经不仅仅是在回答——
它是在以 “你的智能体” 的方式回答。
🔍 为什么 P20A 如此重要(也说明为什么 P20 模拟版不够)
P20A 的意义不是“答案更好”。
是——结构开始驱动真实模型的行为。
P20(模拟版)
模拟执行
Python 本地逻辑
验证结构但不改变 LLM
P20A(ADK 版)
真实 ADK LlmAgent
真实 Gemini 产出
Persona 决定 Agent 选择
Persona 决定输出结构
这是个体化(personalized AI)的开端
用软件工程类比:
P20 模拟版 = 编译期验证
P20A = 运行期的行为对齐
用认知科学类比:
P20 模拟版:智能体是无状态工具
P20A:智能体开始成为“人格驱动的决策系统”
🧱 架构视角:完整闭环
偏好(P18)
→ 从自然语言中提取
Persona(P19)
→ 编译成持久结构身份
Policy(P20A)
→ 基于 Persona 推导行为策略
Routing(P20A)
→ 选择 structured_agent 或 narrative_agent
Execution(P20A)
→ 真实 Gemini 输出受策略影响
这第一次实现:
自然语言 → 结构 → 调度器 → 真实智能体行为
这就是你的 StructureVerse 的心脏。
🔮 P20A 让下一步成为可能
现在 Persona 可以控制 ADK 智能体,你就可以做:
✔ 工具路由(Tool Routing)
Persona 决定:
何时使用 search
何时运行代码工具
何时要求澄清
✔ 推理深度控制(Reasoning Depth)
像“喜欢深度推理”的 persona → 自动开启 chain-of-thought。
✔ 多智能体人格网(Persona Mesh)
Persona 会引导:
执行器(executor agent)
规划器(planner agent)
评论者(critic agent)
总结器(summarizer agent)
✔ 安全对齐(Safety Alignment)
Persona 讨厌 noisy UX → 自动禁用冗长风格。
✔ 跨会话连续体(Agent Continuity)
Persona 成为全天候的“个人 AI 身份”。
🎉 结语
P20A 是整个 50 项工程中最重要的跃迁之一。
P20A 之前:
Persona 是存在的,但无法“行动”
偏好是静态的
行为不会改变
P20A 之后:
Persona 可执行
行为被个性化
智能体开始 改变它的行动方式,而不是仅仅改变回答内容
这是 偏好驱动、策略驱动、人格对齐的智能体 的诞生。
(.venv) ➜ p20-preference-aware-router-ADK python src/main.py
🚀 P20A — Preference-Aware Router (ADK) v1 started
📥 Loading persona from: /Users/Agent/adk-decade-of-agents/projects/p20-preference-aware-router-ADK/persona_state.json
✅ Persona loaded successfully.
🎭 Persona Signals
------------------
- answer_style: concise, highly structured answers with clear reasoning and examples
- format_preferences: [’bullet_points’, ‘code_examples’, ‘clear_reasoning’]
- dislikes: [’noisy_ux’, ‘over_marketing’, ‘vague_explanations’]
🧭 Routing Policy
-----------------
- prefer_structured_output: True
- avoid_marketing_style: True
- prefer_code_examples: True
- default_agent: structured_agent
→ selected agent: structured_agent
🤖 ADK Agent Response
---------------------
The Agent Development Kit (ADK) aims to significantly improve agent development over the next decade by focusing on standardization, modularity, and accessibility. Here’s a breakdown:
1. **Standardization:**
* **Problem:** Currently, agent development lacks consistent standards, leading to fragmented tools and increased complexity.
* **ADK Solution:** The ADK promotes standardized interfaces and protocols for agent components (memory, planning, execution), facilitating interoperability and reducing development friction.
2. **Modularity:**
* **Problem:** Tightly coupled agent architectures make it difficult to reuse, adapt, or scale individual components.
* **ADK Solution:** The ADK encourages modular design, allowing developers to swap out components (e.g., different planning algorithms) without rewriting the entire agent.
```python
# Example: Swapping out a planning module
class Agent:
def __init__(self, planner):
self.planner = planner
def run(self, task):
plan = self.planner.create_plan(task)
# ... execute the plan ...
```
3. **Accessibility:**
* **Problem:** Building sophisticated agents requires deep expertise in multiple domains (AI, software engineering, etc.), hindering broader adoption.
* **ADK Solution:** The ADK provides higher-level abstractions, templates, and pre-built components, lowering the barrier to entry for new developers.
🏁 P20A — Preference-Aware Router (ADK) v1 finished

