LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Feature]: Add first-class Prompt asset registry and Jinja2 dynamic templating

Open iamvince opened this issue 1 week ago • 2 comments

Problem

Currently in LoopForge:

  1. Prompts are anonymous strings embedded inside Agent definitions (agent.prompt). There is no standalone "Prompt" asset in the catalog (unlike rules, skills, sandboxes, and mcp_servers).
  2. If multiple agents or SOP nodes share similar system prompts, formatting conventions, or evaluation criteria, users must duplicate the prompt text across multiple roles.
  3. When a prompt is updated, users must manually search for and update every agent using it. There is no independent revision history, rollback, or versioning for prompts.
  4. Templating is restricted to basic static placeholder replacement (e.g. {{input}}, {{repository}}). There is no support for conditionals ({% if ... %}), iterations over upstream artifacts, default fallbacks, or rich structured context injection.

Proposed behavior

A. Database Schema

Add prompts and prompt_revisions tables matching the existing rules and workflows pattern:

CREATE TABLE IF NOT EXISTS prompts (
    id VARCHAR(64) PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description TEXT,
    template LONGTEXT NOT NULL,
    variables JSON,
    project_id VARCHAR(64),
    shared BOOLEAN DEFAULT FALSE,
    revision INT DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_prompts_project (project_id),
    INDEX idx_prompts_shared (shared)
);

CREATE TABLE IF NOT EXISTS prompt_revisions (
    id VARCHAR(64) PRIMARY KEY,
    prompt_id VARCHAR(64) NOT NULL,
    revision INT NOT NULL,
    payload JSON NOT NULL,
    created_by BIGINT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_prompt_revisions_lookup (prompt_id, revision)
);

B. REST API & MCP Operations

Register the following endpoints in internal/application/operations.go and internal/httpapi/catalog.go:

Operation Name Method Path Description
prompts_list GET /api/prompts List managed prompt assets (supports projectId & shared filters).
prompts_save PUT /api/prompts Create or update a prompt asset and record a revision snapshot.
prompts_delete DELETE /api/prompts/:id Delete an unused prompt asset not referenced by active agents.
prompts_revisions_list GET /api/prompts/:id/revisions List revision history of a prompt.
prompts_revision_restore POST /api/prompts/:id/revisions/:rev/restore Restore a historical prompt revision.

C. Agent Definition Schema Integration

In internal/domain/agent.go, extend AgentDefinition to support referencing a catalog prompt while maintaining full backwards compatibility for inline prompts:

type AgentDefinition struct {
    ID          string     `json:"id"`
    Name        string     `json:"name"`
    ExecutorID  string     `json:"executorId"`
    Rules       []string   `json:"rules"`
    Skills      []string   `json:"skills"`
    MCPServers  []string   `json:"mcpServers"`
    Prompt      string     `json:"prompt,omitempty"`    // Backwards-compatible inline prompt
    PromptRef   *PromptRef `json:"promptRef,omitempty"` // Reference to managed prompt asset
}

type PromptRef struct {
    ID       string `json:"id"`
    Revision int    `json:"revision,omitempty"` // 0 or omitted = latest published revision
}

D. UI Integration in Web Console

  1. Add a dedicated Prompts (提示词) tab under Capability Assets (能力资产) alongside MCP, Rules (规则), and Skills (技能):
    • Backed by /api/prompts and DB tables prompts and prompt_revisions.
    • Users can create, edit, version, and roll back prompt assets independently.
  2. In the Agent Editor (/api/agents), allow agents to either:
    • Provide an inline prompt (legacy backwards-compatible behavior), OR
    • Select a managed prompt from the catalog (promptRef: { id: "system-architect-base", version: "latest" }).

E. Dynamic Templating (Jinja2 / Go Template Syntax)

Support expressive dynamic evaluation at node dispatch time in internal/runtime:

  1. Conditionals:
{% if repository.has_tests %}
Run existing project test suite: {{ repository.test_command }}
{% else %}
Scaffold a new test suite based on requirement: {{ input }}
{% endif %}
  1. Artifact Iteration:
{% for name, content in artifacts.items() %}
### Upstream Artifact: {{ name }}
{{ content }}
{% endfor %}
  1. Structured Context Injection: Expose task.*, repository.*, workflow.*, node.*, and artifacts.* directly to the template evaluation context.

Scope

Platform — workflows / collaboration

Maintenance & Quality Impact

Without native catalog support, teams are forced to copy-paste prompts across multiple SOP roles and chat agents. This causes prompt drift, inconsistent outputs across workflows, and high maintenance overhead when refining prompt engineering guidelines across a project.

Checks

  • [x] This proposal does not require organization-specific infrastructure or credentials.
  • [x] I searched existing issues and discussions for similar proposals.

iamvince avatar Nov 25 '26 03:11 iamvince

Thank you for the proposal. I understand this as a request for a first-class Prompt asset, with its own revision history, so shared prompt text is not copied into every agent, plus Jinja2-style conditionals and loops rather than only static placeholders.

We've seen this and will look at it along with the existing issue queue.

cocofhu00 avatar Nov 25 '26 04:11 cocofhu00

Any update ?

iamvince avatar Nov 30 '26 21:11 iamvince