Skip to content

Commit a02bb88

Browse files
authored
feat: support custom prompt (#1441)
* feat: support custom prompt * feat: support custom prompt * feat: support custom prompt * feat: support custom prompt * feat: upgrade mcp-agent lib * feat: update * feat: fix * feat: fix * feat: fix * feat: fix
1 parent 27685d8 commit a02bb88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4329
-493
lines changed

aperag/agent/mcp_app_factory.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
import logging
1616

1717
from mcp_agent.app import MCPApp
18-
from mcp_agent.config import LoggerSettings, MCPServerSettings, MCPSettings, OpenAISettings, Settings
18+
from mcp_agent.config import (
19+
LoggerSettings,
20+
MCPServerSettings,
21+
MCPSettings,
22+
OpenAISettings,
23+
Settings,
24+
)
1925

2026
from .agent_config import AgentConfig
2127
from .exceptions import agent_config_invalid, mcp_init_failed
@@ -56,7 +62,11 @@ def create_mcp_app(
5662
try:
5763
settings = Settings(
5864
execution_engine="asyncio",
59-
logger=LoggerSettings(type="console", level="info"),
65+
logger=LoggerSettings(
66+
transports=["console"],
67+
level="info",
68+
progress_display=True,
69+
),
6070
mcp=MCPSettings(
6171
servers={
6272
"aperag": MCPServerSettings(
@@ -79,6 +89,10 @@ def create_mcp_app(
7989
temperature=temperature,
8090
max_tokens=max_tokens,
8191
),
92+
# otel=OpenTelemetrySettings(
93+
# enabled=True,
94+
# exporters=["console"],
95+
# ),
8296
)
8397

8498
mcp_app = MCPApp(name="aperag_agent", settings=settings)

aperag/api/components/schemas/collection.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ collectionSource:
109109
type: string
110110

111111

112+
indexPrompts:
113+
type: object
114+
description: Custom prompts for various index types
115+
properties:
116+
graph:
117+
type: string
118+
description: Custom prompt for graph/entity extraction
119+
summary:
120+
type: string
121+
description: Custom prompt for document summarization
122+
vision:
123+
type: string
124+
description: Custom prompt for image analysis
125+
112126
knowledgeGraphConfig:
113127
type: object
114128
description: Configuration for knowledge graph generation
@@ -153,6 +167,8 @@ collectionConfig:
153167
- $ref: '#/knowledgeGraphConfig'
154168
default:
155169
entity_types: ["organization", "person", "geo", "event", "product", "technology", "date", "category"]
170+
index_prompts:
171+
$ref: '#/indexPrompts'
156172
language:
157173
type: string
158174
description: Language for the collection content and processing
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
promptDetail:
2+
type: object
3+
description: Detailed prompt information with source and customization status
4+
properties:
5+
content:
6+
type: string
7+
description: Actual prompt content (resolved with priority)
8+
source:
9+
type: string
10+
enum: [user, system, hardcoded]
11+
description: Source of the prompt
12+
customized:
13+
type: boolean
14+
description: Whether user has customized this prompt
15+
description:
16+
type: string
17+
description: Optional description
18+
19+
userPromptsResponse:
20+
type: object
21+
description: User's prompt configuration with all types
22+
properties:
23+
agent_system:
24+
$ref: '#/promptDetail'
25+
agent_query:
26+
$ref: '#/promptDetail'
27+
index_graph:
28+
$ref: '#/promptDetail'
29+
index_summary:
30+
$ref: '#/promptDetail'
31+
index_vision:
32+
$ref: '#/promptDetail'
33+
34+
updateUserPromptsRequest:
35+
type: object
36+
required:
37+
- prompts
38+
properties:
39+
prompts:
40+
type: object
41+
description: Prompts to update (all fields are optional, only provided fields will be updated)
42+
properties:
43+
agent_system:
44+
type: string
45+
description: Agent system prompt (persona definition)
46+
agent_query:
47+
type: string
48+
description: Agent query prompt template
49+
index_graph:
50+
type: string
51+
description: Graph index prompt for entity/relation extraction
52+
index_summary:
53+
type: string
54+
description: Summary index prompt for document summarization
55+
index_vision:
56+
type: string
57+
description: Vision index prompt for image content extraction
58+
example:
59+
agent_system: "You are a professional technical support assistant..."
60+
index_graph: "Extract entities from medical text..."
61+
62+
updateUserPromptsResponse:
63+
type: object
64+
properties:
65+
message:
66+
type: string
67+
updated:
68+
type: array
69+
items:
70+
type: string
71+
72+
resetPromptsRequest:
73+
type: object
74+
properties:
75+
types:
76+
type: array
77+
items:
78+
type: string
79+
description: Prompt types to reset, omit to reset all
80+
81+
resetPromptsResponse:
82+
type: object
83+
properties:
84+
message:
85+
type: string
86+
reset:
87+
type: array
88+
items:
89+
type: string
90+
91+
deleteUserPromptResponse:
92+
type: object
93+
properties:
94+
message:
95+
type: string
96+
type:
97+
type: string
98+
new_content:
99+
type: string
100+
source:
101+
type: string
102+
enum: [system, hardcoded]
103+
104+
systemPromptDetail:
105+
type: object
106+
properties:
107+
type:
108+
type: string
109+
content:
110+
type: string
111+
description:
112+
type: string
113+
114+
systemPromptsResponse:
115+
type: object
116+
description: System default prompts
117+
additionalProperties:
118+
type: object
119+
properties:
120+
content:
121+
type: string
122+
description:
123+
type: string
124+
125+
previewRequest:
126+
type: object
127+
required:
128+
- template
129+
properties:
130+
template:
131+
type: string
132+
variables:
133+
type: object
134+
additionalProperties: true
135+
136+
previewResponse:
137+
type: object
138+
properties:
139+
rendered:
140+
type: string
141+
142+
validateRequest:
143+
type: object
144+
required:
145+
- type
146+
- template
147+
properties:
148+
type:
149+
type: string
150+
enum: [agent_system, agent_query, index_graph, index_summary, index_vision]
151+
template:
152+
type: string
153+
154+
validateResponse:
155+
type: object
156+
properties:
157+
valid:
158+
type: boolean
159+
errors:
160+
type: array
161+
items:
162+
type: string
163+
warnings:
164+
type: array
165+
items:
166+
type: string

aperag/api/openapi.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ paths:
8484
/settings/test_mineru_token:
8585
$ref: './paths/misc.yaml#/test_mineru_token'
8686

87+
# prompts
88+
/prompts/user:
89+
$ref: './paths/prompts.yaml#/promptsUser'
90+
/prompts/user/{prompt_type}:
91+
$ref: './paths/prompts.yaml#/promptsUserType'
92+
/prompts/user/reset:
93+
$ref: './paths/prompts.yaml#/promptsUserReset'
94+
/prompts/system:
95+
$ref: './paths/prompts.yaml#/promptsSystem'
96+
/prompts/preview:
97+
$ref: './paths/prompts.yaml#/promptsPreview'
98+
/prompts/validate:
99+
$ref: './paths/prompts.yaml#/promptsValidate'
100+
87101
# graphs
88102
/collections/{collection_id}/graphs/labels:
89103
$ref: './paths/collections.yaml#/graph_labels'

0 commit comments

Comments
 (0)