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.
Start
Continue in the docchat repository from Project 3. Fix any missing Project 3 requirements first, then create and switch to a new branch named agent-work. Keep the Project 3 branch unchanged.
Learning Objectives
- extend smaller projects into larger projects
- understand how AI agents work
Build the Agent
When your program starts, it should run two checks:
-
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.
doctests
-
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_file
-
$ 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.”
write_files
-
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.
rm
-
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, and git to show the before and after, and format the prompts clearly.
This session shows docchat creating 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. The checks exercise both passing and failing doctests, file contents and commits, startup, and rejected paths. Instructor review also verifies the required shared implementation, Python libraries, and retained Project 3 behavior; these cannot be established by searching for a function name in the source.
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(.
Submit
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. Claimed pip_install and patch tools are exercised offline. The Ralph loop and agent-built compiler need instructor review of the behavior and branch history; Gradescope shows a pending-review notice rather than awarding points for a keyword or link alone.
Commit and sync the required files. On Gradescope, choose GitHub and submit your docchat repository and its agent-work branch.
In the Gradescope comments, submit a one-to-two-sentence explanation of what you believe your grade should be: