Code Agent
Code Agent takes source code and transforms it with the help of an AI model: it upgrades it to a newer version of the same language, moves it to another language, modernises it or fixes security issues. You can give it a code snippet or several files at once.
The agent works in phases: it analyses the code, converts it, reviews the result and, if the review is not satisfactory, corrects it before returning it. It is useful when you have to bring old applications up to date and want a first draft of the conversion for your team to review.
When to use it
- You have a PHP 5 application that has to run on PHP 8.
- You want to move a set of JavaScript files to TypeScript.
- You need to upgrade old Java code to a current version.
- You want to review and fix known security issues in legacy code before an audit.
Configuration
| Field | What it does |
|---|---|
| Operations | The kind of work you ask the agent for: Code Language migration (move to another language keeping everything the code does), Code modernization (replace deprecated functions and apply current good practices) or Code security fix (convert while fixing security issues). Default: Code modernization. |
| Sources | The code you want to convert. You can type it or connect it from another component, as text or as files. If you connect several files, each one is converted separately. |
| Source Language (required) | The language and version of the original code: php5, php7, javascript, python2, python3, java8 or java11. Default: php5. |
| Target Language (required) | The language and version you want to reach: php8, php7, javascript, typescript, python3, python3.11, java17 or java21. It must be different from Source Language. Default: php8. |
| Conversion Type (required) | The type of conversion: version_upgrade, language_migration, modernization or security_fix. Pick the one that matches Operations. Default: version_upgrade. |
| Connection | What to connect |
|---|---|
| Language Model | The AI model that does the conversion, for example OpenAI or Anthropic. |
Advanced options
| Field | What it does |
|---|---|
| Enable Streaming | Sends the model’s answer as it is generated. Default: off. |
| Enable Retries | Automatically repeats a step if it fails. Default: on. |
| Max Execution Steps | The maximum number of steps the agent can take for each conversion. Default: 50. |
Output
- Data: one entry per converted piece of code or file, with the resulting code (
converted_code), the review result (validation_result) and the name of the original file (file_name). If a file’s conversion fails, its entry says so invalidation_result. Connect it to components that save files or process data. - Text: a message with all the generated code, ready to show in a Chat Output.
Example
A software company wants to prepare the migration of its customer portal, written in PHP 5.
- Connect the portal’s files to Sources.
- Choose
php5in Source Language andphp8in Target Language. - Leave Operations on
Code modernizationand Conversion Type onversion_upgrade. - Connect an AI model to Language Model and the Data output to a component that saves the converted files.
Your team then reviews each file before publishing it.
Good practices
- Always review and test the converted code before using it: the agent prepares a draft, it does not replace your team’s testing.
- Convert a few files first to check the result, and adjust the options before processing a whole project.
Related components
- Coding Agent V2: a conversational agent to write, edit, translate and analyse code.
- Code Task Agent: an agent that writes and runs code to solve tasks with data and files.