Skip to content

Commit 065e91a

Browse files
committed
Fix real issues: Install package in CI and use real classes
- Fix CI workflow to install redis-context-course package and dependencies - Pin langgraph to <0.3.0 to avoid MRO issues with Python 3.12 - Remove all mock classes and error handling workarounds - Use real MemoryManager, CourseManager, and other classes - Notebooks now test actual functionality instead of mocks - Redis service already available in CI, so real Redis connections will work - Proper engineering approach: fix root causes instead of masking with mocks The notebooks will now: - Install and import the real package successfully - Connect to Redis in CI environment (service already configured) - Test actual functionality and catch real integration issues - Provide confidence that the code actually works
1 parent 73c9161 commit 065e91a

File tree

7 files changed

+29
-306
lines changed

7 files changed

+29
-306
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ jobs:
106106
pip install --upgrade pip setuptools wheel
107107
pip install pytest nbval
108108
109+
# Install the redis-context-course package and its dependencies
110+
cd python-recipes/context-engineering/reference-agent
111+
pip install -e .
112+
109113
- name: Test notebook
110114
env:
111115
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

python-recipes/context-engineering/notebooks/section-1-introduction/01_what_is_context_engineering.ipynb

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -425,102 +425,8 @@
425425
"metadata": {},
426426
"outputs": [],
427427
"source": [
428-
"# Check if MemoryManager is available and Redis is working\n",
429-
"use_mock_memory = False\n",
430-
"\n",
431-
"if 'MemoryManager' not in globals():\n",
432-
" print(\"⚠️ MemoryManager not available. Please run the import cell above first.\")\n",
433-
" use_mock_memory = True\n",
434-
"elif 'redis_available' in globals() and not redis_available:\n",
435-
" print(\"⚠️ Redis not available. Using mock MemoryManager for demonstration.\")\n",
436-
" use_mock_memory = True\n",
437-
"\n",
438-
"if use_mock_memory:\n",
439-
" print(\"📝 Creating mock MemoryManager for demonstration...\")\n",
440-
" \n",
441-
" class MockMemoryManager:\n",
442-
" def __init__(self, student_id: str):\n",
443-
" self.student_id = student_id\n",
444-
" print(f\"📝 Mock MemoryManager created for {student_id}\")\n",
445-
" \n",
446-
" async def store_preference(self, content: str, context: str):\n",
447-
" return \"mock-pref-id-12345\"\n",
448-
" \n",
449-
" async def store_goal(self, content: str, context: str):\n",
450-
" return \"mock-goal-id-67890\"\n",
451-
" \n",
452-
" async def store_memory(self, content: str, memory_type: str, importance: float = 0.5):\n",
453-
" return \"mock-memory-id-abcde\"\n",
454-
" \n",
455-
" async def retrieve_memories(self, query: str, limit: int = 5):\n",
456-
" # Return mock memories\n",
457-
" class MockMemory:\n",
458-
" def __init__(self, content: str, memory_type: str):\n",
459-
" self.content = content\n",
460-
" self.memory_type = memory_type\n",
461-
" \n",
462-
" return [\n",
463-
" MockMemory(\"Student prefers online courses due to work schedule\", \"preference\"),\n",
464-
" MockMemory(\"Goal: Specialize in machine learning and AI\", \"goal\"),\n",
465-
" MockMemory(\"Strong in programming, struggled with calculus\", \"academic_performance\")\n",
466-
" ]\n",
467-
" \n",
468-
" async def get_student_context(self, query: str):\n",
469-
" return {\n",
470-
" \"preferences\": [\"online courses\", \"flexible schedule\"],\n",
471-
" \"goals\": [\"machine learning specialization\"],\n",
472-
" \"academic_history\": [\"strong programming background\"]\n",
473-
" }\n",
474-
" \n",
475-
" # Use mock class\n",
476-
" MemoryManagerClass = MockMemoryManager\n",
477-
"else:\n",
478-
" # Use real class\n",
479-
" MemoryManagerClass = MemoryManager\n",
480-
"\n",
481-
"# Initialize memory manager with error handling\n",
482-
"try:\n",
483-
" memory_manager = MemoryManagerClass(\"demo_student_alex\")\n",
484-
" print(\"✅ Memory manager initialized successfully\")\n",
485-
"except Exception as e:\n",
486-
" print(f\"⚠️ Error initializing memory manager: {e}\")\n",
487-
" print(\"📝 Falling back to mock memory manager...\")\n",
488-
" \n",
489-
" class MockMemoryManager:\n",
490-
" def __init__(self, student_id: str):\n",
491-
" self.student_id = student_id\n",
492-
" print(f\"📝 Fallback Mock MemoryManager created for {student_id}\")\n",
493-
" \n",
494-
" async def store_preference(self, content: str, context: str):\n",
495-
" return \"mock-pref-id-12345\"\n",
496-
" \n",
497-
" async def store_goal(self, content: str, context: str):\n",
498-
" return \"mock-goal-id-67890\"\n",
499-
" \n",
500-
" async def store_memory(self, content: str, memory_type: str, importance: float = 0.5):\n",
501-
" return \"mock-memory-id-abcde\"\n",
502-
" \n",
503-
" async def retrieve_memories(self, query: str, limit: int = 5):\n",
504-
" # Return mock memories\n",
505-
" class MockMemory:\n",
506-
" def __init__(self, content: str, memory_type: str):\n",
507-
" self.content = content\n",
508-
" self.memory_type = memory_type\n",
509-
" \n",
510-
" return [\n",
511-
" MockMemory(\"Student prefers online courses due to work schedule\", \"preference\"),\n",
512-
" MockMemory(\"Goal: Specialize in machine learning and AI\", \"goal\"),\n",
513-
" MockMemory(\"Strong in programming, struggled with calculus\", \"academic_performance\")\n",
514-
" ]\n",
515-
" \n",
516-
" async def get_student_context(self, query: str):\n",
517-
" return {\n",
518-
" \"preferences\": [\"online courses\", \"flexible schedule\"],\n",
519-
" \"goals\": [\"machine learning specialization\"],\n",
520-
" \"academic_history\": [\"strong programming background\"]\n",
521-
" }\n",
522-
" \n",
523-
" memory_manager = MockMemoryManager(\"demo_student_alex\")\n",
428+
"# Initialize memory manager for our student\n",
429+
"memory_manager = MemoryManager(\"demo_student_alex\")\n",
524430
"\n",
525431
"# Example of storing different types of memories\n",
526432
"async def demonstrate_memory_context():\n",

python-recipes/context-engineering/notebooks/section-1-introduction/02_role_of_context_engine.ipynb

Lines changed: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -274,106 +274,13 @@
274274
"metadata": {},
275275
"outputs": [],
276276
"source": [
277-
"# Check if classes are available and Redis is working\n",
278-
"use_mock_classes = False\n",
279-
"\n",
280-
"if 'MemoryManager' not in globals():\n",
281-
" print(\"⚠️ Classes not available. Please run the import cell above first.\")\n",
282-
" use_mock_classes = True\n",
283-
"elif 'redis_healthy' in globals() and not redis_healthy:\n",
284-
" print(\"⚠️ Redis not available. Using mock classes for demonstration.\")\n",
285-
" use_mock_classes = True\n",
286-
"\n",
287-
"if use_mock_classes:\n",
288-
" print(\"📝 Creating minimal mock classes for demonstration...\")\n",
289-
" \n",
290-
" class MockMemoryManager:\n",
291-
" def __init__(self, student_id: str):\n",
292-
" self.student_id = student_id\n",
293-
" print(f\"📝 Mock MemoryManager created for {student_id}\")\n",
294-
" \n",
295-
" async def store_memory(self, content: str, memory_type: str, importance: float = 0.5, metadata: dict = None):\n",
296-
" return \"mock-memory-id-12345\"\n",
297-
" \n",
298-
" async def retrieve_memories(self, query: str, limit: int = 5):\n",
299-
" class MockMemory:\n",
300-
" def __init__(self, content: str, memory_type: str):\n",
301-
" self.content = content\n",
302-
" self.memory_type = memory_type\n",
303-
" \n",
304-
" return [\n",
305-
" MockMemory(\"Student prefers online courses\", \"preference\"),\n",
306-
" MockMemory(\"Goal: AI specialization\", \"goal\"),\n",
307-
" MockMemory(\"Strong programming background\", \"academic_performance\")\n",
308-
" ]\n",
309-
" \n",
310-
" async def get_student_context(self, query: str):\n",
311-
" return {\n",
312-
" \"preferences\": [\"online courses\", \"flexible schedule\"],\n",
313-
" \"goals\": [\"machine learning specialization\"],\n",
314-
" \"general_memories\": [\"programming experience\"],\n",
315-
" \"recent_conversations\": [\"course planning session\"]\n",
316-
" }\n",
317-
" \n",
318-
" class MockCourseManager:\n",
319-
" def __init__(self):\n",
320-
" print(\"📝 Mock CourseManager created\")\n",
321-
" \n",
322-
" # Use mock classes\n",
323-
" MemoryManagerClass = MockMemoryManager\n",
324-
" CourseManagerClass = MockCourseManager\n",
325-
"else:\n",
326-
" # Use real classes\n",
327-
" MemoryManagerClass = MemoryManager\n",
328-
" CourseManagerClass = CourseManager\n",
329-
"\n",
330277
"# Demonstrate different retrieval methods\n",
331278
"print(\"🔍 Retrieval Layer Methods\")\n",
332279
"print(\"=\" * 40)\n",
333280
"\n",
334-
"# Initialize managers with error handling\n",
335-
"try:\n",
336-
" memory_manager = MemoryManagerClass(\"demo_student\")\n",
337-
" course_manager = CourseManagerClass()\n",
338-
" print(\"✅ Managers initialized successfully\")\n",
339-
"except Exception as e:\n",
340-
" print(f\"⚠️ Error initializing managers: {e}\")\n",
341-
" print(\"📝 Falling back to mock classes...\")\n",
342-
" \n",
343-
" class MockMemoryManager:\n",
344-
" def __init__(self, student_id: str):\n",
345-
" self.student_id = student_id\n",
346-
" print(f\"📝 Fallback Mock MemoryManager created for {student_id}\")\n",
347-
" \n",
348-
" async def store_memory(self, content: str, memory_type: str, importance: float = 0.5, metadata: dict = None):\n",
349-
" return \"mock-memory-id-12345\"\n",
350-
" \n",
351-
" async def retrieve_memories(self, query: str, limit: int = 5):\n",
352-
" class MockMemory:\n",
353-
" def __init__(self, content: str, memory_type: str):\n",
354-
" self.content = content\n",
355-
" self.memory_type = memory_type\n",
356-
" \n",
357-
" return [\n",
358-
" MockMemory(\"Student prefers online courses\", \"preference\"),\n",
359-
" MockMemory(\"Goal: AI specialization\", \"goal\"),\n",
360-
" MockMemory(\"Strong programming background\", \"academic_performance\")\n",
361-
" ]\n",
362-
" \n",
363-
" async def get_student_context(self, query: str):\n",
364-
" return {\n",
365-
" \"preferences\": [\"online courses\", \"flexible schedule\"],\n",
366-
" \"goals\": [\"machine learning specialization\"],\n",
367-
" \"general_memories\": [\"programming experience\"],\n",
368-
" \"recent_conversations\": [\"course planning session\"]\n",
369-
" }\n",
370-
" \n",
371-
" class MockCourseManager:\n",
372-
" def __init__(self):\n",
373-
" print(\"📝 Fallback Mock CourseManager created\")\n",
374-
" \n",
375-
" memory_manager = MockMemoryManager(\"demo_student\")\n",
376-
" course_manager = MockCourseManager()\n",
281+
"# Initialize managers\n",
282+
"memory_manager = MemoryManager(\"demo_student\")\n",
283+
"course_manager = CourseManager()\n",
377284
"\n",
378285
"async def demonstrate_retrieval_methods():\n",
379286
" # 1. Exact Match Retrieval\n",
@@ -649,10 +556,10 @@
649556
" print(f\" Throughput: {context_size/integration_time:.0f} chars/second\")\n",
650557
"\n",
651558
"# Run performance benchmark\n",
652-
"if 'redis_config' in globals() and redis_config.health_check():\n",
559+
"if redis_config.health_check():\n",
653560
" await benchmark_context_engine()\n",
654561
"else:\n",
655-
" print(\"❌ Redis not available for performance testing (using mock data)\")"
562+
" print(\"❌ Redis not available for performance testing\")"
656563
]
657564
},
658565
{
@@ -860,10 +767,10 @@
860767
" print(\" ✅ Context ready for future interactions\")\n",
861768
"\n",
862769
"# Run the realistic scenario\n",
863-
"if 'redis_config' in globals() and redis_config.health_check():\n",
770+
"if redis_config.health_check():\n",
864771
" await realistic_scenario()\n",
865772
"else:\n",
866-
" print(\"❌ Redis not available for scenario demonstration (using mock data)\")"
773+
" print(\"❌ Redis not available for scenario demonstration\")"
867774
]
868775
},
869776
{

python-recipes/context-engineering/notebooks/section-1-introduction/03_project_overview.ipynb

Lines changed: 12 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -118,48 +118,15 @@
118118
"metadata": {},
119119
"outputs": [],
120120
"source": [
121-
"# Import Redis Context Course components with error handling\n",
122-
"try:\n",
123-
" from redis_context_course.course_manager import CourseManager\n",
124-
" from redis_context_course.models import Course, DifficultyLevel, CourseFormat\n",
125-
" from redis_context_course.redis_config import redis_config\n",
126-
" \n",
127-
" PACKAGE_AVAILABLE = True\n",
128-
" print(\"✅ Redis Context Course package imported successfully\")\n",
129-
" \n",
130-
" # Check Redis connection\n",
131-
" redis_healthy = redis_config.health_check()\n",
132-
" print(f\"📡 Redis Connection: {'✅ Healthy' if redis_healthy else '❌ Failed'}\")\n",
133-
" \n",
134-
"except ImportError as e:\n",
135-
" print(f\"⚠️ Package not available: {e}\")\n",
136-
" print(\"📝 This is expected in CI environments. Creating mock objects for demonstration...\")\n",
137-
" \n",
138-
" # Create mock classes\n",
139-
" class CourseManager:\n",
140-
" def __init__(self):\n",
141-
" print(\"📝 Mock CourseManager created\")\n",
142-
" \n",
143-
" PACKAGE_AVAILABLE = False\n",
144-
" redis_healthy = False\n",
145-
" print(\"✅ Mock objects created for demonstration\")\n",
146-
"\n",
147-
"print(\"\\n🔍 Feature 1: Intelligent Course Search\")\n",
121+
"from redis_context_course.course_manager import CourseManager\n",
122+
"from redis_context_course.models import Course, DifficultyLevel, CourseFormat\n",
123+
"from redis_context_course.redis_config import redis_config\n",
124+
"\n",
125+
"print(\"🔍 Feature 1: Intelligent Course Search\")\n",
148126
"print(\"=\" * 50)\n",
149127
"\n",
150-
"# Initialize course manager with error handling\n",
151-
"try:\n",
152-
" course_manager = CourseManager()\n",
153-
" print(\"✅ Course manager initialized successfully\")\n",
154-
"except Exception as e:\n",
155-
" print(f\"⚠️ Error initializing course manager: {e}\")\n",
156-
" print(\"📝 Using mock course manager for demonstration...\")\n",
157-
" \n",
158-
" class MockCourseManager:\n",
159-
" def __init__(self):\n",
160-
" print(\"📝 Mock CourseManager created\")\n",
161-
" \n",
162-
" course_manager = MockCourseManager()\n",
128+
"# Initialize course manager\n",
129+
"course_manager = CourseManager()\n",
163130
"\n",
164131
"# Example search capabilities\n",
165132
"search_examples = [\n",
@@ -219,39 +186,7 @@
219186
"metadata": {},
220187
"outputs": [],
221188
"source": [
222-
"# Import StudentProfile with error handling\n",
223-
"try:\n",
224-
" from redis_context_course.models import StudentProfile\n",
225-
" MODELS_AVAILABLE = True\n",
226-
"except ImportError:\n",
227-
" print(\"⚠️ StudentProfile not available. Creating mock for demonstration...\")\n",
228-
" \n",
229-
" # Create mock classes\n",
230-
" class CourseFormat:\n",
231-
" ONLINE = \"online\"\n",
232-
" IN_PERSON = \"in_person\"\n",
233-
" HYBRID = \"hybrid\"\n",
234-
" \n",
235-
" class DifficultyLevel:\n",
236-
" BEGINNER = \"beginner\"\n",
237-
" INTERMEDIATE = \"intermediate\"\n",
238-
" ADVANCED = \"advanced\"\n",
239-
" \n",
240-
" class StudentProfile:\n",
241-
" def __init__(self, name, email, major, year, completed_courses, current_courses, \n",
242-
" interests, preferred_format, preferred_difficulty, max_credits_per_semester):\n",
243-
" self.name = name\n",
244-
" self.email = email\n",
245-
" self.major = major\n",
246-
" self.year = year\n",
247-
" self.completed_courses = completed_courses\n",
248-
" self.current_courses = current_courses\n",
249-
" self.interests = interests\n",
250-
" self.preferred_format = preferred_format\n",
251-
" self.preferred_difficulty = preferred_difficulty\n",
252-
" self.max_credits_per_semester = max_credits_per_semester\n",
253-
" \n",
254-
" MODELS_AVAILABLE = False\n",
189+
"from redis_context_course.models import StudentProfile\n",
255190
"\n",
256191
"print(\"🎯 Feature 2: Personalized Recommendations\")\n",
257192
"print(\"=\" * 50)\n",
@@ -274,7 +209,7 @@
274209
"print(f\" Name: {sample_student.name}\")\n",
275210
"print(f\" Major: {sample_student.major} (Year {sample_student.year})\")\n",
276211
"print(f\" Interests: {', '.join(sample_student.interests)}\")\n",
277-
"print(f\" Preferences: {sample_student.preferred_format}, {sample_student.preferred_difficulty}\")\n",
212+
"print(f\" Preferences: {sample_student.preferred_format.value}, {sample_student.preferred_difficulty.value}\")\n",
278213
"print(f\" Academic Progress: {len(sample_student.completed_courses)} completed, {len(sample_student.current_courses)} current\")\n",
279214
"\n",
280215
"print(\"\\n🧠 Recommendation Algorithm:\")\n",
@@ -319,37 +254,13 @@
319254
"metadata": {},
320255
"outputs": [],
321256
"source": [
322-
"# Import MemoryManager with error handling\n",
323-
"try:\n",
324-
" from redis_context_course.memory import MemoryManager\n",
325-
" MEMORY_AVAILABLE = True\n",
326-
"except ImportError:\n",
327-
" print(\"⚠️ MemoryManager not available. Creating mock for demonstration...\")\n",
328-
" \n",
329-
" class MemoryManager:\n",
330-
" def __init__(self, student_id: str):\n",
331-
" self.student_id = student_id\n",
332-
" print(f\"📝 Mock MemoryManager created for {student_id}\")\n",
333-
" \n",
334-
" MEMORY_AVAILABLE = False\n",
257+
"from redis_context_course.memory import MemoryManager\n",
335258
"\n",
336259
"print(\"🧠 Feature 3: Persistent Memory System\")\n",
337260
"print(\"=\" * 50)\n",
338261
"\n",
339-
"# Initialize memory manager with error handling\n",
340-
"try:\n",
341-
" memory_manager = MemoryManager(\"demo_student\")\n",
342-
" print(\"✅ Memory manager initialized successfully\")\n",
343-
"except Exception as e:\n",
344-
" print(f\"⚠️ Error initializing memory manager: {e}\")\n",
345-
" print(\"📝 Using mock memory manager for demonstration...\")\n",
346-
" \n",
347-
" class MockMemoryManager:\n",
348-
" def __init__(self, student_id: str):\n",
349-
" self.student_id = student_id\n",
350-
" print(f\"📝 Mock MemoryManager created for {student_id}\")\n",
351-
" \n",
352-
" memory_manager = MockMemoryManager(\"demo_student\")\n",
262+
"# Initialize memory manager\n",
263+
"memory_manager = MemoryManager(\"demo_student\")\n",
353264
"\n",
354265
"print(\"\\n📚 Memory Types:\")\n",
355266
"memory_types = [\n",

0 commit comments

Comments
 (0)