Files
basicmachines-co-basic-memory/tests/mcp/test_prompts.py
T
Paul Hernandez 093dab5f03 feat: Add enhanced prompts and resources (#15)
## Summary
- Add comprehensive documentation to all MCP prompt modules
- Enhance search prompt with detailed contextual output formatting
- Implement consistent logging and docstring patterns across prompt
utilities
- Fix type checking in prompt modules

## Prompts Added/Enhanced
- `search.py`: New formatted output with relevance scores, excerpts, and
next steps
- `recent_activity.py`: Enhanced with better metadata handling and
documentation
- `continue_conversation.py`: Improved context management

## Resources Added/Enhanced
- `ai_assistant_guide`: Resource with description to give to LLM to
understand how to use the tools

## Technical improvements
- Added detailed docstrings to all prompt modules explaining their
purpose and usage
- Enhanced the search prompt with rich contextual output that helps LLMs
understand results
- Created a consistent pattern for formatting output across prompts
- Improved error handling in metadata extraction
- Standardized import organization and naming conventions
- Fixed various type checking issues across the codebase

This PR is part of our ongoing effort to improve the MCP's interaction
quality with LLMs, making the system more helpful and intuitive for AI
assistants to navigate knowledge bases.

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

---------

Co-authored-by: phernandez <phernandez@basicmachines.co>
2025-02-27 20:48:56 -06:00

62 lines
2.5 KiB
Python

"""Tests for MCP prompts."""
import pytest
from basic_memory.mcp.prompts.continue_conversation import continue_conversation
@pytest.mark.asyncio
async def test_continue_conversation_with_topic(client, test_graph):
"""Test continue_conversation with a topic."""
# We can use the test_graph fixture which already has relevant content
# Call the function with a topic that should match existing content
result = await continue_conversation(topic="Root", timeframe="1w")
# Check that the result contains expected content
assert "Continuing conversation on: Root" in result
assert "This is a memory retrieval session" in result
assert "Start by executing one of the suggested commands" in result
assert "read_note" in result
@pytest.mark.asyncio
async def test_continue_conversation_with_recent_activity(client, test_graph):
"""Test continue_conversation with no topic, using recent activity."""
# Call the function without a topic
result = await continue_conversation(timeframe="1w")
# Check that the result contains expected content for recent activity
assert "Continuing conversation on: Recent Activity" in result
assert "This is a memory retrieval session" in result
assert "Please use the available basic-memory tools" in result
assert "Next Steps" in result
@pytest.mark.asyncio
async def test_continue_conversation_no_results(client):
"""Test continue_conversation when no results are found."""
# Call with a non-existent topic
result = await continue_conversation(topic="NonExistentTopic", timeframe="1w")
# Check the response indicates no results found
assert "Continuing conversation on: NonExistentTopic" in result
assert "I couldn't find any recent work specifically on this topic" in result
assert "Try a different search term" in result
@pytest.mark.asyncio
async def test_continue_conversation_creates_structured_suggestions(client, test_graph):
"""Test that continue_conversation generates structured tool usage suggestions."""
# Call the function with a topic that should match existing content
result = await continue_conversation(topic="Root", timeframe="1w")
# Verify the response includes clear tool usage instructions
assert "start by executing one of the suggested commands" in result.lower()
# Check that the response contains tool call examples
assert "read_note" in result
assert "search" in result
assert "recent_activity" in result
assert "build_context" in result