keepcalculator

06 Numbers and Powers

How to Get Better Results from AI Coding Agents

Card No. 06·42288 · Updated · Standard formula, shown below

AI coding agents can write code, fix bugs, and refactor projects, but their output is only as good as the context and instructions you provide. This guide shows you how to teach an AI agent your codebase, preferences, and workflow so it produces more accurate, maintainable, and useful results. You’ll learn practical techniques for writing effective prompts, providing relevant context, and iterating on the agent’s output.

What You’ll Need

  • Access to an AI coding agent (e.g., GitHub Copilot, Cursor, Codeium, or similar).
  • A code editor or IDE that supports your chosen agent.
  • A project or codebase you want the agent to work on.
  • Basic familiarity with your project’s structure and goals.

Step-by-Step

  1. Start with a clear, specific task. Instead of “fix this bug,” say “The login form throws a 500 error when the email field is empty. Find the validation logic in auth.js and add a check that returns a friendly error message before the request is sent.” The more precise you are about the file, the function, and the expected behavior, the better the agent can target its response.
  2. Provide relevant context in your prompt. Paste the relevant code snippet, describe the surrounding architecture, or mention which files are involved. For example: “Here’s the current handleSubmit function in components/Login.js. It calls the API but doesn’t handle the loading state. Add a loading spinner that shows while the request is pending and disables the submit button.”
  3. Specify the tech stack and conventions. Tell the agent which framework, language version, or styling approach you’re using. For instance: “Use React 18 with hooks, TypeScript, and Tailwind CSS. Follow the existing naming conventions in this project (camelCase for variables, PascalCase for components).” This prevents the agent from suggesting incompatible or inconsistent code.
  4. Break large tasks into smaller steps. If you need a whole feature, ask for it in pieces. First: “Create a new API endpoint in routes/users.js that fetches a user by ID.” Then: “Add validation to that endpoint to ensure the ID is a positive integer.” Then: “Write a unit test for the endpoint using Jest.” Each step gives the agent a focused goal and lets you review progress.
  5. Use examples in your prompts. Show the agent what “good” looks like. For example: “Here’s an example of a well-structured component from our codebase: [paste code]. Write a similar component for a product card that displays name, price, and an ‘Add to Cart’ button.” Examples are powerful because they encode your style and expectations.
  6. Ask for explanations, not just code. When the agent suggests a solution, ask “Why did you choose this approach?” or “Can you explain how this code works?” This helps you understand the reasoning and catch potential issues. It also teaches the agent to think more carefully about its suggestions.
  7. Iterate and refine based on feedback. If the output isn’t perfect, don’t just accept it. Give specific feedback: “The function works, but the error handling is too generic. Add specific messages for network errors vs. server errors.” The agent will adjust its response. Over time, this back-and-forth trains the agent to match your preferences.
  8. Feed the agent your project’s documentation. If you have a README, coding standards, or architecture docs, paste relevant sections into the prompt. For example: “Here’s our contribution guide: [paste]. Make sure the new code follows the style guide.” This gives the agent a reference point.
  9. Use the agent to generate tests and documentation. Ask it to “Write unit tests for the calculateTotal function” or “Add JSDoc comments to the new module.” This not only produces useful artifacts but also reinforces the agent’s understanding of your codebase.
  10. Review and verify everything. Never blindly trust the agent’s output. Run the code, check for edge cases, and ensure it integrates with the rest of your project. The agent is a tool, not a replacement for your judgment.

Common Mistakes

  • Being too vague. “Help me with my code” gives the agent no direction. Always specify the task, the file, and the desired outcome.
  • Ignoring the agent’s questions. Many agents ask clarifying questions. If you skip them, you’ll get a generic answer. Take the time to answer.
  • Not providing enough context. The agent can’t see your whole project unless you tell it. Paste relevant code and describe the surrounding system.
  • Expecting the agent to know your conventions. Unless you tell it, the agent will guess. Explicitly state your naming, formatting, and architectural preferences.
  • Accepting the first answer. The first suggestion is often a starting point, not the final solution. Iterate until it meets your needs.
  • Forgetting to test. The agent doesn’t run your tests. You must verify that the code works in your environment.

Tips

  • Create a project context file. Write a short document describing your project’s structure, tech stack, and coding conventions. Paste it into the chat when starting a new session.
  • Use the agent’s built-in context features. Some agents let you “add files” or “@mention” specific files. Use these to give the agent direct access to relevant code.
  • Ask for alternatives. “Can you show me a different way to implement this?” or “What are the trade-offs of using a class vs. a function?” This broadens your perspective.
  • Teach by example. When you correct the agent, explain why. “I prefer early returns because they reduce nesting.” The agent will learn from that feedback.
  • Keep a repository of good prompts. Save prompts that worked well and reuse them for similar tasks.

Troubleshooting

If the agent consistently gives poor results, try the following:

  • Check your prompt clarity. Re-read your request. Is it ambiguous? Rewrite it with more specific details.
  • Provide more context. The agent may not understand the bigger picture. Paste more code, describe the data flow, or explain the expected behavior.
  • Simplify the task. Break it down into smaller pieces. A complex request can overwhelm the agent.
  • Restart the conversation. If the agent seems stuck on a wrong path, start a new chat with a fresh prompt that includes all the necessary context.
  • Check for outdated information. If the agent suggests deprecated APIs or libraries, it may be using outdated training data. Specify the versions you’re using.
  • Use a different agent. Different agents have different strengths. If one isn’t working, try another.

Frequently Asked Questions

  1. How much context should I give the agent? Give as much as needed to understand the task, but avoid dumping entire files unless they’re directly relevant. A few key snippets and a description of the surrounding code usually suffice.
  2. Can the agent learn my codebase over time? Some agents can remember preferences within a session, but most don’t persist across sessions. You’ll need to re-provide context each time.
  3. What if the agent produces insecure code? Always review for security issues. Ask the agent to “check for SQL injection” or “use parameterized queries” explicitly. Never assume the agent’s code is safe.
  4. Should I let the agent write entire files? It can be helpful for boilerplate, but for complex logic, it’s better to have the agent generate functions or components that you integrate yourself.
  5. How do I get the agent to follow my style guide? Paste the relevant style rules into the prompt. For example: “Use 2-space indentation, single quotes, and no semicolons.”
  6. Is it worth the time to teach the agent? Yes, especially if you work on the same project regularly. The upfront effort pays off in faster, more accurate assistance.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →