Skip to content

Conversation

@stevei101
Copy link
Collaborator

Implement Prompt Vault Intelligence (FR#201) by integrating an AI Suggestion Agent to provide prompt optimization, structured output schemas, and function calling hints.


Open in Cursor Open in Web

Integrates AI-driven prompt suggestions via a new Suggestion Agent.

Co-authored-by: s73ven.1rvin <s73ven.1rvin@gmail.com>
@cursor
Copy link

cursor bot commented Nov 6, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@curiousstevenintx curiousstevenintx added the bug Something isn't working label Nov 7, 2025
@stevei101
Copy link
Collaborator Author

stevei101 commented Nov 7, 2025

@copilot this needs to be patched with the backend python fix in this branch fix/backend-test-failures-pr169 that was merged in #236. Cherry pick the fixes into your branch, get checks passing. Then squash, and merge. This is the same patch that needs to be applied to PR #246

Copy link
Contributor

Copilot AI commented Nov 7, 2025

@stevei101 I've opened a new pull request, #252, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements FR#201 - Prompt Vault Intelligence, which integrates AI-driven prompt analysis capabilities from the agentnav backend into the Prompt Vault application. The feature introduces a new Suggestion Agent that analyzes prompts using Google's Gemini AI and provides optimization suggestions, structured output schemas, function calling hints, and quality scoring.

Key changes:

  • New Suggestion Agent backend service with ADK/A2A Protocol integration
  • RESTful API endpoints for prompt analysis, health checks, and examples
  • TypeScript frontend service and React component for seamless integration
  • Comprehensive test suite achieving 70%+ coverage requirement
  • Detailed documentation including integration guide, deployment checklist, and quick reference

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
backend/agents/suggestion_agent.py New ADK-based agent implementing prompt analysis logic with Gemini AI integration and A2A Protocol communication
backend/routes/suggestion_routes.py REST API endpoints for analyze, health check, and examples with error handling
backend/models/suggestion_models.py Pydantic models for request/response validation with structured schemas and type safety
backend/models/__init__.py Updated exports to include new suggestion models
backend/agents/__init__.py Added SuggestionAgent to agent registry exports
backend/main.py Integrated suggestion routes into FastAPI application
backend/tests/test_suggestion_agent.py Comprehensive test suite covering agent core, parsing, API endpoints, models, and integration
services/suggestionService.ts TypeScript client service for calling Suggestion Agent API from frontend
components/PromptSuggestions.tsx React component with UI for displaying suggestions, quality scores, and interactive features
docs/FR201_PROMPT_VAULT_INTEGRATION.md Complete integration guide with architecture, examples, and troubleshooting
FR201_QUICK_REFERENCE.md Quick reference card for developers with common usage patterns
FR201_DEPLOYMENT_CHECKLIST.md Comprehensive deployment checklist with verification steps and monitoring setup


## Related Documentation

- [FR#201 Feature Request](../FR029_IMPLEMENTATION_SUMMARY.md)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references an incorrect feature request number. Line 488 links to "FR029_IMPLEMENTATION_SUMMARY.md" but should link to "FR201_IMPLEMENTATION_SUMMARY.md" to match the current feature request (FR#201).

Suggested change
- [FR#201 Feature Request](../FR029_IMPLEMENTATION_SUMMARY.md)
- [FR#201 Feature Request](../FR201_IMPLEMENTATION_SUMMARY.md)

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +65
# Create A2A Protocol instance for agent communication
a2a = A2AProtocol()

# Initialize Suggestion Agent
suggestion_agent = SuggestionAgent(a2a)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent creates a new A2A Protocol instance for each request, which may cause issues with shared state or message routing. In line 62, a new A2AProtocol() is created, and in line 65, a new SuggestionAgent(a2a) is instantiated. Consider whether these instances should be singleton or reused across requests to maintain consistent A2A communication channels with other agents.

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +99
def _get_prompt_template(self) -> str:
"""Get prompt template for suggestion analysis"""
if self._prompt_template:
return self._prompt_template

try:
from services.prompt_loader import get_prompt

self._prompt_template = get_prompt("suggestion_agent_system_instruction")
logger.info("✅ Loaded suggestion agent prompt from Firestore")
return self._prompt_template
except Exception as e:
logger.warning(f"⚠️ Could not load prompt from Firestore: {e}")
# Fallback prompt
self._prompt_template = """
You are the Suggestion Agent, an expert in prompt engineering and optimization.

Your task is to analyze user prompts and provide intelligent suggestions for improvement.

Analyze the following prompt and provide:

1. OPTIMIZATION SUGGESTIONS:
- Clarity improvements (more specific instructions, better structure)
- Constraint additions (output format, length, style requirements)
- Example additions (few-shot learning opportunities)
- Context enhancements (background information that would help)

2. STRUCTURED OUTPUT SUGGESTION:
- If the prompt expects structured data, suggest a JSON schema
- Include field names, types, descriptions, and constraints
- Ensure schema is compatible with Gemini's structured output format

3. FUNCTION CALLING HINT:
- Identify if the task could benefit from tool/function calling
- Suggest function definitions with parameters and descriptions
- Explain when and why function calling would be beneficial

4. PROMPT QUALITY SCORE:
- Rate the prompt quality (1-10)
- Identify strengths and weaknesses
- Provide specific actionable improvements

Format your response as:

OPTIMIZATION_SUGGESTIONS:
[List 3-5 specific suggestions for improving the prompt]

STRUCTURED_OUTPUT_SCHEMA:
[JSON schema if applicable, or "NOT_APPLICABLE"]

FUNCTION_CALLING_HINT:
[Function definition if applicable, or "NOT_APPLICABLE"]

QUALITY_SCORE: [1-10]
STRENGTHS: [List strengths]
WEAKNESSES: [List weaknesses]
ACTIONABLE_IMPROVEMENTS: [List specific improvements]

Prompt to analyze:
{prompt_text}
"""
return self._prompt_template
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential performance issue: The _get_prompt_template() method attempts to load from Firestore on every call before caching. While the result is cached after the first successful load, the try-except block for Firestore loading should ideally happen only once during initialization rather than on every template access. Consider moving this to __init__ or using a lazy-loaded property pattern to avoid repeated exception handling.

Copilot uses AI. Check for mistakes.

---

**Implementation Complete:** 2025-11-06
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation date "November 6, 2025" appears inconsistent. The current review is happening in November 2025, which would mean this feature is being implemented on the current date. This should likely be a past date (e.g., early 2025) or should be updated to reflect the actual implementation completion date.

Suggested change
**Implementation Complete:** 2025-11-06
**Implementation Complete:** 2025-03-15

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +110
const errorData: SuggestionError = await response.json();
throw new Error(errorData.message || `API error: ${response.status}`);
}

const data: PromptSuggestionResponse = await response.json();
return data;
} catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to analyze prompt: ${error.message}`);
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling logic wraps the original error message, potentially losing information. When response.json() fails (line 102), the error is caught at line 108 and wrapped again at line 110, resulting in a message like "Failed to analyze prompt: API error: 500" which loses the original errorData.message. Consider handling JSON parsing errors separately or checking response.ok before attempting to parse JSON.

Suggested change
const errorData: SuggestionError = await response.json();
throw new Error(errorData.message || `API error: ${response.status}`);
}
const data: PromptSuggestionResponse = await response.json();
return data;
} catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to analyze prompt: ${error.message}`);
// Try to parse error response as JSON, but handle parsing errors gracefully
let errorMessage = `API error: ${response.status}`;
try {
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
const errorData: SuggestionError = await response.json();
errorMessage = errorData.message || errorMessage;
} else {
// If not JSON, try to get text
const errorText = await response.text();
if (errorText) {
errorMessage += ` - ${errorText}`;
}
}
} catch (jsonError) {
// If JSON parsing fails, try to get text
try {
const errorText = await response.text();
if (errorText) {
errorMessage += ` - ${errorText}`;
}
} catch {
// Ignore, use default errorMessage
}
}
throw new Error(errorMessage);
}
// Parse success response, handle JSON errors
try {
const data: PromptSuggestionResponse = await response.json();
return data;
} catch (jsonError) {
throw new Error(`Failed to parse suggestion response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
}
} catch (error) {
// Do not wrap error, just propagate with full message
if (error instanceof Error) {
throw error;

Copilot uses AI. Check for mistakes.

**Feature Status:** ✅ Implemented
**Priority:** High (Product Value / Architectural Synthesis)
**Implementation Date:** 2025-11-06
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation date "2025-11-06" appears to be incorrect as the current date (per system knowledge cutoff) would be in November 2025, but this date format suggests November 6, 2025. This should likely be "2025-01-06" (January 6, 2025) or the actual implementation date should be verified.

Suggested change
**Implementation Date:** 2025-11-06
**Implementation Date:** 2025-01-06

Copilot uses AI. Check for mistakes.
Comment on lines +211 to +232
quality_score = 5
if word_count > 50:
quality_score += 1
if has_examples:
quality_score += 2
if has_constraints:
quality_score += 1

return f"""
OPTIMIZATION_SUGGESTIONS:
{chr(10).join(f"- {s}" for s in suggestions)}

STRUCTURED_OUTPUT_SCHEMA:
NOT_APPLICABLE

FUNCTION_CALLING_HINT:
NOT_APPLICABLE

QUALITY_SCORE: {quality_score}
STRENGTHS: Basic prompt structure
WEAKNESSES: Limited detail and constraints
ACTIONABLE_IMPROVEMENTS: Add more specific instructions and examples
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quality score calculation in the fallback analysis may produce scores outside the valid range. The base score starts at 5 and can be incremented by up to 4 points (1 + 2 + 1), resulting in a maximum of 9. However, there's no lower bound check, and if the conditions aren't met, it stays at 5. Consider adding validation to ensure the score always falls within the documented 1-10 range, or adjust the calculation to use the full range.

Copilot uses AI. Check for mistakes.

**Deployment Status:** 🟢 Ready for Production

**Last Updated:** November 6, 2025
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation date "November 6, 2025" appears to be in the future or current date (since the current date is November 2025). This should be updated to reflect the actual implementation date if this PR has already been completed, or use a placeholder like "TBD" if it's still in progress.

Suggested change
**Last Updated:** November 6, 2025
**Last Updated:** TBD

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +20
PromptSuggestionError,
)

Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'PromptSuggestionError' is not used.

Suggested change
PromptSuggestionError,
)
)

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +16
import json

Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'json' is not used.

Suggested change
import json

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants