Build a Custom Langchain Tool for Generating and Executing Code

<p>In the previous articles (<a href="https://betterprogramming.pub/creating-my-first-ai-agent-with-vicuna-and-langchain-376ed77160e3" rel="noopener ugc nofollow" target="_blank">1</a>,<a href="https://betterprogramming.pub/fine-tuning-my-first-wizardlm-lora-ca75aa35363d" rel="noopener ugc nofollow" target="_blank">2</a>), we saw that LLMs could generate and execute coding instructions sequences &mdash; however, often, they get stuck on errors, especially related to package installation.</p> <p>I wanted to have something similar to Langchain Python REPL, but that instead:</p> <ol> <li>Allowed the generated source code to be saved in a file.</li> <li>Allowed the agent to install pip packages.</li> <li>Allowed execution of the source code, with the full output/traceback</li> <li>Allowed linters to be applied and different code generations sampled accordingly.</li> <li>Offered the option to delegate the code generation completely to the tool, so the main agent does not have to be necessarily good at coding (though the model used in code still has to be good at coding).</li> </ol> <p>To fulfill these requirements, I rolled my own library,&nbsp;code-it &mdash; it&rsquo;s still early in development, lacking some documentation and more testing. However, the basic functionality is working, and I would like to present it.</p> <p><a href="https://betterprogramming.pub/building-a-custom-langchain-tool-for-generating-executing-code-fa20a3c89cfd">Website</a></p>