---
title: "Code Modernization Code"
source: https://docs.autohand.ai/agent-sdk/tutorials/400-code-modernization
---

# Code Modernization Agent

Build an advanced coding assistant that modernizes legacy code automatically with the Autohand Code Agent SDK. Available in TypeScript, Python, and Java.

In this advanced tutorial, you'll build a code modernization coding assistant that identifies outdated patterns, suggests modern alternatives, creates updated versions of files, and generates migration guides. This demonstrates real-world coding assistant capabilities for code transformation.

**Prerequisites:**

-   Completed [Multi-Tool Reasoning](200-multi-tool-reasoning.html)
-   Node.js 16+ (for TypeScript), Python 3.10+ (for Python), or Java 11+ (for Java)
-   SDK installed for your chosen language
-   API key from your LLM provider (set as `AUTOHAND_API_KEY`)
-   Understanding of modern patterns in your chosen language

## What You'll Build

A code modernization coding assistant that:

-   Identifies outdated patterns (old string formatting, deprecated imports, etc.)
-   Suggests modern alternatives (template literals, modern array methods, etc.)
-   Creates updated versions of files using WRITE\_FILE and EDIT\_FILE
-   Generates MIGRATION.md documentation explaining changes
-   Updates dependency files with modern versions
-   Tests that modernized code still compiles

## Step 1: Create Legacy Project

First, create a sample legacy project with outdated patterns in your chosen language:

## Step 2: Create Modernization Agent

Create an agent with detailed instructions for modernization in your chosen language:

## Step 3: Run Modernization

Run the modernization agent on the legacy project in your chosen language:

## Key Concepts

1

**Complex Instructions**

Detailed coding assistant instructions guide the coding assistant through complex multi-step tasks.

2

**File Creation and Editing**

Using WRITE\_FILE to create new files and EDIT\_FILE for targeted modifications.

3

**Documentation Generation**

Coding assistants can automatically generate documentation (MIGRATION.md) explaining changes.

4

**Validation and Testing**

Using BASH to run tsc and validate that modernized code still compiles.

## Complete Example

Here's the complete example with cleanup:

## Real-World Applications

This pattern can be applied to:

-   **Legacy migration:** Migrate large codebases from old patterns to modern ones
-   **Framework upgrades:** Update code to work with new framework versions
-   **Code quality:** Automatically apply best practices and linting rules
-   **Dependency updates:** Update dependencies and fix breaking changes
-   **Documentation generation:** Auto-generate docs from code changes

## Next Steps

### 📁 View the Example

See the complete example in the TypeScript SDK repository.

[View on GitHub →](https://github.com/autohandai/agent-sdk-typescript/tree/main/examples/23-code-modernization)

### 🔧 Documentation Maintenance

Learn how to build agents that maintain documentation automatically.

[View Example →](https://github.com/autohandai/agent-sdk-typescript/tree/main/examples/24-documentation-maintenance)

### 📚 Explore More Examples

Check out all examples in the SDK repositories.

[TypeScript Examples →](https://github.com/autohandai/agent-sdk-typescript/tree/main/examples)