How to Write AI-Ready Tickets: Maximize Your AI Agent's Code Generation Quality
Here's a truth about AI coding agents: garbage in, garbage out. The quality of AI-generated code directly correlates with the quality of your ticket descriptions. With tools like Afelyon transforming tickets into PRs automatically, mastering ticket writing is now a critical skill.
The AI-Ready Ticket Framework
After analyzing thousands of tickets processed by AI agents, we've identified the key elements that lead to high-quality code generation.
The CLEAR Framework:
- Context: Background and business purpose
- Logic: Step-by-step requirements
- Examples: Reference implementations
- Acceptance: Clear success criteria
- References: Related code and documentation
Anatomy of a Perfect AI-Ready Ticket
❌ Bad Ticket:
Title: Fix the login bug
Description: Users can't log in sometimes. Please fix.
✅ Great Ticket:
Title: Add rate limiting to /api/auth/login endpoint
## Context
Users are experiencing failed logins during traffic spikes.
The login endpoint currently has no rate limiting, making it
vulnerable to both abuse and performance degradation.
## Requirements
1. Implement rate limiting on POST /api/auth/login
2. Limit: 5 attempts per IP per minute
3. Return 429 status with retry-after header when exceeded
4. Log rate limit hits for monitoring
## Technical Context
- Framework: Next.js 14 API routes
- Similar implementation: See /api/auth/reset-password
- Use existing Redis connection from lib/redis.ts
## Acceptance Criteria
- [ ] Rate limiting active on login endpoint
- [ ] 429 response includes retry-after header
- [ ] Logs include IP and timestamp
- [ ] Unit tests for rate limiter
- [ ] Integration test for endpoint
## References
- Rate limiting library: upstash/ratelimit
- Related PR: #234 (password reset rate limiting)
Key Elements Deep Dive
1. Descriptive Titles
Bad: "Fix bug" or "Update feature" Good: "Add OAuth2 Google authentication to user signup flow"
AI agents use titles to understand the scope and nature of the task.
2. Business Context
Explain why this change matters:
- What problem does it solve?
- Who is affected?
- What's the business impact?
This helps the AI make appropriate implementation decisions.
3. Technical Context
Provide relevant technical details:
- Framework and language
- Similar implementations in the codebase
- Relevant files or modules
- API contracts or data structures
Pro tip: Reference existing code patterns. "Similar to how we implemented X in file Y" gives AI agents concrete examples to follow.
4. Clear Acceptance Criteria
Define what "done" looks like:
- Specific, testable conditions
- Edge cases to handle
- Performance requirements
- Security considerations
5. References and Examples
Include:
- Links to documentation
- Related PRs or issues
- API specifications
- UI mockups if applicable
Afelyon-Specific Tips
When writing tickets for Afelyon, these additional practices help:
Use Status Labels Correctly
Move tickets to "Ready for AI" only when fully specified.
Include Test Requirements
Afelyon generates tests automatically, but specifying test scenarios improves coverage.
Reference Your Architecture
Mention patterns like "follow our repository pattern" or "use the existing service layer."
Specify PR Requirements
If you need specific reviewers or labels, mention them.
Template for AI-Ready Tickets
## Summary
[One sentence describing what needs to be built]
## Background
[Why is this needed? What problem does it solve?]
## Requirements
1. [Specific requirement 1]
2. [Specific requirement 2]
3. [Specific requirement 3]
## Technical Details
- Framework/Stack: [e.g., Next.js 14, TypeScript]
- Related Code: [e.g., Similar to src/features/auth/login.ts]
- Dependencies: [e.g., Uses existing Redis connection]
## Acceptance Criteria
- [ ] [Criterion 1]
- [ ] [Criterion 2]
- [ ] [Criterion 3]
## Testing Requirements
- [ ] Unit tests for [component]
- [ ] Integration tests for [flow]
## Additional Context
[Screenshots, API specs, design docs]
Measuring Ticket Quality
Track these metrics to improve:
| Metric | Good | Needs Improvement |
|---|---|---|
| AI Success Rate | >90% | <70% |
| Revision Requests | <2 | >3 |
| Time to Merge | <4 hours | >1 day |
The ROI of Good Tickets
Investment: 10-15 extra minutes per ticket Return:
- Higher first-pass success rate
- Fewer revision cycles
- Better code quality
- Faster time-to-merge
Ready to ship faster? Start with Afelyon and see how great tickets become great PRs.
Related: