Instead of a single prompt-and-reply exchange, an agentic system runs a closed control loop: a local model proposes tool actions, an orchestrator executes them inside a sandboxed workspace, and real test results feed back as messages until the task passes.
A standard chat completion stops after generating text. An agentic workflow gives the model structured capabilities (list_files, read_file, write_file, run_pytest) and wraps inference inside a while / for loop bounded by --max-steps.
Because every file write and pytest traceback is appended back into the conversation history, the model observes the consequences of its own code and repairs syntax or import errors autonomously.
Runs locally on the RTX 4070 GPU. Interprets requirements, writes FastAPI routes and pytest suites, and diagnoses stack traces across loop iterations.
Manages the conversation state array, executes HTTP requests to /api/chat, parses structured or fallback JSON tool calls, and enforces --max-steps.
Resolves and locks all file operations strictly inside TARGET_DIR (e.g., C:\dev\fastapi-target), creating parent folders automatically while blocking path traversal.
Runs pytest using the isolated virtual environment of the target repository so dependency checks and test execution never collide with the agent runtime.
Ollama's /api/chat endpoint is stateless across HTTP calls. The orchestrator maintains memory by sending the growing messages array on every step.
Sends behavioral rules, user goal, and available tool schemas to local Ollama.
{ "model": "qwen2.5-coder", "messages": [system, user], "tools": TOOLS, "stream": false }Sets the engineering persona, enforces clean triple-quoted Python strings, and mandates running run_pytest after every code modification.
Injected from the PowerShell CLI or stdin. Defines target files, endpoints, and verification criteria without manual file editing.
Generated by Ollama (qwen2.5-coder). Either requests function executions via tool_calls or emits the final completion summary once tests pass.
Appended by agent.py after executing WorkspaceGuard or pytest. Feeds real file contents, write confirmations, or tracebacks back into context.
Select any stage below to inspect how messages move between agent.py, Ollama, and your target FastAPI workspace during a single automated build-and-test cycle.
The orchestrator (agent.py) loads .env.local, initializes WorkspaceGuard on TARGET_DIR, and sends the initial messages list (system + user) plus the TOOLS schema to Ollama via POST /api/chat.
{ "role": "user", "content": "Create app/main.py with GET /health and run_pytest." }Qwen2.5-coder evaluates the context and returns an assistant message containing tool_calls (or JSON extracted by extract_fallback_calls) specifying write_file, read_file, list_files, or run_pytest.
{ "role": "assistant", "tool_calls": [{ "function": { "name": "write_file", "arguments": { "rel_path": "app/main.py" } } }] }The model never touches the OS directly. agent.py validates paths inside TARGET_DIR, writes UTF-8 files, and runs pytest inside the target .venv, capturing returncode, stdout, and stderr.
{ "role": "tool", "content": "{\"returncode\": 1, \"stderr\": \"ModuleNotFoundError: No module named app.main\"}" }Every tool result is appended to messages with role: 'tool' and sent back to Ollama on step + 1. If pytest fails, the model reads the traceback, rewrites the file, and re-runs tests until green or --max-steps is reached.
{ "role": "assistant", "content": "All pytest checks passed in C:\\dev\\fastapi-target." }$env:TARGET_DIR = "C:\dev\fastapi-target" python agent.py "Update app/main.py, add tests, and run_pytest."
The orchestrator loops up to --max-steps turns, logging every tool invocation and halting automatically once the model confirms passing tests.