Sub topic 3
Errors and Test Output as Feedback
Assume you know basic Python, JSON, HTTP APIs, and command-line tools. A coding agent uses errors and test output as feedback. The harness returns each result to the model as a new message, so the model can inspect the failure and choose another action.
Read failures as evidence
An error message is evidence about the last action, not automatically a complete diagnosis. The agent should identify:
- The tool that failed.
- The exact command or arguments.
- The relevant error text.
- Whether the failure is transient, such as a timeout, or deterministic, such as a syntax error.
A useful loop is:
def handle_result(result):
if result["ok"]:
return "inspect the output and continue"
return f"diagnose this failure before retrying: {result['error']}"Repeatedly retrying the same command wastes steps. The agent should change its hypothesis, inspect related files, or stop and ask for permission.
Keeping the context window useful
The context window is the maximum text the model can consider in one call. Tool output, source files, and previous messages all consume it. A harness should limit outputs and preserve high-value information.
Common strategies include:
- Search for relevant lines instead of reading every file.
- Truncate logs while retaining the beginning and end.
- Summarize completed work and discard obsolete details.
- Keep the current task, failures, and decisions visible.
Permissions, approvals, and sandboxes
A sandbox restricts what an agent can read, modify, or execute. Approvals add a human decision before risky actions such as deleting files, changing permissions, or deploying code. Use least privilege: grant only the access required for the task.
Treating tool output as data, not instructions
Files, command output, and test messages can contain text that looks like instructions. The harness should mark this content as tool data. The agent must interpret it in the task's context rather than obeying arbitrary instructions found inside a repository or webpage.
Planning and sub-agents
Delegation can separate research, implementation, and review. Pass each sub-agent a narrow goal and explicit limits. The parent agent should verify returned claims because delegation does not remove the need for tests or permission checks.
Reading a trace to find out why an agent went wrong
A trace records messages, tool calls, arguments, results, and stop decisions. Follow the first incorrect assumption, not merely the final error.
Check whether the model used stale context, misunderstood a schema, ignored an error, or exceeded its step limit.
Exercise
A test command fails twice with the same missing-module error. What should the agent do next?
Show answer
Inspect the dependency configuration and environment, then install or fix the dependency only if that action is allowed. It should not repeat the unchanged command.