|
365 | 365 | "\n", |
366 | 366 | "catalog_view = redis_client.get(\"course_catalog_view\") or \"\"\n", |
367 | 367 | "\n", |
368 | | - "# Define a tool for searching courses\n", |
| 368 | + "# Define a tool for retrieving course details by course code\n", |
369 | 369 | "from langchain_core.tools import tool\n", |
| 370 | + "from typing import List\n", |
370 | 371 | "\n", |
371 | 372 | "@tool\n", |
372 | | - "async def search_courses_tool(query: str, limit: int = 5) -> str:\n", |
373 | | - " \"\"\"Search for courses by semantic similarity to the query.\n", |
| 373 | + "async def get_course_details(course_codes: List[str]) -> str:\n", |
| 374 | + " \"\"\"Get detailed information about one or more courses by their course codes.\n", |
374 | 375 | " \n", |
375 | 376 | " Args:\n", |
376 | | - " query: Natural language description of what courses to find\n", |
377 | | - " limit: Maximum number of courses to return (default: 5)\n", |
| 377 | + " course_codes: List of course codes (e.g., ['CS101', 'MATH201'])\n", |
378 | 378 | " \n", |
379 | 379 | " Returns:\n", |
380 | | - " Formatted string with course details\n", |
| 380 | + " Formatted string with detailed course information\n", |
381 | 381 | " \"\"\"\n", |
382 | | - " courses = await course_manager.search_courses(query=query, limit=limit)\n", |
383 | | - " if not courses:\n", |
384 | | - " return \"No courses found matching that query.\"\n", |
| 382 | + " if not course_codes:\n", |
| 383 | + " return \"No course codes provided.\"\n", |
385 | 384 | " \n", |
386 | 385 | " result = []\n", |
387 | | - " for course in courses:\n", |
388 | | - " result.append(f\"\"\"Course: {course.course_code} - {course.title}\n", |
| 386 | + " for code in course_codes:\n", |
| 387 | + " course = await course_manager.get_course_by_code(code)\n", |
| 388 | + " if course:\n", |
| 389 | + " result.append(f\"\"\"Course: {course.course_code} - {course.title}\n", |
389 | 390 | "Department: {course.department}\n", |
390 | 391 | "Description: {course.description}\n", |
391 | 392 | "Credits: {course.credits} | Difficulty: {course.difficulty_level}\n", |
392 | | - "Format: {course.format}\"\"\")\n", |
| 393 | + "Format: {course.format}\n", |
| 394 | + "Instructor: {course.instructor}\n", |
| 395 | + "Prerequisites: {', '.join([p.course_code for p in course.prerequisites]) if course.prerequisites else 'None'}\"\"\")\n", |
| 396 | + " else:\n", |
| 397 | + " result.append(f\"Course {code}: Not found\")\n", |
| 398 | + " \n", |
393 | 399 | " return \"\\n\\n\".join(result)\n", |
394 | 400 | "\n", |
395 | 401 | "# Bind the tool to the LLM\n", |
396 | | - "llm_with_tools = llm.bind_tools([search_courses_tool])\n", |
| 402 | + "llm_with_tools = llm.bind_tools([get_course_details])\n", |
397 | 403 | "\n", |
398 | 404 | "system_prompt = f\"\"\"You are a class scheduling agent for Redis University.\n", |
399 | 405 | "\n", |
400 | 406 | "{catalog_view}\n", |
401 | 407 | "\n", |
402 | 408 | "Use this overview to help students understand what's available.\n", |
403 | | - "For specific course details, use the search_courses_tool to find detailed information.\n", |
| 409 | + "When students ask about specific courses, use the get_course_details tool with the course codes from the overview above.\n", |
404 | 410 | "\"\"\"\n", |
405 | 411 | "\n", |
406 | 412 | "user_query = \"What departments offer courses? I'm interested in computer science.\"\n", |
|
0 commit comments