Add long-term memory to a Pydantic AI agent (one capability, per-user recall across runs)
Description and use
<p><em>Disclosure: I'm Mohammed, founder of MemorySync. I drafted this article with AI assistance and reviewed it for accuracy against the official MemorySync and Pydantic AI docs. The code is adapted from the docs and I haven't run it.</em></p> <p>Pydantic AI keeps context across runs through message history: you pass <code>message_history=</code> (or the previous result's conversation) into the next <code>Agent.run</code>, and <code>result.all_messages()</code> / <code>new_messages()</code> give you the messages back (<a href="https://ai.pydantic.dev/message-history/" rel="noopener noreferre
Problem
<p><em>Disclosure: I'm Mohammed, founder of MemorySync. I drafted this article with AI assistance and reviewed it for accuracy against the official MemorySync and Pydantic AI docs. The code is adapted from the docs and I haven't run it.</em></p> <p>Pydantic AI keeps context across runs through message history: you pass <code>message_history=</code> (or the previous result's conversation) into the next <code>Agent.run</code>, and <code>result.all_messages()</code> / <code>new_messages()</code> give you the messages back (<a href="https://ai.pydantic.dev/message-history/" rel="noopener noreferre
Outcome
<p><em>Disclosure: I'm Mohammed, founder of MemorySync. I drafted this article with AI assistance and reviewed it for accuracy against the official MemorySync and Pydantic AI docs. The code is adapted from the docs and I haven't run it.</em></p> <p>Pydantic AI keeps context across runs through message history: you pass <code>message_history=</code> (or the previous result's conversation) into the next <code>Agent.run</code>, and <code>result.all_messages()</code> / <code>new_messages()</code> give you the messages back (<a href="https://ai.pydantic.dev/message-history/" rel="noopener noreferre
Evidence
Add long-term memory to a Pydantic AI agent (one capability, per-user recall across runs)
- Record date: 2026-10-24T17:11:07.427Z