Skip to content

Code Duplication & Maintainability Problems in Prompt Generators #16

@codeMaestro78

Description

@codeMaestro78

The current implementation of generate_mcp_system_prompt, generate_no_mcp_system_prompt, generate_agent_specific_system_prompt, and generate_agent_summarize_prompt contains extensive code duplication. Large blocks of boilerplate text are repeated across functions, making it difficult to maintain and extend. Adding a new agent type or modifying instructions requires editing multiple places in the code.

Problems Identified:

Repetition of Long Strings:

Many identical or near-identical text blocks (e.g., cautionary instructions, task strategies) are repeated across functions.

Hard to update consistently.

Scalability Issue:

Adding new agent types requires modifying multiple if/elif branches instead of a single mapping/dictionary.

High risk of introducing inconsistencies.

Poor Separation of Concerns:

Long instructional strings are hardcoded in Python functions rather than stored in reusable constants, templates, or even external files.

Readability & Maintainability:

Lack of type hints and docstrings reduces clarity.

JSON schemas for tools are dumped inline, which can reduce readability when large.

Suggested Improvements:

Refactor into reusable templates:
Use base templates and format with variables instead of repeating blocks.

Use dictionary mappings instead of long if/elif:
Map agent types (main, agent-browsing, etc.) to their specific template text.

Extract long instructional text into constants or Markdown template files:
Keep Python code lean and focused on logic, not large strings.

Pretty-print JSON schemas with json.dumps(..., indent=2):
For readability.

Add type hints & docstrings:
Improve IDE support and maintainability.

Improve error handling:
When raising ValueError, list available agent types to help debugging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions