Ex-Google engineer just dropped 1-hour course: loops, self-improving AI, memory systems - from scratch:
00:00 - the self-building agent
03:01 - soul.md runs everything
30:16 - RAG memory: pull 20 messages, not 2,000
31:48 - the loop that knows when to stop
35:14 - find the bug, fix the prompt
50:22 - how Claude compresses your memory
1 hour of his guide beats any paid agent course
watch & bookmark - then read Karpathy's loop method below
What are Claude Code Hooks?
Most people configure Claude Code with 𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱 and call it a day.
But that's a mistake.
𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱 is just a suggestion. 𝗛𝗼𝗼𝗸𝘀 are a guarantee.
Claude follows 𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱 most of the time, not all of the time. It might forget to run your linter. It might execute a command you'd never approve. It might declare "done" while tests are still failing.
Hooks fix this by making critical behaviors deterministic.
Here's the idea.
Every tool call Claude makes passes through a lifecycle. Before the tool runs, after it finishes, when Claude is about to stop. You attach shell scripts to these lifecycle events, and they fire automatically. Not most of the time. Every time.
The image below shows exactly how this works.
Claude generates a tool call. Before it executes, the 𝗣𝗿𝗲𝗧𝗼𝗼𝗹𝗨𝘀𝗲 hook intercepts it. Your bash firewall script checks the command against dangerous patterns. If it matches 𝗿𝗺 -𝗿𝗳 / or a force-push to main, 𝗲𝘅𝗶𝘁 𝗰𝗼𝗱𝗲 𝟮 blocks the call entirely and sends the error back to Claude for self-correction. If it's safe, 𝗲𝘅𝗶𝘁 𝗰𝗼𝗱𝗲 𝟬 lets it through.
The tool runs. After it finishes, the 𝗣𝗼𝘀𝘁𝗧𝗼𝗼𝗹𝗨𝘀𝗲 hook kicks in. A one-liner runs 𝗣𝗿𝗲𝘁𝘁𝗶𝗲𝗿 on the file Claude just wrote. Clean output, every time, without Claude needing to remember.
But that's just the mechanical part. The real power is in what you enforce.
A 𝗦𝘁𝗼𝗽 hook that runs 𝗻𝗽𝗺 𝘁𝗲𝘀𝘁 and blocks Claude from finishing until the suite is green. A 𝗦𝗲𝘀𝘀𝗶𝗼𝗻𝗦𝘁𝗮𝗿𝘁 hook that injects the current git branch into context automatically. A 𝗡𝗼𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 hook that pings your desktop when Claude needs attention.
The exit code behavior is worth understanding before you write your first hook
𝗘𝘅𝗶𝘁 𝟬 means success. 𝗘𝘅𝗶𝘁 𝟭 means error but non-blocking, execution continues normally. Only 𝗲𝘅𝗶𝘁 𝗰𝗼𝗱𝗲 𝟮 actually blocks and feeds your error message to Claude. Using 𝗲𝘅𝗶𝘁 𝟭 for security hooks is the most common mistake. It logs a warning and does absolutely nothing to stop the action.
The entire configuration lives in 𝘀𝗲𝘁𝘁𝗶𝗻𝗴𝘀.𝗷𝘀𝗼𝗻 under a 𝗵𝗼𝗼𝗸𝘀 key. Each hook gets a matcher regex to target specific tools and a shell command to run. Commit it to git and your whole team gets the same guardrails.
A 𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱 that says "always run 𝗣𝗿𝗲𝘁𝘁𝗶𝗲𝗿" is a hope. A 𝗣𝗼𝘀𝘁𝗧𝗼𝗼𝗹𝗨𝘀𝗲 hook that runs 𝗣𝗿𝗲𝘁𝘁𝗶𝗲𝗿 is a fact.
Suggestions scale with trust. Hooks scale with certainty.
The article below is a complete guide to 𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱, hooks, skills, agents, and permissions, and how to set them up properly.
𝗔𝗜 𝗔𝗴𝗲𝗻𝘁’𝘀 𝗠𝗲𝗺𝗼𝗿𝘆 is the most important piece of 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗶𝗻𝗴, this is how we define it 👇
In general, the memory for an agent is something that we provide via context in the prompt passed to LLM that helps the agent to better plan and react given past interactions or data not immediately available.
It is useful to group the memory into four types:
𝟭. 𝗘𝗽𝗶𝘀𝗼𝗱𝗶𝗰 - This type of memory contains past interactions and actions performed by the agent. After an action is taken, the application controlling the agent would store the action in some kind of persistent storage so that it can be retrieved later if needed. A good example would be using a vector Database to store semantic meaning of the interactions.
𝟮. 𝗦𝗲𝗺𝗮𝗻𝘁𝗶𝗰 - Any external information that is available to the agent and any knowledge the agent should have about itself. You can think of this as a context similar to one used in RAG applications. It can be internal knowledge only available to the agent or a grounding context to isolate part of the internet scale data for more accurate answers.
𝟯. 𝗣𝗿𝗼𝗰𝗲𝗱𝘂𝗿𝗮𝗹 - This is systemic information like the structure of the System Prompt, available tools, guardrails etc. It will usually be stored in Git, Prompt and Tool Registries.
𝟰. Occasionally, the agent application would pull information from long-term memory and store it locally if it is needed for the task at hand.
𝟱. All of the information pulled together from the long-term or stored in local memory is called short-term or working memory. Compiling all of it into a prompt will produce the prompt to be passed to the LLM and it will provide further actions to be taken by the system.
We usually label 1. - 3. as Long-Term memory and 5. as Short-Term memory.
And that is it! The rest is all about how you architect the topology of your Agentic Systems.
Learn all of this hands-on in my End-to-end AI Engineering Bootcamp (we are kicking off in 2 weeks!).
🎁 Get a 15% discount via this link: https://t.co/czhitnDVGT
Any war stories you have while managing Agent’s memory? Let me know in the comments 👇
RAG was never the end goal.
Memory in AI agents is where everything is heading. Let me break down this evolution in the simplest way possible.
RAG (2020-2023):
- Retrieve info once, generate response
- No decision-making, just fetch and answer
- Problem: Often retrieves irrelevant context
Agentic RAG:
- Agent decides *if* retrieval is needed
- Agent picks *which* source to query
- Agent validates *if* results are useful
- Problem: Still read-only, can't learn from interactions
AI Memory:
- Read AND write to external knowledge
- Learns from past conversations
- Remembers user preferences, past context
- Enables true personalization
The mental model is simple:
↳ RAG: read-only, one-shot
↳ Agentic RAG: read-only via tool calls
↳ Agent Memory: read-write via tool calls
Here's what makes agent memory powerful:
The agent can now "remember" things - user preferences, past conversations, important dates. All stored and retrievable for future interactions.
This unlocks something bigger: continual learning.
Instead of being frozen at training time, agents can now accumulate knowledge from every interaction. They improve over time without retraining.
Memory is the bridge between static models and truly adaptive AI systems.
But it's not all smooth sailing.
Memory introduces new challenges RAG never had, like memory corruption, deciding what to forget, and managing multiple memory types (procedural, episodic, and semantic).
Solving these problems from scratch is hard. If you want to build Agents that never forget, Cognee is an open-source framework (12k+ stars) to build real-time knowledge graphs and get self-evolving AI memory.
Getting started with Cognee is as simple as this:
𝗮𝘄𝗮𝗶𝘁 𝗰𝗼𝗴𝗻𝗲𝗲[.]𝗮𝗱𝗱("𝗬𝗼𝘂𝗿 𝗱𝗮𝘁𝗮 𝗵𝗲𝗿𝗲")
𝗮𝘄𝗮𝗶𝘁 𝗰𝗼𝗴𝗻𝗲𝗲[.]𝗰𝗼𝗴𝗻𝗶𝗳𝘆()
𝗮𝘄𝗮𝗶𝘁 𝗰𝗼𝗴𝗻𝗲𝗲[.]𝗺𝗲𝗺𝗶𝗳𝘆()
𝗮𝘄𝗮𝗶𝘁 𝗰𝗼𝗴𝗻𝗲𝗲[.]𝘀𝗲𝗮𝗿𝗰𝗵("𝗬𝗼𝘂𝗿 𝗾𝘂𝗲𝗿𝘆 𝗵𝗲𝗿𝗲")
That’s it. Cognee handles the heavy lifting, and your agent gets a memory layer that actually learns over time.
I have shared the repo in the replies!
Did researchers at Tencent just kill fine-tuning?
A new paper called Training-Free GRPO shows you can get the same results as reinforcement learning for $18 instead of $10,000, with zero parameter updates.
The idea is surprisingly simple:
Instead of updating the model's weights through RL, you let the model practice on a few problems, compare what worked and what didn't across multiple attempts, and distill that into natural language "experiences" that get injected into the prompt.
The model stays completely frozen. All the learning happens in what the model reads, not what the model is.
Here's how it works:
↳ For each problem, generate multiple outputs and score them
↳ Compare the winners and losers within each group
↳ Ask the LLM to articulate WHY certain attempts succeeded
↳ Store those insights in an evolving experience library
↳ Inject the experiences into future prompts
The results are wild.
Training-Free GRPO applied to DeepSeek-V3.1-Terminus (671B) outperformed fine-tuned 32B models on the AIME math benchmarks.
It used 100 training samples instead of 17,000. It cost $18 instead of $10,000. And because the base model is never touched, it generalizes across both math AND web searching simultaneously.
Fine-tuned models can't do that. ReTool, trained on math, dropped from 67% to 18% when tested on web tasks. Worse than the baseline.
But I want to be clear on something:
This isn't just prompt engineering.
Directly asking an LLM to generate helpful tips doesn't work. Performance actually dropped when they tried that.
The experiences only become useful when they're distilled through the structured loop of trying, failing, comparing, and reflecting. That's what makes this different from self-reflection or few-shot prompting.
You might wonder: aren't we just bloating the context window?
Not really. Each experience is capped at 32 words. The math experiments produced 48 total. That's roughly 1,500 tokens for a model with a 128K context window.
And tool calls actually decrease after learning. The agent takes fewer wrong turns, so the small context cost saves tokens downstream.
I've shared link to the paper in the next tweet.
𝗔𝗜 𝗔𝗴𝗲𝗻𝘁’𝘀 𝗠𝗲𝗺𝗼𝗿𝘆 is the most important piece of 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗶𝗻𝗴, this is how we define it 👇
In general, the memory for an agent is something that we provide via context in the prompt passed to LLM that helps the agent to better plan and react given past interactions or data not immediately available.
It is useful to group the memory into four types:
𝟭. 𝗘𝗽𝗶𝘀𝗼𝗱𝗶𝗰 - This type of memory contains past interactions and actions performed by the agent. After an action is taken, the application controlling the agent would store the action in some kind of persistent storage so that it can be retrieved later if needed. A good example would be using a vector Database to store semantic meaning of the interactions.
𝟮. 𝗦𝗲𝗺𝗮𝗻𝘁𝗶𝗰 - Any external information that is available to the agent and any knowledge the agent should have about itself. You can think of this as a context similar to one used in RAG applications. It can be internal knowledge only available to the agent or a grounding context to isolate part of the internet scale data for more accurate answers.
𝟯. 𝗣𝗿𝗼𝗰𝗲𝗱𝘂𝗿𝗮𝗹 - This is systemic information like the structure of the System Prompt, available tools, guardrails etc. It will usually be stored in Git, Prompt and Tool Registries.
𝟰. Occasionally, the agent application would pull information from long-term memory and store it locally if it is needed for the task at hand.
𝟱. All of the information pulled together from the long-term or stored in local memory is called short-term or working memory. Compiling all of it into a prompt will produce the prompt to be passed to the LLM and it will provide further actions to be taken by the system.
We usually label 1. - 3. as Long-Term memory and 5. as Short-Term memory.
And that is it! The rest is all about how you architect the topology of your Agentic Systems.
Any war stories you have while managing Agent’s memory? Let me know in the comments 👇
#AI #LLM #MachineLearning
Everyone is talking about LLM and fine-tuning...
...but no one is telling you how to pre-process your data.
In this article, I share the secret sauce to make LLMs work for YOUR dataset ↓
https://t.co/EUmIR74eKn
Finally, MCP servers can now deliver UI-rich experiences!
MCP servers in Claude/Cursor don't offer any UI elements like charts or tables. It's just text.
mcp-ui lets you add interactive web components to its output that can be rendered by the MCP client.
100% open-source!
Turn research papers into interactive AI agents!
Stanford researchers released Paper2Agent a multi-agent AI system that automatically transforms research papers into interactive AI agents with minimal human input.
100% Open Source
Who is a Full-stack AI Engineer?
Production-grade AI systems demand a deep understanding of how LLMs are engineered, deployed, and optimized.
Here are the 8 pillars that define serious LLM development:
Couldn't resist.
Here's a pure PyTorch from-scratch re-implementation of Gemma 3 270M in a Jupyter Notebook (uses about 1.49 GB RAM): https://t.co/M2f8EB0KBE
Incase you missed it! 💫
I posted an illustrated guide to implementing "Attention is all you need" in PyTorch!
This paper laid the foundation for modern LLMs!
We cover:
- Transformer architecture
- Encoder-Decoder setup
- Multi-Head Attention
- Training and inference
Learn how LLMs work under the hood!
This is the best interactive website to learn how LLMs work.
It combines clear, step-by-step explanations with dynamic 3D visualizations for an intuitive learning experience.
Drag-and-drop UI to build AI agent workflows!
Sim Studio is a lightweight, user-friendly platform that makes creating AI agent workflows accessible to everyone.
Supports all major LLMs, MCP servers, vectorDBs, etc.
100% open-source.
Fine-tune Qwen3, LLaMA 4, and Gemma 2x faster with 80% less VRAM!
Unsloth AI is an open-source Python framework that accelerates and simplifies the fine-tuning of LLMs.
100% Open Source
Generate synthetic data at scale!
SDV is an open-source Python library that generates tabular synthetic data by using ML algorithms to learn and replicate patterns from your real data.
Here's how it works in 3 steps:
1️⃣ Train: Point SDV at your real table; it will capture the underlying distributions & relationships.
2️⃣ Generate: Run the trained SDV model to pop out as many look-alike rows as you need—no real data exposed.
3️⃣ Validate: Use SDV’s quality report to see how closely the generated data matches the real stuff; tweak and repeat if you want it tighter.
Class imbalance—solved in one shot! ✨
Key features:
🧠 Multiple models from GaussianCopula to CTGAN
🔗 Single, multi & sequential-table support
🔒 Built-in anonymization & logical constraints
⚙️ Single call does it all `sdv.sample()`
Link to the GitHub repo in next tweet!
____
Share this with your network if you found this insightful ♻️
Follow me ( @akshay_pachaar ) for more insights and tutorials on AI and Machine Learning!
Every ML service can be decomposed into 3 components
→ Feature pipeline → transforms raw data into model features
→ Training pipeline → re-trains the model to keep it up-to-date.
→ Inference pipeline → takes model features, and the model, and outputs new predictions.
Turn any ML paper into code repository!
Paper2Code is a multi-agent LLM system that transforms a paper into a code repository.
It follows a three-stage pipeline: planning, analysis, and code generation, each handled by specialized agents.
100% Open Source