Project 4: AI Coding Agent
In Project 3 (docchat) you built a program that loads files into a conversation and answers questions about them. Its tools only read your computer: cat dumps a file, grep searches for text, and ls lists a directory, so the model can diagnose code but cannot edit it.
With tools for creating, editing, and deleting files, plus automatic git commits, docchat can edit a project like a small version of Claude Code or Cursor.
Due: Wednesday, December 2 at 11:59pm, see the schedule.
Learning objectives
- extend smaller projects into larger projects
- understand how AI agents work
Instructions
Your project must meet every specification from Project 3 (docchat). If you missed any points there, fix the issue now, or you will lose those points again on this project.
Create a new branch in your repository and do all of your work in it. You may not touch the
main/masterbranch you submitted for docchat.Coding tasks.
When your program starts, it should run two checks:
Look for a
.gitfolder in the current directory. If it is not present, print an error and stop.Look for an
AGENTS.mdfile in the current directory. If it is present, load it into the conversation using yourcattool.Note:
AGENTS.mdis a standard file that AI agents load when they start working in a repo. It is a README for the agent that lists project-specific instructions. You can find details and examples at https://agents.md/.
Then add the following four tools.
doctestsIt takes a single argument,
path.It runs the doctests in
pathwith the--verboseflag and returns the output.Note: Use
--verboseso the LLM sees explicit confirmation that the tests pass.Note: We have not covered how to run doctests from inside a Python program; any approach is fine.
write_fileIt takes three arguments:
path,contents, andcommit_message.It opens
pathand writescontentsto it. The output file must be UTF-8 encoded.Then it uses the
gitlibrary in Python to run the equivalent of:$ git add <path> $ git commit -m "[docchat] <commit_message>"Note: Commit every change the agent makes so you can revert its work when it “goes Skynet.”
If the file is a Python file, run your
docteststool on it and return the output.
write_filesIt takes two arguments:
filesandcommit_message.filesis a list of dictionaries, each with apathkey and acontentskey. Write each one the same waywrite_filedoes.After writing all of the files, add and commit them together.
Note: Implement the shared logic in
write_files, then makewrite_filecall it with a one-element list. Shared code is easier to test and change. This is the DRY principle, short for Don’t Repeat Yourself.
Note: Keep
write_filebecause LLMs use a specific tool more reliably than a general one. Its name and narrower schema make the appropriate call easier to select.
rmIt takes a single argument,
path.It deletes the path using Python’s
os.removefunction.It supports multiple files at once using globs.
It creates a commit with the file removed, using the commit message
[docchat] rm <path>.Warning: Incorrect
rmimplementations have caused real data loss:- Meta’s director of AI alignment research, Summer Yue, had Claude accidentally delete her inbox through a bad combination of the
rmandcompactcommands: https://www.pcmag.com/news/meta-security-researchers-openclaw-ai-agent-accidentally-deleted-her-emails. - Toy Story 2 was almost lost forever to a bad
rmcommand combined with a glob: https://thenextweb.com/news/how-pixars-toy-story-2-was-deleted-twice-once-by-technology-and-again-for-its-own-good.
- Meta’s director of AI alignment research, Summer Yue, had Claude accidentally delete her inbox through a bad combination of the
Warning: Every one of these tools must validate its
pathbefore running, exactly like your read tools did: it must not run on absolute paths or on paths containing... A bug in a read tool can leak a file to the model; the same bug here can let the agent delete files outside the project.Repository organization.
Add examples to your README that show the agent in action: creating, modifying, and deleting files, and making git commits along the way. Use shell commands like
ls,cat, andgitto show the before and after, and format the prompts clearly.This session shows
docchatcreating a file and committing it to the git repo:$ git checkout -b agent-work Switched to a new branch 'agent-work' $ ls -a .git AGENTS.md README.md $ git log --oneline c21103f (HEAD -> agent-work, master) init commit $ docchat chat> Create python code that implements the project in README.md Created the file hello_world.py chat> ^C $ ls -a .git AGENTS.md README.md hello_world.py $ git log --oneline 3cfb0a6 (HEAD -> agent-work) [docchat] create basic hello world python project c21103f (master) init commit
Grading rubric
This project is worth 20 points.
Gradescope runs the 18 automated points inside a temporary git repository. No model call, package installation, or destructive operation reaches your computer or the network.
You may still complete any of the extra credit from previous projects, though extra credit you have already earned will not be counted twice. The extra credit below is new for this project.
Extra credit
-
Warning: A PyPI package can run arbitrary code during installation, so an agent with this tool could execute malicious code on your computer. The popular
LiteLLMpackage recently suffered a supply-chain attack:- https://docs.litellm.ai/blog/security-hardening-april-2026
- https://www.trendmicro.com/en_us/research/26/c/inside-litellm-supply-chain-compromise.html
- https://console.groq.com/docs/litellm
Open question: how would you prove that a piece of code is “safe”?
-
Note: Anthropic recently renamed their Ralph Wiggum implementation to just “Ralph” for copyright reasons. You can follow along in their GitHub repo: https://github.com/anthropics/claude-plugins-official/commit/44328beed48874d8e00da6c4ca5daaa5f0f3183c.
-
Hint: The free Groq API’s Llama models have tight token limits and may struggle with this task. A current GPT or Claude Opus model generally performs better. An OpenRouter API key lets you experiment across models. This task should cost less than $0.10 with a current high-end model; $10 of credit leaves room to experiment.
-
Even current LLMs often generate invalid diffs because they are unreliable at identifying exact line positions. Standard
diffandpatchtools reject that output. Any workaround is acceptable. One option is wiggle, a tool built for applying these “broken” LLM-generated diffs.Updating only changed lines uses fewer tokens and avoids regenerating code that the LLM might accidentally alter, such as by dropping a
)that should match a(.
Submission
Push your work, then submit the new branch to the Project 4 programming assignment on Gradescope. Add a submission.toml file at the repository root:
[project]
branch = "agent-work"
base_commit = "abcdef0" # commit submitted for Project 3
submitted_commit = "1234567" # commit selected for Project 4
[features]
pip_install = false
ralph_loop = false
markdown_agent = false # or the GitHub branch URL when claimed
patches = falseSet only the extra-credit features you completed. For markdown_agent, replace false with the GitHub /tree/BRANCH URL containing the agent-only commits. Unclaimed extra-credit tests are skipped.
In the Gradescope comments, submit a one-to-two-sentence explanation of what you believe your grade should be:
- If you completed any extra credit, say so.
- Describe any part of your project that does not work; this may earn you more lenient grading.
- If you are requesting points back from a previous project, you must say so explicitly.