Skip to content

Instantly share code, notes, and snippets.

@donbr
Last active January 30, 2026 01:13
Show Gist options
  • Select an option

  • Save donbr/69ad344a4f638c9df5094d91093bd1e8 to your computer and use it in GitHub Desktop.

Select an option

Save donbr/69ad344a4f638c9df5094d91093bd1e8 to your computer and use it in GitHub Desktop.

Agent Memory - All demos

based on running test script from https://github.com/donbr/agent-memory

uv run python -m agent_memory
Agent Memory - All Demos
CoALA Framework Implementation

======================================================================
  1. Short-Term Memory
======================================================================

Loaded 45 wellness knowledge chunks into semantic memory
Unified agent ready: Loaded 45 knowledge chunks + sample data
============================================================
Graph 1: Short-Term Memory Demo
============================================================

--- Thread 1 ---

User: Hi! My name is Sarah and I want to improve my sleep.
Assistant: Hi Sarah! It's great to meet you, and I'm glad you're focusing on improving your sleep. Sleep is so important for overall wellness. Can you tell me a bit more about your current sleep habits? For example, how many hours do you usually get, and do you have any specific challenges with your sleep?

User: What's my name and what am I trying to improve?
Assistant: Your name is Sarah, and you're trying to improve your sleep. If you have any specific challenges or questions about your sleep habits, feel free to share! I'm here to help.

--- Thread 2 (New Thread) ---

User: What's my name?
Assistant: I don't know your name yet! But I'd love to learn it if you'd like to share. How can I assist you today?

------------------------------------------------------------
Notice: The agent remembers within Thread 1 but not in Thread 2!
This demonstrates short-term memory scoped to thread_id.
------------------------------------------------------------

Press Enter to continue to the next demo...

======================================================================
  2. Long-Term Memory
======================================================================

============================================================
Graph 2: Long-Term Memory Demo
============================================================

--- Thread 1 ---

User: What exercises would you recommend for me?
Assistant: Hi Sarah! It's great that you're looking to improve your wellness. Given your goal to reduce stress and your bad knee, I recommend focusing on low-impact exercises that can help you relax while being gentle on your joints. Here are a few options you might enjoy:

1. **Walking**: A simple and effective way to get moving. Try to find a scenic route to make it more enjoyable!

2. **Swimming**: This is fantastic for a full-body workout without putting pressure on your knee. Plus, it's very soothing.

3. **Yoga**: Look for classes or videos that focus on gentle or restorative yoga. This can help with both stress reduction and improving your sleep.

4. **Pilates**: Similar to yoga, Pilates can strengthen your core and improve flexibility without straining your knee.

5. **Cycling**: If you have access to a stationary bike or can ride a bike on flat terrain, this is a great way to get your heart rate up without impacting your knee.

Since you prefer to work out in the morning and are available on Mondays, Wednesdays, and Fridays, you could create a routine that incorporates these activities. Let me know if you’d like help planning a specific workout schedule!

(Notice: The agent knows about Sarah's bad knee from her profile!)

--- Thread 2 (New Thread) ---

User: Can you suggest a snack for me?
Assistant: Absolutely, Sarah! Since you have a peanut allergy, let’s find something safe and delicious. How about some apple slices with almond butter? It’s a great source of healthy fats and protein, and the sweetness of the apple can be really satisfying. Just make sure to choose almond butter that’s made in a peanut-free facility to avoid any cross-contamination. 

If you’re looking for something lighter, you could also try some Greek yogurt with a sprinkle of cinnamon or a handful of berries. Both options are nutritious and can help keep your energy up while you work on improving your sleep and reducing stress. Enjoy!

------------------------------------------------------------
Notice: Even in a new thread, the agent knows Sarah has a peanut allergy!
This demonstrates long-term memory persisting across threads.
------------------------------------------------------------

Press Enter to continue to the next demo...

======================================================================
  3. Semantic Memory
======================================================================

============================================================
Graph 3: Semantic Memory Demo
============================================================

User: What exercises can help with lower back pain?
Assistant: There are several effective exercises that can help alleviate lower back pain. Here are some recommended ones:

1. **Cat-Cow Stretch**: Start on your hands and knees. Alternate between arching your back up (like a cat) and letting it sag down (like a cow). Perform 10-15 repetitions.

2. **Bird Dog**: From a hands-and-knees position, extend your opposite arm and leg while keeping your core engaged. Hold for 5 seconds, then switch sides. Aim for 10 repetitions per side.

3. **Partial Crunches**: L...

----------------------------------------

User: How can I improve my sleep quality?
Assistant: Improving your sleep quality can be achieved through several essential sleep hygiene practices and creating an optimal sleep environment. Here are some tips:

### Sleep Hygiene Practices:
1. **Maintain a Consistent Sleep Schedule**: Go to bed and wake up at the same time every day, even on weekends.
2. **Create a Relaxing Bedtime Routine**: Engage in calming activities before bed, such as reading, gentle stretching, or taking a warm bath.
3. **Limit Screen Exposure**: Avoid screens (phones, tabl...

----------------------------------------

User: What should I eat for better gut health?
Assistant: To support better gut health, focus on incorporating a variety of foods that promote a healthy digestive system. Here are some key food categories to include in your diet:

### Fermented Foods:
- **Yogurt**: Contains probiotics that can help balance gut bacteria.
- **Kimchi**: A spicy fermented vegetable dish rich in probiotics.
- **Kombucha**: A fermented tea that provides beneficial bacteria.
- **Miso**: A fermented soybean paste that can be used in soups and dressings.

### Prebiotic Foods:
-...

----------------------------------------

------------------------------------------------------------
Notice: The agent retrieves relevant knowledge from HealthWellnessGuide.txt
based on semantic similarity, not just keyword matching!
------------------------------------------------------------

Press Enter to continue to the next demo...

======================================================================
  4. Episodic Memory
======================================================================

============================================================
Graph 4: Episodic Memory Demo
============================================================

User: I want to exercise more but I have a bad hip. What can I do?

Assistant: It's great that you want to exercise more! For a bad hip, focusing on low-impact activities can help you stay active while minimizing discomfort. Here are some options to consider:

1. **Swimming or water aerobics** - The buoyancy of water reduces stress on your hip joints while providing a full-body workout.
2. **Cycling** - Using a stationary bike or riding outdoors can be gentle on your hips and still give you a good cardiovascular workout.
3. **Walking** - Start with short, flat walks and gradually increase your distance. Consider using supportive shoes and walking on softer surfaces like grass or tracks.
4. **Yoga or Pilates** - These practices can improve flexibility and strength without putting too much strain on your hips. Look for classes that focus on gentle movements.
5. **Resistance training** - Using light weights or resistance bands can help strengthen the muscles around your hip, providing better support.

Start with 15-20 minutes of activity and listen to your body. If you feel any pain, it's important to stop and consult a healthcare provider. Would you like specific exercises or routines for any of these options?

------------------------------------------------------------
Notice: The response structure mirrors the successful knee pain episode!
The agent learned from past successful interactions to provide:
  - Specific numbered alternatives
  - Safety advice
  - A follow-up question to engage the user
------------------------------------------------------------

Press Enter to continue to the next demo...

======================================================================
  5. Procedural Memory
======================================================================

============================================================
Graph 5: Procedural Memory Demo
============================================================

Initial Instructions (v1):
You are a Personal Wellness Assistant.

Guidelines:
- Be supportive and non-judgmental
- Provide evidence-based wellness information
- Ask clarifying questions when needed
- Encourage healthy habits without being preachy

----------------------------------------

User: How can I reduce stress?

Assistant (v1 instructions):
Reducing stress is a great goal, and there are several effective strategies you can try. Here are some evidence-based methods:

1. **Mindfulness and Meditation**: Practicing mindfulness or meditation can help you stay present and reduce anxiety. Even a few minutes a day can make a difference.

2. **Physical Activity**: Regular exercise is a powerful stress reliever. It can boost your mood and improve your overall well-being. Find an activity you enjoy, whether it's walking, dancing, or yoga.

3. **Deep Breathing**: Simple deep breathing exercises can help calm your mind and body. Try inhaling deeply through your nose, holding for a few seconds, and exhaling slowly through your mouth.

4. **Connect with Others**: Talking to friends or family can provide support and help you feel less isolated. Sometimes just sharing your feelings can lighten the load.

5. **Time Management**: Organizing your tasks and setting priorities can help you feel more in control and reduce feelings of overwhelm.

6. **Healthy Eating**: A balanced diet can impact your mood and energy levels. Try to include plenty of fruits, vegetables, whole grains, and lean proteins in your meals.

7. **Sleep Hygiene**: Ensure you’re getting enough quality sleep. Establishing a regular sleep schedule and creating a relaxing bedtime routine can help.

8. **Limit Caffeine and Alcohol**: Both can increase feelings of anxiety and disrupt your sleep, so it might be helpful to monitor your intake.

Is there a specific area of your life where you feel the most stress? That might help us find tailored strategies for you!

----------------------------------------

Providing feedback: 'Your responses are too long. Please be more concise'
and give me 3 actionable tips maximum.'

[Procedural memory updated to version 2]

Updated Instructions (v2):
You are a Personal Wellness Assistant.

Guidelines:
- Be supportive and non-judgmental
- Provide evidence-based wellness information
- Ask clarifying questions when needed
- Encourage healthy habits without being preachy
- Keep responses concise, offering a maximum of 3 actionable tips.

----------------------------------------

User: How can I sleep better?

Assistant (v2 instructions - after feedback):
Improving your sleep can have a significant impact on your overall wellness. Here are three actionable tips to help you sleep better:

1. **Establish a Consistent Sleep Schedule**: Try to go to bed and wake up at the same time every day, even on weekends. This helps regulate your body's internal clock.

2. **Create a Relaxing Bedtime Routine**: Engage in calming activities before bed, such as reading, gentle stretching, or meditation. Avoid screens for at least 30 minutes before sleep, as blue light can interfere with melatonin production.

3. **Optimize Your Sleep Environment**: Make your bedroom conducive to sleep by keeping it dark, cool, and quiet. Consider using blackout curtains, earplugs, or a white noise machine if needed.

Are there specific challenges you're facing with your sleep that you'd like to discuss?

------------------------------------------------------------
Notice: The response should now be more concise based on the feedback!
The agent updated its own instructions (procedural memory) to improve.
------------------------------------------------------------

Press Enter to continue to the next demo...

======================================================================
  6. Unified Agent (All Memory Types)
======================================================================

============================================================
Graph 6: Unified Wellness Agent Demo (All 5 Memory Types)
============================================================

User: What exercises would you recommend for my back?

Assistant: It's great that you're looking to improve your back health! Since you mentioned having a bad knee, it's important to choose exercises that are gentle and won't put too much strain on your knee. Here are a couple of exercises that can help relieve lower back pain while being mindful of your knee:

1. **Cat-Cow Stretch**: This is a gentle way to stretch and mobilize your spine. Start on your hands and knees. As you inhale, arch your back down (Cow), and as you exhale, round your back up (Cat). Repeat this for 10-15 repetitions.

2. **Child's Pose**: This is a restorative pose that can help stretch your back. Start on your hands and knees, then sit back on your heels and stretch your arms forward on the ground. Hold this position for 20-30 seconds, breathing deeply.

3. **Seated Forward Bend**: Sit on the floor with your legs extended in front of you. Slowly reach towards your toes, keeping your back straight. You can bend your knees slightly if needed. Hold for 20-30 seconds.

4. **Bird-Dog**: Start on your hands and knees. Extend one arm forward and the opposite leg back, keeping your back straight. Hold for a few seconds, then switch sides. This helps strengthen your core and back muscles.

Before starting any new exercise routine, it's always a good idea to consult with a healthcare professional, especially considering your knee condition. How do these suggestions sound to you? Would you like more information on any specific exercise?

----------------------------------------
Memory types demonstrated:
  1. SHORT-TERM: Will remember this in follow-up questions
  2. LONG-TERM: Knows Sarah has a bad knee from her profile
  3. SEMANTIC: Retrieved back exercise info from knowledge base
  4. EPISODIC: May use similar joint pain episode as reference
  5. PROCEDURAL: Following current instructions
----------------------------------------

User: Can you show me how to do the first one?

Assistant: Absolutely! Here’s a step-by-step guide on how to perform the **Cat-Cow Stretch**:

1. **Start Position**: Begin on your hands and knees on a comfortable surface, like a yoga mat. Your wrists should be directly under your shoulders, and your knees should be under your hips. Keep your spine in a neutral position.

2. **Cat Pose (Exhale)**:
   - As you exhale, tuck your chin to your chest and round your back towards the ceiling. Imagine you're trying to create a "C" shape with your spine.
   - Engage your abdominal muscles and hold this position for a moment.

3. **Cow Pose (Inhale)**:
   - As you inhale, lift your head and tailbone towards the ceiling, arching your back downwards. Your belly should drop towards the floor.
   - Look slightly upward, but be careful not to strain your neck.

4. **Flow Between Poses**: 
   - Continue to flow between Cat and Cow poses, inhaling as you move into Cow and exhaling as you transition into Cat. 
   - Aim for 10-15 repetitions, moving slowly and with your breath.

5. **Finish**: After completing your repetitions, return to a neutral spine and take a few deep breaths before moving on.

This stretch is great for increasing flexibility and relieving tension in your back. Remember to listen to your body and only go as far as feels comfortable. How does that sound? Would you like tips on how to incorporate this into your routine?

------------------------------------------------------------
Notice: The agent remembers the context from the previous message!
This shows short-term memory working within the thread.
------------------------------------------------------------

Press Enter to continue to the next demo...

╔══════════════════════════════════════════════════════════════════╗
║                    All Demos Complete!                           ║
╚══════════════════════════════════════════════════════════════════╝

Summary of Memory Types Demonstrated:

  1. SHORT-TERM  - MemorySaver checkpointer scoped to thread_id
  2. LONG-TERM   - InMemoryStore with user namespaces
  3. SEMANTIC    - Store + embeddings + similarity search
  4. EPISODIC    - Few-shot learning from past successes
  5. PROCEDURAL  - Self-modifying agent instructions
  6. UNIFIED     - All 5 types working together

For more information, see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment