Skip to content

feat(api): AI services backend — refine prompt tool call#3687

Open
mmabrouk wants to merge 24 commits intomainfrom
feat/refine-ai-feature
Open

feat(api): AI services backend — refine prompt tool call#3687
mmabrouk wants to merge 24 commits intomainfrom
feat/refine-ai-feature

Conversation

@mmabrouk
Copy link
Member

@mmabrouk mmabrouk commented Feb 9, 2026

Summary

  • Adds an MCP-shaped REST API for AI tool calls under /ai/services
  • Implements the first tool: tools.agenta.api.refine_prompt
  • Calls an internal deployed cloud prompt (/services/completion/run) and returns validated structured output (messages, summary)

Endpoints

Method Path Description
GET /ai/services/status Returns enabled flag + available tools
POST /ai/services/tools/call Executes a tool call

What Changed (latest)

  • Switched endpoint prefix from /preview/ai/services to /ai/services across backend router wiring, EE entitlements category mapping, web client calls, and docs
  • Replaced tuple/error-dict client returns with typed DTO + domain exceptions
  • Moved unknown-tool validation into service dispatcher (AIServicesUnknownToolError) and mapped at router boundary
  • Moved AI services throttling to EE entitlements middleware (Category.AI_SERVICES) and removed OSS inline router throttle
  • Updated env var naming to:
    • AGENTA_AI_SERVICES_ENVIRONMENT_SLUG
    • AGENTA_AI_SERVICES_REFINE_PROMPT_KEY
  • Updated docs/specs to match code behavior, including __ag_* cloud input keys

Notes

  • AI services are env-gated: when disabled, status returns enabled: false and tool call returns 503
  • Org-level owner feature flag for AI services is planned (TODO in router)

Open with Devin

Implement the backend for Chapter 1 of the AI services feature:
- REST API with MCP-shaped tool-call contract at /preview/ai/services/
- Single tool: tools.agenta.api.refine_prompt
- Thin HTTP client calling deployed prompt in internal Agenta org
- EE permission check (EDIT_WORKFLOWS) and rate limiting
- Input/output validation for prompt templates
- Design docs with spec, plan, context, and research
@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Feb 14, 2026 7:30am

Request Review

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

The design reference doc used 'prompt_text' as the input key while the
service code, DTOs, spec, and input schema all use 'prompt_template_json'.
Align the doc to match.
…ment

Two-panel modal (Instructions + Preview) integrated into the Playground:
- Left panel: @ant-design/x Sender + Prompts for guidelines input with chat-like display
- Right panel: Editable refined messages with JSON diff toggle
- Backend output schema simplified: messages + summary (removed redundant refined_prompt)
- Preserves original template_format through refinement (only messages are changed)
- Keyboard shortcut (Cmd/Ctrl+Enter), accessibility (aria-labels, focus management)
- Magic wand icon on prompt header with AI services availability check
@mmabrouk mmabrouk requested a review from jp-agenta February 10, 2026 18:16
@mmabrouk mmabrouk marked this pull request as ready for review February 10, 2026 18:16
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Backend labels Feb 10, 2026
Remove empty __init__.py file in ai_services module
Removed the docstring for the AI Services core module.
Copy link
Member

@jp-agenta jp-agenta left a comment

Choose a reason for hiding this comment

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

This is 🔥, @mmabrouk !
lgtm

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants