feat: improve todo agent (#83)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Todo
|
||||
|
||||
An AI agent that helps you manage a todo list
|
||||
|
||||
https://github.com/user-attachments/assets/36bd42ba-cbd6-4e0c-b8b1-bb3e28db9a98
|
||||
+14
-15
@@ -1,20 +1,19 @@
|
||||
name: Todo
|
||||
description: A helpful ai agent that manages a todo list.
|
||||
description: An AI agent that helps you manage a todo list
|
||||
version: 0.1.0
|
||||
instructions: |
|
||||
You will be provided with a list of todos.
|
||||
You are AI agent that manage a todo list.
|
||||
|
||||
Users can interact with you using the following tools:
|
||||
* add_todo: Add a todo to the list.
|
||||
* rm_todo: Remove a todo from the list.
|
||||
* list_todos: Display the current todo list.
|
||||
* clear_todos: Delete the entire todo list.
|
||||
Available tools:
|
||||
{{__tools__}}
|
||||
|
||||
When outputting the todo list to the user, don't simply print JSON data; instead, output it in Markdown format.
|
||||
`{"id": 1, "desc": "Buy milk", "done": true }` => `1. [x] Buy milk`
|
||||
`{"id": 2, "desc": "Buy eggs", "done": false}` => `2. [ ] Buy eggs`
|
||||
|
||||
Based on the interaction, ensure that you provide appropriate confirmations or errors for the requested operation. For example:
|
||||
- Confirmations: "Todo item added successfully!", "Todo item removed successfully!", "All todo items deleted!"
|
||||
- Errors: "Cannot add todo item, missing description.", "Todo item with id {id} not found.", "No todo items to delete."
|
||||
Make sure you understand the user request properly before performing any action. If unsure, ask clarifying questions like "Do you want to remove all todos or just a specific one?"
|
||||
conversation_starters:
|
||||
- "Add a new todo item: "
|
||||
- "What todos do I have pending?"
|
||||
- "Delete all my todos."
|
||||
- "How can I remove a specific todo item?"
|
||||
- "List all todos"
|
||||
- "Clean the entire todo list"
|
||||
- "Add a new todo: "
|
||||
- "Done todo id="
|
||||
- "Delete todo id="
|
||||
+38
-18
@@ -2,36 +2,50 @@
|
||||
set -e
|
||||
|
||||
# @cmd Add a new todo item
|
||||
# @option --desc! The task description
|
||||
# @option --desc! The todo description
|
||||
add_todo() {
|
||||
todos_file="$(_get_todos_file)"
|
||||
if [[ -f "$todos_file" ]]; then
|
||||
num="$(cat "$todos_file" | jq '[.[].id] | max + 1')"
|
||||
data="$(cat "$todos_file")"
|
||||
num="$(echo "$data" | jq '[.[].id] | max + 1')"
|
||||
else
|
||||
num=1
|
||||
data="[]"
|
||||
fi
|
||||
echo "$data" | \
|
||||
jq --arg new_id $num \
|
||||
--arg new_desc "$argc_desc" \
|
||||
'. += [{"id": $new_id | tonumber, "desc": $new_desc}]' \
|
||||
jq --arg new_id $num --arg new_desc "$argc_desc" \
|
||||
'. += [{"id": $new_id | tonumber, "desc": $new_desc, "done": false}]' \
|
||||
> "$todos_file"
|
||||
echo "Successfully added todo id=$num" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Delete an existing todo item
|
||||
# @option --id! <INT> The task id
|
||||
# @cmd Delete an todo item
|
||||
# @option --id! <INT> The todo id
|
||||
del_todo() {
|
||||
todos_file="$(_get_todos_file)"
|
||||
if [[ -f "$todos_file" ]]; then
|
||||
data="$(cat "$todos_file")"
|
||||
echo "$data" | \
|
||||
jq --arg id $argc_id '[.[] | select(.id != ($id | tonumber))]' \
|
||||
jq '[.[] | select(.id != '$argc_id')]' \
|
||||
> "$todos_file"
|
||||
echo "Successfully deleted todo id=$argc_id" >> "$LLM_OUTPUT"
|
||||
else
|
||||
echo "Empty todo list" >> "$LLM_OUTPUT"
|
||||
echo "The operation failed because the todo list is currently empty." >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Set a todo item status as done
|
||||
# @option --id! <INT> The todo id
|
||||
done_todo() {
|
||||
todos_file="$(_get_todos_file)"
|
||||
if [[ -f "$todos_file" ]]; then
|
||||
data="$(cat "$todos_file")"
|
||||
echo "$data" | \
|
||||
jq '. |= map(if .id == '$argc_id' then .done = true else . end)' \
|
||||
> "$todos_file"
|
||||
echo "Successfully mark todo id=$argc_id as done" >> "$LLM_OUTPUT"
|
||||
else
|
||||
echo "The operation failed because the todo list is currently empty." >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -45,22 +59,28 @@ list_todos() {
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Delete the entire todo list
|
||||
# @cmd Clean the entire todo list
|
||||
clear_todos() {
|
||||
todos_file="$(_get_todos_file)"
|
||||
if [[ -f "$todos_file" ]]; then
|
||||
rm -rf "$todos_file" >> "$LLM_OUTPUT"
|
||||
if [ -t 1 ]; then
|
||||
read -r -p "Clean the entire todo list? [Y/n] " ans
|
||||
if [[ "$ans" == "N" || "$ans" == "n" ]]; then
|
||||
echo "Aborted!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
rm -rf "$todos_file"
|
||||
echo "Successfully cleaned the entire todo list" >> "$LLM_OUTPUT"
|
||||
else
|
||||
echo "The operation failed because the todo list is currently empty." >> "$LLM_OUTPUT"
|
||||
fi
|
||||
echo "Successfully deleted entry todo list" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
_argc_before() {
|
||||
todos_file="$(_get_todos_file)"
|
||||
mkdir -p "$(dirname "$todos_file")"
|
||||
}
|
||||
|
||||
_get_todos_file() {
|
||||
echo "${LLM_AGENT_CACHE_DIR:-/tmp}/todos.json"
|
||||
todos_dir="${LLM_AGENT_CACHE_DIR:-.}"
|
||||
mkdir -p "$todos_dir"
|
||||
echo "$todos_dir/todos.json"
|
||||
}
|
||||
|
||||
# See more details at https://github.com/sigoden/argc
|
||||
|
||||
Reference in New Issue
Block a user