Beginner20 min

Learn how to use Replit's AI Agent to build applications from natural language descriptions and iterate with AI assistance.

Using Replit's AI Agent

Replit's AI Agent transforms natural language descriptions into working applications. It can create projects from scratch, add features, debug issues, and explain code—all through conversation.

Understanding Replit AI

AI Features Overview

Replit offers several AI-powered features:

Replit Agent

  • Creates entire applications from descriptions
  • Plans and executes multi-step tasks
  • Manages files and dependencies

Ghostwriter

  • Real-time code completion
  • Context-aware suggestions
  • Multi-line code generation

AI Chat

  • Ask questions about your code
  • Get explanations and suggestions
  • Debug with AI assistance

Generate Code

  • Write code from comments
  • Transform descriptions to implementation
  • Fill in boilerplate

Using Replit Agent

Starting with Agent

To use Replit Agent:

  1. Create a new Repl or open existing
  2. Click the AI button in the toolbar
  3. Select Replit Agent
  4. Describe what you want to build

Your First Agent Prompt

Let's build a simple app:

Terminal
Create a personal expense tracker app using Python and Flask.

Features:
- Add expenses with amount, category, and date
- View list of expenses
- See total spending by category
- Simple, clean web interface

Use SQLite for data storage.

Watching Agent Work

Replit Agent will:

  1. Plan: Show you what it intends to do
  2. Create files: Set up project structure
  3. Write code: Implement the features
  4. Install packages: Add necessary dependencies
  5. Test: Verify the app works

You'll see each step in the Agent panel.

Reviewing Agent Output

After completion, Agent provides:

  • Summary of what was created
  • List of files added/modified
  • Instructions for running
  • Suggestions for next steps

Always review the code before deploying.

Effective Agent Prompts

Be Specific About Tech Stack

Terminal
 "Create a Flask app with SQLite database and Jinja2 templates"

 "Create a web app" (too vague—Agent will choose)

Describe Features Clearly

Terminal
 "User authentication with:
   - Registration with email/password
   - Login page
   - Protected dashboard
   - Logout functionality"

 "Add login" (missing details)

Mention Design Preferences

Terminal
 "Clean interface with a blue color scheme,
    card-based layout, mobile-responsive"

 "Make it look good"

Specify Data Structure

Terminal
 "Tasks table with columns:
   - id (auto-increment)
   - title (string, required)
   - completed (boolean, default false)
   - due_date (datetime, optional)"

 "Store tasks" (leaves structure to Agent)

Iterating with Agent

Adding Features

After initial creation:

Terminal
Add these features to the expense tracker:
- Edit existing expenses
- Delete expenses with confirmation
- Filter by date range
- Export to CSV

Fixing Issues

When something doesn't work:

Terminal
The add expense form isn't submitting.
Debug and fix the issue.
Show me what was wrong.

Improving Code

Terminal
Refactor the expense routes to use Flask blueprints.
Add proper error handling.

Changing Design

Terminal
Update the styling:
- Use a dark theme
- Add icons from Font Awesome
- Improve mobile layout

Ghostwriter: AI Code Completion

How It Works

As you type, Ghostwriter suggests completions:

Terminal
def calculate_total(expenses):
    # Ghostwriter suggests:
    total = sum(expense.amount for expense in expenses)
    return total

Press Tab to accept, or keep typing to ignore.

Triggering Suggestions

Ghostwriter activates when:

  • You pause while typing
  • You start a new line
  • You write a comment describing intent

Comment-Driven Development

Write comments, get code:

Terminal
# Function to validate email format using regex
def validate_email(email):
    # Ghostwriter fills in the implementation

Multi-Line Completion

Ghostwriter can suggest entire functions:

Terminal
def get_expenses_by_category(category):
    # Ghostwriter suggests multiple lines:
    expenses = db.session.query(Expense).filter(
        Expense.category == category
    ).all()
    return expenses

AI Chat Features

Asking Questions

Open the AI chat and ask:

Terminal
What does this code do?
[paste code snippet]
Terminal
How can I make this function more efficient?
Terminal
What's the best way to handle file uploads in Flask?

Getting Explanations

Terminal
Explain line by line what this SQL query does:
SELECT category, SUM(amount) FROM expenses GROUP BY category

Debugging Help

Terminal
I'm getting this error: "TypeError: 'NoneType' object is not iterable"
Here's my code: [paste code]
What's wrong?

Learning New Concepts

Terminal
Explain Flask blueprints and show me an example
Terminal
What are Python decorators and when should I use them?

Generate Code Feature

From Natural Language

Select code or position cursor, then:

Terminal
Generate a function that:
- Takes a list of numbers
- Returns the mean, median, and mode
- Handles empty lists gracefully

Transform Code

Terminal
Convert this function to async
Terminal
Add type hints to this code
Terminal
Rewrite using list comprehension

Complete Boilerplate

Terminal
Generate a Flask route that handles file upload
with validation for image files only

Best Practices

Start with Agent, Refine with Ghostwriter

  1. Use Agent for initial project creation
  2. Use Ghostwriter for incremental coding
  3. Use Chat for questions and debugging

Review AI Output

AI-generated code may have:

  • Security vulnerabilities
  • Performance issues
  • Missing edge cases
  • Outdated patterns

Always review and understand generated code.

Iterate Incrementally

Terminal
// First prompt
Create basic expense tracker with add/view

// After that works
Add editing and deleting

// After that works
Add filtering and categories

// Continue building up

Use AI for Learning

When you see unfamiliar code:

Terminal
I don't understand how this decorator works.
Explain it step by step.

Agent Limitations

What Agent Struggles With

  • Complex architectural decisions
  • Highly specialized domains
  • Performance-critical code
  • Security-sensitive features

When to Take Over

Switch to manual coding when:

  • Agent makes repeated mistakes
  • You need precise control
  • Implementing complex business logic
  • Security is critical

Combining AI and Manual

Terminal
Agent: Create the basic structure
Manual: Implement business logic
Agent: Add error handling
Manual: Security review
Agent: Add tests
Manual: Final review

Practical Example: Build a Todo API

Step 1: Initial Creation

Terminal
Create a REST API for a todo app using FastAPI and SQLite.

Endpoints:
- GET /todos - list all todos
- POST /todos - create todo
- PUT /todos/{id} - update todo
- DELETE /todos/{id} - delete todo

Include proper status codes and error handling.

Step 2: Add Features

Terminal
Add these features:
- Filter todos by completion status
- Sort by creation date
- Pagination (10 per page)

Step 3: Add Authentication

Terminal
Add simple API key authentication:
- X-API-Key header required for all endpoints
- Store key in secrets
- Return 401 for missing/invalid key

Step 4: Documentation

Terminal
Add automatic API documentation using FastAPI's
built-in Swagger UI.

Summary

  • Replit Agent builds apps from descriptions
  • Ghostwriter provides real-time code completion
  • AI Chat answers questions and explains code
  • Generate Code creates code from natural language
  • Iterate incrementally—don't do everything at once
  • Review all AI-generated code before using

Next Steps

Now that you can use Replit's AI features, let's explore the platform's other powerful capabilities for developers.

Mark this lesson as complete to track your progress