This project serves as an investigation of multiple methodologies for implementing an AI assistant. This assistant provides useful answers to travel-related queries.
Getting started with large language modelling and generative AI can be overwhelming due to the wide variety of tools, techniques and methods available. A practical approach to learning is to focus on a straightforward use case and build models from scratch.
This project is designed as a starting point, providing a learning experience for beginners in the field. Here, the same application has been implemented using four approaches.
- Basic prompt-driven (
core/basic
): A non-agentic framework that uses chat completions API from OpenAI and tool calling. - Multi-agent (
core/agents_method
): An multi-agent framework based on chat completions API and tool calling. - LangGraph single-agent (
core/langGraph_single_agent
): A single-agent graph framework with tool calling implemented using LangChain and LangGraph. - LangGraph multi-agent (
core/langGraph_multi_agent
): A multi-agent graph framework with specialized paths for handling each task using LangChain and LangGraph.
- Travel duration given the origin, destination and mode of travel.
- Traffic updates for a given route
- Transit route numbers for a given trip.
- Transit schedule for a route number.
- Other travel-related queries (the assistant decides which queries are relevant).
- python==3.7+
- langchain==0.3.9
- langchain-core==0.3.21
- langchain-openai==0.2.8
- langgraph==0.2.53
- openai==1.54.4
- pydantic==2.9.2
- langsmith==0.1.147 (for evaluation)
- python-dotenv==1.0.1 (for environment variable management)
- requests==2.32.3 (for calling Google maps API)
-
Clone the repository
git clone https://github.com/buddhiW/travel_duration_assistant_2.git cd travel_duration_assistant
-
Install dependencies
pip install -r requirements.txt
-
Setup API keys
- Obtain an API key from OpenAI.
- Obtain an API key from LangChain.
- Create a
.env
file in the root directory and add the API keys:
OPENAI_API_KEY=your_openai_api_key LANGCHAIN_API_KEY=your_langchain_api_key
This project uses OpenAI's
gpt-4
models. However, you can experiment with other models.
Navigate to the folder corresponding to each approach within the core
folder and execute main.py.
python main.py
questions
list in main.py is a sample list of questions you can use to test the applications.
- This approach involves the fewest moving components, making it simple and straightforward.
- It is well-suited for tasks with a limited number of subtasks or functions. However, as the number of subtasks grows, the prompt construction can become complicated and potentially lead to degraded performance.
- Conversation history is maintained by appending all messages to the
messages
parameter in thechat.completions.create
API call. This can lead to inefficiencies as the conversation length increases.
- In this approach, each subtask is handled by a dedicated agent with its own specific instructions, resulting in a cleaner and more modular design.
- A central agent, referred to as the
triage_agent
, orchestrates the workflow by delegating the subtasks to corresponding agents. - This enhances scalability and flexibility, as agents can recursively delegate subtasks to other agents.
- However, certain tasks such as tool execution are still handled manually, as seen in the
run_assistant
function.
- This approach reimagines the application as a graph, leveraging the modularity and abstraction provided by LangGraph.
- Many routines previously implemented manually are now streamlined using LangChain’s built-in interfaces, resulting in a more maintainable implementation. This is evidenced by the updated
run_assistant
function. - LangGraph’s
MemorySaver
checkpointing mechanism provides efficient memory management. This leads to better recall capabilities, improved token efficiency and overall smoother operation.
- This extends the Multi-agent framework by integrating LangGraph for better task ochestration and memory management.
- This method is suitable for multi-step tasks where the dependency between tasks can be modeled as a graph.
- The implementation demands a higher level of expertise compared to the Multi-agent approach since it relies on more advanced concepts in LangGraph.
- Although the chosen task may to too simple to fully leverage the benefits of LangGraph, it demonstates how a multi-agent framework can effectively manage isolated workflows for different tasks, thereby reducing the burden on the
triage_agent
.
This project incorporates code snippets and ideas from the following sources:
- Tool calling and multi-agent framework with Chat Completions API - Licensed under MIT.
- LangGraph introductory tutorial - Licensed under MIT.
- Message history with LangGraph - Lincensed under MIT.
- Multi-agent supervisor using LangGraph - Licensed under MIT.
- Customer support bot using LangGraph - Licensed under MIT.
I acknowledge and thank the authors of these resources for their contributions to the open-source community.
If you believe I have inadvertently used code without proper credit, please contact me, and I will rectify this promptly.