Building something like this is the todo list of agents.
I found this one easy to understand:
https://ampcode.com/notes/how-to-build-an-agent