Overview
The AI Agent is more than a code generator - it’s a context-aware assistant that:- Understands your project - Analyzes project structure, dependencies, and code
- Maintains conversation history - Remembers previous interactions
- Tracks modifications - Records all code changes with undo capability
- Supports multiple providers - Works with various AI services
- Writes files directly - Can create and modify files with permission
The AI Agent requires an API key from a supported provider and internet connectivity.
Supported Providers
Android Code Studio supports multiple AI providers:- Anthropic (Claude)
- OpenAI
- Google (Gemini)
- DeepSeek
- Local LLM
Claude models by Anthropic
- Claude 3.5 Sonnet
- Claude 3 Opus
- Claude 3 Sonnet
- Claude 3 Haiku
- Get API key from console.anthropic.com
- In Android Code Studio: Settings → AI Agent → Provider
- Select Anthropic
- Enter your API key
Getting Started
Configure the AI Agent
- Open Settings → AI Agent
- Select your preferred provider
- Enter your API key
- (Optional) Choose a specific model
- Save settings
Open the AI Assistant
Tap the AI Agent icon in the toolbar, or select Tools → AI Agent from the menu.
Grant Permissions
On first use, the AI Agent requests permission to:
- Read your project files
- Access project structure
- Modify files (with confirmation)
Project Awareness
The AI Agent analyzes your project to provide contextual assistance:ProjectData.kt
- Your project structure and modules
- Available dependencies
- Existing classes and files
- Build configuration
- Package names
Example Interactions
File Operations
The AI Agent can create and modify files:Writing Files
AIAgent.kt:54
- Permission Check - Asks for your confirmation
- Content Preview - Shows what will be written
- Write Operation - Creates or updates the file
- Verification - Confirms success
File Write Results
FileWriteResult.kt
Modification Tracking
The agent tracks all modifications:AIAgent.kt:46-47
Modification History
Review Changes Screen
When the AI agent makes multiple file modifications, Android Code Studio presents a Review Changes interface: Features:- File List - See all files modified by the AI agent
- Diff Preview - View changes side-by-side with syntax highlighting
- Selective Apply - Choose which changes to accept or reject
- Summary - Overview of all modifications in the current batch
- Apply All - Accept all suggested changes
- Cancel - Reject all changes and close the review screen
- Individual Review - Select each file to review changes before applying
Always review AI-generated code in this screen before applying changes. The agent may make assumptions or introduce errors that need correction.
Undo Changes
Revert unwanted changes:AIAgent.kt:46
Conversation Management
The AI Agent maintains conversation context:Clear Conversation
AIAgent.kt:36
- Click Clear Chat in the AI Agent panel
- Or select Tools → AI Agent → Clear Conversation
Clearing the conversation removes context but preserves modification history.
Context Window
The agent maintains recent messages for context:- User messages - Your questions and requests
- Assistant responses - AI-generated answers
- System messages - Project context and information
- Modification results - File operation outcomes
Retry Logic
The agent includes automatic retry for failed operations:AIAgent.kt:49-52
- API rate limits are hit
- Network errors occur
- Generation fails temporarily
Best Practices
Be Specific
- Good
- Bad
“Create a RecyclerView adapter for User objects with name and email fields, showing a profile picture using Glide”
Provide Context
- Good
- Bad
“In MainActivity, add a button that navigates to the ProfileActivity and passes the user ID”
Review Generated Code
Iterate
If the result isn’t perfect:- Provide feedback: “The button should be in the top right corner”
- Ask for modifications: “Change this to use Kotlin coroutines instead”
- Request explanations: “Why did you use this approach?”
Common Use Cases
Generate Boilerplate Code
Generate Boilerplate Code
“Create a data class for an API response with id, title, description, and timestamp fields”The agent generates:
Add Dependencies
Add Dependencies
“Add Retrofit and Gson for networking”The agent updates
build.gradle.kts:Implement Patterns
Implement Patterns
“Implement the Repository pattern for user data with Room database”The agent creates:
- UserEntity.kt
- UserDao.kt
- UserRepository.kt
- AppDatabase.kt
Fix Errors
Fix Errors
“Fix the crash when rotating the screen in MainActivity”The agent:
- Analyzes MainActivity
- Identifies lifecycle issues
- Suggests ViewModel implementation
- Applies the fix
Optimize Code
Optimize Code
“Optimize this image loading code for better performance”The agent:
- Reviews the code
- Suggests caching strategies
- Recommends using Glide or Coil
- Implements the optimization
Permissions
The AI Agent respects user permissions:AIPermissionManager.kt
- Read Project - Allow reading project files
- Write Files - Allow creating/modifying files
- Execute Commands - Allow running Gradle tasks
- Access Network - Allow API requests
Limitations
Context Size
Large projects may exceed the model’s context window. Focus requests on specific modules.
API Costs
AI providers charge per request. Monitor usage to control costs.
Network Required
Requires internet connectivity (except for local LLM setup).
Not Always Accurate
AI can make mistakes. Always review generated code.
Troubleshooting
API Key Invalid
API Key Invalid
Error: “Invalid API key” or “Authentication failed”Solution:
- Verify your API key is correct
- Check that the key hasn’t expired
- Ensure you selected the correct provider
- Re-enter the key in Settings
Rate Limited
Rate Limited
Error: “Rate limit exceeded”Solution:
- Wait a few minutes before retrying
- Check your API provider’s rate limits
- Consider upgrading your plan
- Use retry logic (automatic)
Context Too Large
Context Too Large
Error: “Context length exceeded”Solution:
- Be more specific in your requests
- Focus on individual files or modules
- Clear conversation and start fresh
- Split large requests into smaller ones
No Response
No Response
Issue: Agent doesn’t respondSolution:
- Check internet connectivity
- Verify API service is operational
- Restart the IDE
- Check logs in Build Output
Security & Privacy
Best Practices
- Don’t share API keys or passwords with the agent
- Review what data is being sent
- Use local LLM for sensitive projects
- Check your organization’s AI usage policy
Advanced Configuration
Model Selection
Choose the right model for your needs:- Fast models (GPT-3.5, Claude Haiku) - Quick responses, lower cost
- Powerful models (GPT-4, Claude Opus) - Better understanding, higher cost
- Balanced models (Claude Sonnet) - Good balance of speed and quality
Temperature Settings
Adjust creativity vs. accuracy:Custom Prompts
Define system prompts for consistent behavior: Settings → AI Agent → System PromptNext Steps
- Configure environment variables for AI agent settings
- Build your app with AI-generated code
- Debug issues using AI assistance
- Explore plugins that extend AI capabilities