Skip to content

✨Feat:Enhance prompt optimization by integrating openjiuwen and fix related bugs#3190

Open
DongJiBao2001 wants to merge 26 commits into
developfrom
djb_feat_promp_optim
Open

✨Feat:Enhance prompt optimization by integrating openjiuwen and fix related bugs#3190
DongJiBao2001 wants to merge 26 commits into
developfrom
djb_feat_promp_optim

Conversation

@DongJiBao2001
Copy link
Copy Markdown
Contributor

@DongJiBao2001 DongJiBao2001 commented Jun 4, 2026

Integrated Openjiuwen's prompt optimization feature: supports fine-grained adjustments including global optimization, insertion optimization, replacement optimization, and feedback-based optimization using bad cases on the agent debugging page . #3187
img_v3_02125_0d654403-88f1-47dd-9eb5-7bbec1ab204g
img_v3_02125_8695ab0c-2dbd-4cce-88b1-23c141e7c2eg
img_v3_02125_e2df0e3a-d6e4-472a-b181-7d02bfeba6fg
img_v3_0212b_41a66a96-2da6-49c1-9f23-02c555f83ccg

Copilot AI review requested due to automatic review settings June 4, 2026 02:11
except NexentCapabilityError as e:
return JSONResponse(
status_code=HTTPStatus.BAD_REQUEST,
content={"message": str(e)},
except NexentCapabilityError as e:
return JSONResponse(
status_code=HTTPStatus.BAD_REQUEST,
content={"message": str(e)},
except NexentCapabilityError as e:
return JSONResponse(
status_code=HTTPStatus.BAD_REQUEST,
content={"message": str(e)},
Copy link
Copy Markdown
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 integrates OpenJiuwen-based prompt optimization into Nexent, exposing fine-grained optimization modes (global/insert/replace/feedback via bad cases) through new backend APIs and updated frontend UX, and aligns the runtime/tooling stack to Python 3.11 plus newer MCP/FastMCP versions.

Changes:

  • Add a unified backend PromptOptimizationService that uses Jiuwen SDK when available and falls back to Nexent’s native optimizer where supported.
  • Add new prompt optimization endpoints (/prompt/optimize, /prompt/optimize/badcase, /prompt/optimize/from_debug) and update frontend types/UI to support mode-based optimization and agent-debug “optimize from reply”.
  • Upgrade Python/runtime and dependency baselines (Python 3.11 images/workflows; fastmcp/mcp version bumps; introduce openjiuwen).

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/backend/services/test_prompt_service.py Adds unit tests for the new optimization service (Jiuwen vs Nexent fallback).
test/backend/app/test_prompt_app.py Updates API tests to mock PromptOptimizationService and cover new endpoints.
sdk/pyproject.toml Bumps mcp/fastmcp dependency ranges for the SDK package.
make/mcp/Dockerfile Moves MCP image base to Python 3.11 and adjusts shell strict-mode usage.
make/main/Dockerfile Moves main image base to Python 3.11.
make/data_process/Dockerfile Moves data_process image base to Python 3.11 and installs SDK extras.
frontend/types/agentConfig.ts Extends prompt optimization request types with mode/positions; adds badcase request/response types.
frontend/services/promptService.ts Keeps /prompt/optimize client; removes badcase client function (commented as automated elsewhere).
frontend/public/locales/zh/common.json Adds i18n strings for prompt optimization and compare UX (ZH).
frontend/public/locales/en/common.json Adds i18n strings for prompt optimization and compare UX (EN).
frontend/pnpm-workspace.yaml Updates pnpm workspace build-related configuration.
frontend/app/[locale]/agents/components/agentInfo/PromptTemplateManagerModal.tsx Defers form initialization to avoid modal mount timing issues; switches modal destroy behavior.
frontend/app/[locale]/agents/components/agentInfo/PromptOptimizeModal.tsx Adds mode selection + insert/select position handling and richer before/after UI.
frontend/app/[locale]/agents/components/agentInfo/DebugPromptCompareModal.tsx New modal for comparing original vs optimized full prompts.
frontend/app/[locale]/agents/components/agentInfo/DebugOptimizeModal.tsx New modal to optimize full system prompt from agent-debug selected reply.
frontend/app/[locale]/agents/components/agentInfo/DebugMessageList.tsx Adds “optimize this reply” action wiring from assistant messages.
frontend/app/[locale]/agents/components/agentInfo/DebugConfig.tsx Integrates new debug optimization flow and applies optimized full prompt back into agent config.
frontend/app/[locale]/agents/components/agentInfo/AgentGenerateDetail.tsx Adjusts optimized-content apply handler to target the correct section fields.
backend/services/prompt_service.py Implements PromptOptimizationService, request/result dataclasses, and Jiuwen/Nexent fallback logic.
backend/pyproject.toml Bumps required Python to 3.11, adds openjiuwen, updates dependencies, and adds uv exclusions.
backend/mcp_service.py Updates FastMCP .mount() call signatures to match newer FastMCP API expectations.
backend/consts/model.py Extends optimize request model with mode/start/end and adds badcase + debug optimization request models.
backend/consts/const.py Adds ENABLE_JIUWEN_SDK env flag.
backend/apps/prompt_app.py Reworks /prompt/optimize to use the new service and adds badcase/from_debug routes with headers.
backend/apps/app_factory.py Adds global handling for NexentCapabilityError as HTTP 400.
backend/adapters/jiuwen_sdk_adapter.py New adapter providing lazy/robust SDK import and feedback/badcase optimization entry points.
backend/adapters/exception.py New adapter exception types for Jiuwen and Nexent capability signaling.
backend/adapters/init.py Exposes adapter symbols and safely imports JiuwenSDKAdapter.
.github/workflows/sdk_publish.yml Updates workflow Python to 3.11.
.github/workflows/auto-unit-test.yml Updates workflow Python to 3.11.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +98 to +101
assert response.status_code == 200
assert call_args[0][0].mode == "insert"
assert call_args[0][0].start_pos == 10
assert call_args[0][0].end_pos == 20
Comment on lines +2072 to +2074
@patch('backend.services.prompt_service.optimize_prompt_section_impl')
@patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', False)
def test_optimize_nexent_fallback_general_mode(self, mock_impl):
Comment on lines +2144 to +2149
from consts.const import ENABLE_JIUWEN_SDK

# Patch ENABLE_JIUWEN_SDK to False
with patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', False):
service = PromptOptimizationService(model_id=1, tenant_id="t", language="zh")
self.assertFalse(service.is_jiuwen_mode_available())
Comment on lines +2151 to +2171
@patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', True)
@patch('backend.services.prompt_service.sys.modules', {'openjiuwen': MagicMock()} if False else {})
def test_is_jiuwen_mode_available_openjiuwen_missing(self):
"""openjiuwen 未安装时 Jiuwen SDK 不可用"""
import sys
saved = sys.modules.copy()

# Simulate openjiuwen not installed
def fake_import(name, *args, **kwargs):
if name == 'openjiuwen':
raise ModuleNotFoundError("No module named 'openjiuwen'")
return saved.get(name)

with patch.dict('sys.modules', {'openjiuwen': None}):
service = PromptOptimizationService(model_id=1, tenant_id="t", language="zh")
# Mock ENABLE_JIUWEN_SDK to True
with patch('backend.services.prompt_service.ENABLE_JIUWEN_SDK', True):
with patch('builtins.__import__', side_effect=fake_import):
# We need to actually trigger the import check
# Patch at the point where the check happens
pass # skip - import already happened at module load
Comment thread backend/services/prompt_service.py Outdated
Comment on lines +900 to +912
def is_jiuwen_mode_available(self) -> bool:
"""判断 Jiuwen SDK 模式是否可用"""
from consts.const import ENABLE_JIUWEN_SDK

if not ENABLE_JIUWEN_SDK:
return False

try:
import openjiuwen # noqa: F401
except ImportError:
return False

return True
Comment thread backend/services/prompt_service.py Outdated
Comment on lines +34 to +38
from dataclasses import dataclass, field
from typing import Optional as Opt

from adapters.exception import JiuwenSDKError, NexentCapabilityError
from adapters.jiuwen_sdk_adapter import JiuwenSDKAdapter
Comment thread backend/pyproject.toml
Comment on lines 26 to +30
"scikit-learn>=1.0.0",
"numpy>=1.24.0",
"openjiuwen>=0.1.0",
"pydantic-settings>=2.0.0",
]
Comment on lines +320 to 325
{/* Submit Button */}
<div className="flex justify-end">
<Button
type="primary"
onClick={handleOptimize}
loading={isOptimizing}
>
<Button type="primary" onClick={handleOptimize}>
{t("systemPrompt.optimize.submit")}
</Button>
</div>
… test coverage for prompt optimization service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants