How muhammadtalha-prog/local-coding-agent works
Purpose and Entry Points
This is a local Python CLI for generating verified base-MATLAB .m functions from natural-language tasks. It uses a local Ollama-hosted coding model, optionally invokes installed MATLAB for validation, and saves successful output into a workspace.
Primary entry point: main.py. Central runtime settings and environment-derived defaults are in config.py.
Pipeline Orchestrator
main.py owns the end-to-end control flow: parse task/model/timeout/retry options, check LLM availability, invoke pipeline stages, report status, and copy verified artifacts to the output workspace. It also supports interactive task input when no task is supplied.
Paths: main.py, config.py.
Local LLM Boundary
The LLM integration is intentionally thin and direct: agents/llm_client.py communicates with Ollama’s local OpenAI-compatible API. Model selection, token limits, temperature, base URL, and request timeouts are configuration concerns rather than agent concerns.
Paths: agents/llm_client.py, config.py.
External service/runtime: Ollama must be running locally, typically at http://localhost:11434/v1; intended models include Qwen coder variants.
Planning Stage
The planner translates the user task into an in-memory structured implementation plan, including expected MATLAB file/function intent. This separates requirements decomposition from source generation and provides the coder with constrained context.
Paths: agents/planner.py, agents/llm_client.py.
Code Generation Stage
The coder consumes the task and plan to produce MATLAB source. The generated artifact is first written into the transient sandbox rather than directly to final output, establishing a validation boundary before publication.
Paths: agents/coder.py, sandbox/moving_average_filter.m.
The generation policy targets base MATLAB and avoids licensed toolbox dependencies.
MATLAB Execution and Verification
agents/matlab_executor.py is the system-process boundary. It runs MATLAB as a subprocess against sandboxed code, captures execution success/failure, and enforces a configurable execution timeout. MATLAB is optional: unavailable execution does not prevent code generation and saving, but eliminates runtime verification.
Paths: agents/matlab_executor.py, config.py, sandbox/.
External runtime: installed MATLAB executable, auto-detected or supplied through configuration.
Debug/Repair Loop
On MATLAB errors, the debugger receives the current code and execution diagnostics, asks the LLM for a correction, and returns revised source for another sandbox execution. The orchestrator bounds this feedback loop through MAX_DEBUG_RETRIES (default three), preventing unbounded model/subprocess work.
Paths: agents/debugger.py, agents/matlab_executor.py, main.py.
Artifact Lifecycle
Code moves through: user task → plan → generated sandbox .m file → optional MATLAB validation → debugger retries if needed → final verified .m file under a task-named workspace directory. Sandbox files are temporary pipeline artifacts; workspace output is the durable deliverable.
Paths: sandbox/, main.py, LOCAL_OPTIMIZATION_GUIDE.md.
Main entry points: main.py Pipeline CLI · llm_client.py LLM client · matlab_executor.py MATLAB executor · coder.py MATLAB coder
Components 14
CLI & orchestration
- User task · Natural-language MATLAB function request.
- Pipeline CLI · Parses options, coordinates stages, and publishes artifacts.
main.py - Runtime settings · Environment-derived model, timeout, and retry defaults.
config.py
Generation agents
- Local Ollama · Local OpenAI-compatible coding-model endpoint.
- LLM client · Direct boundary to the local Ollama API.
agents/llm_client.py - Task planner · Builds an in-memory MATLAB implementation plan.
agents/planner.py - MATLAB coder · Generates base-MATLAB source from the task and plan.
agents/coder.py - Repair agent · Revises source using MATLAB diagnostics.
agents/debugger.py
Validation & artifacts
- Transient sandbox · Holds generated code before publication.
sandbox - Generated .m file · Candidate source written for validation.
sandbox/moving_average_filter.m - MATLAB executor · Runs sandboxed code with a configurable timeout.
agents/matlab_executor.py - Installed MATLAB · Optional executable used for runtime verification.
- Task workspace · Task-named directory containing the final .m deliverable.
- Optimization guide · Documents local workflow guidance.
LOCAL_OPTIMIZATION_GUIDE.md
Connections 22
- User task → Pipeline CLI: task input
- Runtime settings → Pipeline CLI: CLI defaults
- Pipeline CLI → LLM client: availability check
- Runtime settings → LLM client: model/API settings
- LLM client → Local Ollama: API requests
- Pipeline CLI → Task planner: task
- Task planner → LLM client: plan prompt
- Task planner → MATLAB coder: implementation plan
- Pipeline CLI → MATLAB coder: task
- MATLAB coder → LLM client: generation prompt
- MATLAB coder → Generated .m file: write candidate
- Generated .m file → Transient sandbox: stored in
- Pipeline CLI → MATLAB executor: validate candidate
- Runtime settings → MATLAB executor: execution timeout
- MATLAB executor → Installed MATLAB: subprocess execution
- Generated .m file → MATLAB executor: source under test
- MATLAB executor → Repair agent: failure diagnostics
- Repair agent → LLM client: repair prompt
- Repair agent → Generated .m file: revised source
- Pipeline CLI → Repair agent: bounded retries · Limited by MAX_DEBUG_RETRIES.
- Pipeline CLI → Task workspace: publish generated or verified file
- Optimization guide → Pipeline CLI: workflow guidance