- Learn
- AI App Builders
- Replit
- Using Replit's AI Agent
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:
- Create a new Repl or open existing
- Click the AI button in the toolbar
- Select Replit Agent
- Describe what you want to build
Your First Agent Prompt
Let's build a simple app:
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:
- Plan: Show you what it intends to do
- Create files: Set up project structure
- Write code: Implement the features
- Install packages: Add necessary dependencies
- 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
✅ "Create a Flask app with SQLite database and Jinja2 templates"
❌ "Create a web app" (too vague—Agent will choose)
Describe Features Clearly
✅ "User authentication with:
- Registration with email/password
- Login page
- Protected dashboard
- Logout functionality"
❌ "Add login" (missing details)
Mention Design Preferences
✅ "Clean interface with a blue color scheme,
card-based layout, mobile-responsive"
❌ "Make it look good"
Specify Data Structure
✅ "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:
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:
The add expense form isn't submitting.
Debug and fix the issue.
Show me what was wrong.
Improving Code
Refactor the expense routes to use Flask blueprints.
Add proper error handling.
Changing Design
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:
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:
# Function to validate email format using regex
def validate_email(email):
# Ghostwriter fills in the implementation
Multi-Line Completion
Ghostwriter can suggest entire functions:
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:
What does this code do?
[paste code snippet]
How can I make this function more efficient?
What's the best way to handle file uploads in Flask?
Getting Explanations
Explain line by line what this SQL query does:
SELECT category, SUM(amount) FROM expenses GROUP BY category
Debugging Help
I'm getting this error: "TypeError: 'NoneType' object is not iterable"
Here's my code: [paste code]
What's wrong?
Learning New Concepts
Explain Flask blueprints and show me an example
What are Python decorators and when should I use them?
Generate Code Feature
From Natural Language
Select code or position cursor, then:
Generate a function that:
- Takes a list of numbers
- Returns the mean, median, and mode
- Handles empty lists gracefully
Transform Code
Convert this function to async
Add type hints to this code
Rewrite using list comprehension
Complete Boilerplate
Generate a Flask route that handles file upload
with validation for image files only
Best Practices
Start with Agent, Refine with Ghostwriter
- Use Agent for initial project creation
- Use Ghostwriter for incremental coding
- 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
// 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:
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
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
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
Add these features:
- Filter todos by completion status
- Sort by creation date
- Pagination (10 per page)
Step 3: Add Authentication
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
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.