This project is an example of a LangChain agent for task management. The agent can add tasks, search for tasks based on their status, and delete tasks. This example does not use a real database, only simulated data for demonstration purposes.
- Clone the repository.
- Create a
.env
file in the root directory with your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
- Install the required dependencies:
pip install -r requirements.txt
- Run the FastAPI server:
uvicorn main:app --reload
The agent provides three main functions:
add_task
: Adds a new task with a description and due date.search_tasks
: Searches for tasks with a specified status (e.g., pending, completed).delete_task
: Deletes a task.
Interaction with the agent is done through the /chat
route. Send a POST request to this route with the following body:
{
"text": "Request content here"
}
To add a new task, you can send:
curl -X POST "http://localhost:8000/chat" -H "Content-Type: application/json" -d '{"text": "I need to buy bread tomorrow"}'
The agent will invoke a function that will create the task and return a response like this:
{
"status": "success",
"operation": "add",
"task_description": "buy bread",
"due_date": "2024-07-15"
}
The agent will then return a natural language response to the user, such as:
{
"response": "I have added your task to buy bread tomorrow. If there is anything else I can help with, please let me know."
}
You can interact with the agent informally. For example, to add a task, you can send a text like:
{
"text": "I need to buy bread tomorrow"
}
Or to search for pending tasks, you can send:
{
"text": "What are my pending tasks?"
}
And to delete a task, you can send:
{
"text": "Delete the task to buy bread"
}
The agent will process the request and return the appropriate response in natural language.