AI Agent Prompt

About Prompt

  • Prompt Type – Dynamic
  • Prompt Platform – ChatGPT, Grok, Deepseek, Gemini, Copilot, Midjourney, Meta AI and more
  • Niche – Code Generation
  • Language – English
  • Category – Coding
  • Prompt Title – AI Agent Prompt

Prompt Details

## Dynamic AI Prompt for Code Generation (All Platforms)

This prompt is designed to be highly adaptable for various code generation tasks across different AI platforms. It emphasizes clarity, specificity, and modularity, allowing users to easily customize it for their unique needs. It leverages best practices like providing clear instructions, defining the desired output format, and incorporating optional parameters for fine-tuning.

**Core Prompt:**

“`
Generate code in {{programming_language}} that implements {{task_description}}.

Desired Functionality:
{{detailed_functional_description}}

Input Parameters:
{{input_parameters_and_types}}

Output:
{{expected_output_format_and_type}}

Code Style Guidelines:
{{coding_style_preferences}}

Optional Parameters:
* Target Platform: {{target_platform}} (e.g., Web, Mobile, Desktop)
* Framework/Library: {{framework_library}} (e.g., React, Angular, .NET)
* Performance Considerations: {{performance_requirements}} (e.g., Optimize for speed, memory efficiency)
* Error Handling: {{error_handling_requirements}} (e.g., Include try-catch blocks, specific exception handling)
* Code Comments: {{code_comments_level}} (e.g., Detailed explanations, minimal comments, docstrings)
* Test Cases: {{test_cases_required}} (e.g., Provide unit tests, integration tests)
* Code Example: {{code_example}} (Provide a code snippet illustrating a specific aspect or partial solution)

“`

**Example Usage and Customization:**

**1. Generating a Python function to calculate the factorial of a number:**

“`
Generate code in Python that implements a function to calculate the factorial of a non-negative integer.

Desired Functionality:
The function should take a non-negative integer as input and return its factorial. If the input is negative, it should raise a ValueError.

Input Parameters:
n (integer)

Output:
An integer representing the factorial of n.

Code Style Guidelines:
PEP 8 compliant.

Optional Parameters:
* Error Handling: Include a try-except block to handle negative input.
* Code Comments: Include docstrings explaining the function’s purpose, parameters, and return value.
* Test Cases: Provide three unit tests: one for a positive input, one for zero, and one for a negative input.
“`

**2. Generating JavaScript code for a React component:**

“`
Generate code in JavaScript that implements a React component for displaying a list of items.

Desired Functionality:
The component should receive an array of strings as props and render each string as a list item within an unordered list.

Input Parameters:
items (array of strings)

Output:
A React component rendering an unordered list with the given items.

Code Style Guidelines:
Use functional components with hooks.

Optional Parameters:
* Framework/Library: React
* Code Comments: Include JSDoc style comments.
* Code Example: `

  • {item}

` (Illustrating the basic list structure)
“`

**3. Generating Java code for a data access object:**

“`
Generate code in Java that implements a Data Access Object (DAO) for interacting with a MySQL database table called “users”.

Desired Functionality:
The DAO should provide methods for creating, reading, updating, and deleting user records.

Input Parameters:
Connection object to the MySQL database.

Output:
A Java class implementing the DAO interface.

Code Style Guidelines:
Use camelCase for variable and method names.

Optional Parameters:
* Target Platform: Desktop
* Framework/Library: Spring JDBC Template
* Error Handling: Throw appropriate exceptions for database errors.
* Code Comments: Include Javadoc style comments.
“`

**Explanation and Best Practices:**

* **Dynamic Structure:** The modular design allows easy customization for different coding tasks by simply filling in the placeholders.
* **Clear Instructions:** The prompt clearly defines the task and the expected outcome.
* **Specific Details:** Providing input parameters, output format, and coding style preferences ensures the generated code aligns with the user’s requirements.
* **Optional Parameters:** These offer fine-grained control over the generated code, addressing platform-specific requirements, performance considerations, and testing needs.
* **Example Code Snippets:** Including example code can guide the AI and enhance the accuracy of the generated code, especially for complex tasks.
* **Cross-Platform Compatibility:** The prompt’s structure is designed to be generally applicable across different AI code generation platforms. However, minor adjustments might be needed based on the specific platform’s capabilities and limitations.

By using this dynamic prompt template and tailoring it to your specific needs, you can effectively leverage AI for efficient and accurate code generation. Remember to experiment and iterate to achieve optimal results.