@@ -46,25 +46,6 @@ class CheckPrerequisitesInput(BaseModel):
4646 )
4747
4848
49- class StoreMemoryInput (BaseModel ):
50- """Input schema for storing memories."""
51- text : str = Field (description = "The information to remember" )
52- memory_type : str = Field (
53- default = "semantic" ,
54- description = "Type of memory: 'semantic' for facts, 'episodic' for events"
55- )
56- topics : List [str ] = Field (
57- default = [],
58- description = "Topics/tags for this memory (e.g., ['preferences', 'courses'])"
59- )
60-
61-
62- class SearchMemoriesInput (BaseModel ):
63- """Input schema for searching memories."""
64- query : str = Field (description = "What to search for in memories" )
65- limit : int = Field (default = 5 , description = "Maximum number of memories to retrieve" )
66-
67-
6849# Course Tools
6950def create_course_tools (course_manager : CourseManager ):
7051 """
@@ -184,87 +165,28 @@ async def check_prerequisites(course_code: str, completed_courses: List[str]) ->
184165
185166
186167# Memory Tools
187- def create_memory_tools (memory_client : MemoryAPIClient ):
168+ def create_memory_tools (memory_client : MemoryAPIClient , session_id : str , user_id : str ):
188169 """
189- Create memory-related tools.
170+ Create memory-related tools using the memory client's built-in LangChain integration .
190171
191172 These tools are demonstrated in Section 3, notebook 04_memory_tools.ipynb.
192173 They give the LLM explicit control over memory operations.
193- """
194-
195- @tool (args_schema = StoreMemoryInput )
196- async def store_memory (text : str , memory_type : str = "semantic" , topics : List [str ] = []) -> str :
197- """
198- Store important information in long-term memory.
199-
200- Use this tool when:
201- - Student shares preferences (e.g., "I prefer online courses")
202- - Student states goals (e.g., "I want to graduate in 2026")
203- - Student provides important facts (e.g., "My major is Computer Science")
204- - You learn something that should be remembered for future sessions
205-
206- Do NOT use for:
207- - Temporary conversation context (working memory handles this)
208- - Trivial details
209- - Information that changes frequently
210-
211- Examples:
212- - text="Student prefers morning classes", memory_type="semantic", topics=["preferences", "schedule"]
213- - text="Student completed CS101 with grade A", memory_type="episodic", topics=["courses", "grades"]
214- """
215- try :
216- from agent_memory_client .models import ClientMemoryRecord
217-
218- # Note: user_id should be passed from the calling context
219- # For now, we'll let the client use its default namespace
220- memory = ClientMemoryRecord (
221- text = text ,
222- memory_type = memory_type ,
223- topics = topics if topics else ["general" ]
224- )
225174
226- await memory_client .create_long_term_memory ([memory ])
227- return f"✅ Stored memory: { text } "
228- except Exception as e :
229- return f"❌ Failed to store memory: { str (e )} "
230-
231- @tool (args_schema = SearchMemoriesInput )
232- async def search_memories (query : str , limit : int = 5 ) -> str :
233- """
234- Search for relevant memories using semantic search.
235-
236- Use this tool when:
237- - You need to recall information about the student
238- - Student asks "What do you know about me?"
239- - You need context from previous sessions
240- - Making personalized recommendations
241-
242- The search uses semantic matching, so natural language queries work well.
243-
244- Examples:
245- - query="student preferences" → finds preference-related memories
246- - query="completed courses" → finds course completion records
247- - query="goals" → finds student's stated goals
248- """
249- try :
250- results = await memory_client .search_long_term_memory (
251- text = query ,
252- limit = limit
253- )
175+ Args:
176+ memory_client: The memory client instance
177+ session_id: Session ID for the conversation
178+ user_id: User ID for the student
254179
255- if not results .memories :
256- return "No relevant memories found."
180+ Returns:
181+ List of LangChain StructuredTool objects for memory operations
182+ """
183+ from agent_memory_client .integrations .langchain import get_memory_tools
257184
258- result = f"Found { len (results .memories )} relevant memories:\n \n "
259- for i , memory in enumerate (results .memories , 1 ):
260- result += f"{ i } . { memory .text } \n "
261- result += f" Type: { memory .memory_type } | Topics: { ', ' .join (memory .topics )} \n \n "
262-
263- return result
264- except Exception as e :
265- return f"❌ Failed to search memories: { str (e )} "
266-
267- return [store_memory , search_memories ]
185+ return get_memory_tools (
186+ memory_client = memory_client ,
187+ session_id = session_id ,
188+ user_id = user_id
189+ )
268190
269191
270192# Tool Selection Helpers (from Section 4, notebook 04_tool_optimization.ipynb)
0 commit comments