Start learning free

LESSON 100 OF 129 · AI ENGINEERING: BUILD YOUR OWN CODING AGENT

Project: Your Own Coding Agent

Practice

You have all the parts of a coding agent: six tools, the question before a risky command, the output limit, the step limit, the diff and the log of changes. In this project you put the loop back as a function, agent(task), that takes any task and returns the answer.

A function that returns its result, and leaves the printing to its caller, can be used anywhere: in a script, behind a Flask route, in a test. A small example:

def greet(name):
    return "Hello, " + name

text = greet("Ana")
print("Greeting:", text)   # Greeting: Hello, Ana

A function is also called more than once. Your agent keeps its conversation, its trace and its log of changes in three lists, and each task must find them empty: a second task that lands in the first task's conversation confuses the model. The step limit counts the trace, so it needs that fresh start too.

Your program gives the agent one task, and the check gives it two more. The first is fixed and proven by the tests, the second is stopped by the step limit, and the third reads a long log that is cut on its way to the model:

Step 1: run_command {'cmd': 'ls'}
...
Answer: Fixed. shipping() compared the total with >, so an order of exactly $50 still paid for shipping. I changed > to >= in cart.py, and all 6 tests pass. The cache folder is still there: you said no when I asked to remove it.
Trace: run_command > run_tests > read_file > write_file > run_tests > run_command
Changed: cart.py
Tests: OK
Tests pass after the run: True
The check gives the agent a new task: Tidy up the project.
...
Answer: Stopped after 8 steps, without an answer
The check gives the agent a new task: What is in orders.log?
...
orders.log has 400 lines. Lines the model got: 31

Your task: write agent(task): empty messages, trace and changes, put the task in as the first message, and run the tools in a loop for as long as the model asks for them. Return the model's last text, or Stopped after 8 steps, without an answer when the limit is reached. Then call it with "Make the failing test pass." and print the answer, the trace and a Changed: line for every change.


Assignment
Follow the Coding Tutorial to build agent(task) and the report of its run.


Hint
Inside a function, return ends the loop too, so the step limit needs no break. Empty the lists with .clear(): the other functions append to these same lists.


STEP 1 OF 11
    Ctrl + Enter to check