Get tasks from Todoist
We all dream to have our own AI personal assistant someday. While the perfect AI assistant might still be far away, we can build simple AI agents that work with Todoist today.
Scenario
For this demo, we will focus on simply getting the tasks due today from Todoist.
Our AI agent has tools to do the following with our Todoist account:
- Get tasks
- Create tasks
- Update tasks
- Complete tasks
- Delete tasks
But you can use our Todoist tools to create new tasks or update, close, and delete existing tasks. You can even combine it with other tools to create a more capable AI assistant.
Setup
To get started, we first set the following environment variables in a .env
file:
TODOIST_API_TOKEN
: The API key of the Todoist account you want to use<COMPANY>_API_KEY
: The API key of the model you want to use
Now, we are ready to load the Todoist tools and build our AI agent.
Scripts
Here are the scripts for the various major LLM providers and frameworks. Remember to install the required dependencies mentioned at the top of each script.
import os
import anthropic
from dotenv import load_dotenv
import stores
# Load environment variables
load_dotenv()
# Load tools and set the required environment variables
index = stores.Index(
["silanthro/todoist"],
env_var={
"silanthro/todoist": {
"TODOIST_API_TOKEN": os.environ["TODOIST_API_TOKEN"],
},
},
)
# Get response from the model
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{"role": "user", "content": "What tasks are due today?"}
],
# Pass tools
tools=index.format_tools("anthropic"),
)
tool_call = response.content[-1]
# Execute tool call
result = index.execute(tool_call.name, tool_call.input)
print(f"Tool output: {result}")
In the folder where you have this script, you can run the AI agent with the command:
python get-todoist-tasks.py
The agent should then return the tasks in your Todoist account that are due today.
If you have any questions, let us know on GitHub.