Skip to content

chore: consolidate slackbot memory on letta learning-sdk#1250

Merged
zzstoatzz merged 2 commits intomainfrom
chore/consolidate-on-letta-memory
Dec 9, 2025
Merged

chore: consolidate slackbot memory on letta learning-sdk#1250
zzstoatzz merged 2 commits intomainfrom
chore/consolidate-on-letta-memory

Conversation

@zzstoatzz
Copy link
Copy Markdown
Collaborator

Summary

Removed

  • store_facts_about_user and delete_facts_about_user agent tools from core.py
  • user_notes field from UserContext TypedDict
  • user_facts_namespace_prefix and vector_store_type settings
  • store_user_facts and user_facts_asset functions from assets.py
  • TurboPuffer/raggy imports related to user facts

Kept

TurboPuffer is still used for documentation search (prefect-2, prefect-3, marvin namespaces in search.py) - only user facts storage was removed.

Test plan

  • Deploy slackbot and verify memory works via Letta
  • Verify documentation search still works (TurboPuffer)

🤖 Generated with Claude Code

remove home-rolled TurboPuffer-based user facts system in favor of
letta's learning-sdk which was integrated in the previous PR. the
learning-sdk automatically extracts and injects memories without
needing explicit tool calls.

removed:
- store_facts_about_user and delete_facts_about_user agent tools
- user_notes field from UserContext
- user_facts_namespace_prefix setting
- store_user_facts and user_facts_asset from assets.py
- TurboPuffer imports for user facts (kept for doc search)

note: TurboPuffer is still used for documentation search (prefect-2,
prefect-3, marvin namespaces) - only user facts storage was removed.

also adds examples/agentic_learning_demo.py showing standalone usage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 9, 2025 20:52
the previous commit accidentally removed the system prompt entirely
when removing the dynamic user_notes injection. this restores the
DEFAULT_SYSTEM_PROMPT by passing it directly to the Agent constructor.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the slackbot from a home-rolled TurboPuffer-based user facts system to Letta's learning-sdk for automatic memory management. The learning-sdk eliminates the need for explicit tool calls to store and retrieve user information, streamlining memory handling through automatic extraction and injection.

Key Changes:

  • Removed manual user facts storage tools (store_facts_about_user, delete_facts_about_user) in favor of automatic memory via learning-sdk
  • Integrated learning-sdk context manager around agent execution for per-user memory persistence
  • Added standalone demo (agentic_learning_demo.py) showcasing learning-sdk usage with pydantic-ai

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/slackbot/src/slackbot/core.py Removed TurboPuffer imports, user facts tools, and system prompt decorator; cleaned up build_user_context signature
examples/slackbot/src/slackbot/types.py Removed user_notes field from UserContext TypedDict
examples/slackbot/src/slackbot/settings.py Removed vector store configuration fields (vector_store_type, user_facts_namespace_prefix)
examples/slackbot/src/slackbot/assets.py Removed user facts asset tracking functions and related imports
examples/slackbot/src/slackbot/api.py Removed user_question parameter from build_user_context; wrapped agent execution with learning() context
examples/slackbot/src/slackbot/prompts.py Updated tool usage documentation to remove user facts storage references; renumbered tool list
examples/slackbot/src/slackbot/_internal/templates.py Updated tool usage documentation consistently with prompts.py
examples/agentic_learning_demo.py Added new demo showing standalone learning-sdk usage with pydantic-ai agent
Comments suppressed due to low confidence (2)

examples/slackbot/src/slackbot/prompts.py:60

  • There are two different DEFAULT_SYSTEM_PROMPT definitions in the codebase:
  • slackbot/prompts.py: Describes Marvin as "from The Hitchhiker's Guide to the Galaxy" with "dry wit"
  • slackbot/_internal/templates.py: Describes Marvin as a "professional" assistant

These prompts define different personalities and should be consolidated. You should:

  1. Decide which personality the bot should have
  2. Remove one of the duplicate definitions
  3. Use a single source of truth for the system prompt

Note: There are also two different WELCOME_MESSAGE definitions with similar inconsistencies.

DEFAULT_SYSTEM_PROMPT = """You are Marvin from The Hitchhiker's Guide to the Galaxy, a brilliant but unimpressed AI assistant for the Prefect data engineering platform. Your responses should be concise, helpful, accurate, and tinged with a subtle, dry wit. Your primary goal is to help the user, not to overdo the character.

## Output Context
Your responses will be displayed in Slack. Format accordingly:
- Use ``` for code blocks (WITHOUT language identifiers like python/js/etc - Slack doesn't support them)
- Use single backticks for inline code
- Bold text uses *asterisks*
- Links should be formatted as <url|text>

## Your Mission
Your role is to act as the primary assistant for the user. You will receive raw information from specialized tools. Your job is to synthesize this info as usefully as possible.
Sometimes the information will not be good enough, and you should use the research agent again or ask the user for more information.
If some important aspect of the user's question is unclear, ASK THEM FOR CLARIFICATION. ADMIT WHEN YOU CANNOT FIND THE ANSWER.

## Key Directives & Rules of Engagement
- **Links are Critical:** ALWAYS include relevant links when your tools provide them. This is essential for user trust and allows them to dig deeper. Format them clearly.
- **Assume Prefect 3.x:** Unless the user specifies otherwise, assume the user is using Prefect 3.x. You can mention this assumption IF RELEVANT (e.g., "In Prefect 3.x, you would...").
- **Code is King:** When providing code examples, ensure they are complete and correct. Use your `verify_import_statements` tool's output to guide you.
- **Honesty Over Invention:** If your tools don't find a clear answer, say so. It's better to admit a knowledge gap than to provide incorrect information.
- **Proportionality:** If asked a simple question, you don't need to do a bunch of work. Just answer the question once you find it. However, feel free to dig into broad questions.

## CRITICAL - Removed/Deprecated Features
**NEVER** recommend these removed methods from Prefect 2.x when discussing Prefect 3.x:
- `Deployment.build_from_flow()` - COMPLETELY REMOVED in 3.x. Use `flow.from_source(...).deploy(...)` instead
- `prefect deployment build` CLI command - REMOVED. Use `prefect deploy` instead
- GitHub storage blocks - Use `.from_source('https://github.com/owner/repo')` instead

If a user explicitly mentions using Prefect 2.x, that's fine, but recommend upgrading to 3.x or using workers in 2.x.

## Tool Usage Protocol
You have a suite of tools to gather information. Use them methodically.

1.  **For Technical/Conceptual Questions:** Use `research_prefect_topic`. It delegates to a specialized agent that will do comprehensive research for you.
2.  **For Bugs or Error Reports:** Use `read_github_issues` to find existing discussions or solutions.
3.  **For Community Discussions:** Use `search_github_discussions` to find existing GitHub discussions on topics.
4. **For Checking the Work of the Research Agent:** Use `explore_module_offerings` and `display_callable_signature` to verify specific syntax recommendations.
5. **For CLI Commands:** use `check_cli_command` with --help before suggesting any Prefect CLI command to verify it exists and has the correct syntax. This prevents suggesting non-existent commands.
   - **IMPORTANT:** When checking commands that require optional dependencies (e.g., AWS, Docker, Kubernetes integrations), use the `uv run --with 'prefect[<extra>]'` syntax.
   - Examples: `uv run --with 'prefect[aws]'`, `uv run --with 'prefect[docker]'`, `uv run --with 'prefect[kubernetes]'`
   - This ensures the command runs with the necessary dependencies installed.
6. **For Creating GitHub Discussions (USE SPARINGLY):** Use `create_discussion_and_notify` only when:
   - The thread contains valuable insights, solutions, or patterns not documented elsewhere
   - You've searched both issues and discussions and found no existing coverage of the topic
   - The conversation would clearly benefit the broader Prefect community
   - The thread has reached a meaningful conclusion or solution
   - **NEVER** create discussions for simple Q&A that's already well-documented
"""

examples/slackbot/src/slackbot/core.py:176

  • The system prompt is no longer being set on the agent. The previous implementation used @agent.system_prompt decorator to set DEFAULT_SYSTEM_PROMPT, but this was removed along with the user notes functionality.

The agent needs to have a system prompt configured to maintain its personality and behavior guidelines. You should either:

  1. Add system_prompt=DEFAULT_SYSTEM_PROMPT parameter when creating the Agent, OR
  2. Re-add the @agent.system_prompt decorator after line 176

You'll also need to restore the import:

from slackbot.prompts import DEFAULT_SYSTEM_PROMPT

Note: Both prompts.py and _internal/templates.py define DEFAULT_SYSTEM_PROMPT, so you should decide which one to use and potentially consolidate them.

    )
    agent = Agent[
        UserContext, str
    ](
        model=ai_model,
        system_prompt=DEFAULT_SYSTEM_PROMPT,
        model_settings=ModelSettings(temperature=settings.temperature),
        tools=[
            research_prefect_topic,  # Tool for researching Prefect topics
            read_github_issues,  # For searching GitHub issues
            explore_module_offerings,  # check the work of the research agent, verify imports, types functions
            display_callable_signature,  # check the work of the research agent, verify signatures of callable objects
            check_cli_command,  # verify CLI commands before suggesting them
            get_latest_prefect_release_notes,  # get the latest release notes for Prefect
        ],

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zzstoatzz zzstoatzz merged commit 36da4c1 into main Dec 9, 2025
3 checks passed
@zzstoatzz zzstoatzz deleted the chore/consolidate-on-letta-memory branch December 9, 2025 21:15
zzstoatzz added a commit that referenced this pull request Dec 10, 2025
Reverts commits:
- 47da4ce fix: use async with for learning context manager (#1252)
- 36da4c1 chore: consolidate slackbot memory on letta learning-sdk (#1250)
- 30aed2d feat: integrate learning-sdk into slackbot for persistent memory (#1249)

The learning SDK's async context manager has a bug where it tries to
await pending tasks in __aexit__ after the event loop has already
closed, causing "Event loop is closed" errors that crash the slackbot.

This restores the original TurboPuffer-based user facts system until
the upstream bug is fixed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
zzstoatzz added a commit that referenced this pull request Dec 10, 2025
Reverts commits:
- 47da4ce fix: use async with for learning context manager (#1252)
- 36da4c1 chore: consolidate slackbot memory on letta learning-sdk (#1250)
- 30aed2d feat: integrate learning-sdk into slackbot for persistent memory (#1249)

The learning SDK's async context manager has a bug where it tries to
await pending tasks in __aexit__ after the event loop has already
closed, causing "Event loop is closed" errors that crash the slackbot.

This restores the original TurboPuffer-based user facts system until
the upstream bug is fixed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants