Skip to content

Commit e5dfd31

Browse files
author
linyuan.yang
committed
迁移 prompt
1 parent e2ba7a2 commit e5dfd31

15 files changed

Lines changed: 79 additions & 42 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The above is a summary of the previous conversation. Please continue from where you left off without asking the user any questions. Resume work directly; do not confirm the summary content, do not recap previous work, and do not start with phrases like "I will continue".
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
vars:
3+
summary: The compacted conversation summary text
4+
---
5+
[Conversation Summary]
6+
{summary}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List or get prompt templates from MCP servers. Use action 'list' to discover available prompts, or 'get' to render a specific prompt by name.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List or read resources from MCP servers. Use action 'list' to discover available resources, or 'read' to fetch content by URI.

packages/sbot/src/Agent/AgentFactory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
TransientACPAgentService, PersistentACPAgentService, T_ACPCommand, T_ACPArgs, T_ACPEnv, T_ACPWorkPath,
44
IModelService,
55
IAgentSaverService, AgentMemorySaver, ILoggerService,
6-
ConversationCompactor, IConversationCompactor, T_SummaryModelService, T_CompactPromptTemplate,
6+
ConversationCompactor, IConversationCompactor, T_SummaryModelService,
7+
T_CompactPromptTemplate, T_PostCompactMessageTemplate, T_PostCompactContinuation,
78
} from "scorpio.ai";
89
import {
910
IAgentToolService, AgentToolService,
@@ -182,6 +183,8 @@ export class AgentFactory {
182183
container.registerWithArgs(IConversationCompactor, ConversationCompactor, {
183184
[T_SummaryModelService]: await config.getModelService(entry.compactModel, true),
184185
[T_CompactPromptTemplate]: loadPrompt('compact/instruction.txt'),
186+
[T_PostCompactMessageTemplate]: loadPrompt('compact/post_message.txt'),
187+
[T_PostCompactContinuation]: loadPrompt('compact/post_continuation.txt'),
185188
});
186189
}
187190

packages/sbot/src/Agent/AgentRunner.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import {
1010
IAgentSaverService, AgentFileSaver, AgentSqliteSaver, AgentMemorySaver,
1111
T_DBPath,
1212
T_MemorySystemPromptTemplate,
13+
T_MemoryToolDescs,
1314
IModelService,
1415
IWikiService, IWikiDatabase,
1516
WikiService,
1617
T_WikiSystemPromptTemplate,
18+
T_WikiToolDescs,
1719
IInsightService, InsightService,
1820
IInsightExtractor, InsightExtractor,
1921
T_InsightDir,
@@ -138,6 +140,7 @@ export class AgentRunner {
138140
sub.registerWithArgs(IMemoryService, MemoryService, {
139141
[IEmbeddingService]: embedding,
140142
[T_MemorySystemPromptTemplate]: loadPrompt('memory/system.txt'),
143+
[T_MemoryToolDescs]: { search: loadPrompt('tools/memory/search.txt') },
141144
});
142145

143146
return sub.resolve<IMemoryService>(IMemoryService);
@@ -171,6 +174,10 @@ export class AgentRunner {
171174

172175
const args: Record<string | symbol, any> = {
173176
[T_WikiSystemPromptTemplate]: loadPrompt('wiki/system.txt'),
177+
[T_WikiToolDescs]: {
178+
search: loadPrompt('tools/wiki/search.txt'),
179+
read: loadPrompt('tools/wiki/read.txt'),
180+
},
174181
};
175182

176183
sub.registerWithArgs(IWikiService, WikiService, args);

packages/sbot/src/Session/BuiltInCommands.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ export class CompactCommand implements ICommand {
115115

116116
const saver = await AgentRunner.createSaverService(saverId, session.threadId);
117117
try {
118-
const compactor = new ConversationCompactor(summaryModel, loadPrompt('compact/instruction.txt'), GlobalLoggerService.getLoggerService());
118+
const compactor = new ConversationCompactor(
119+
summaryModel,
120+
loadPrompt('compact/instruction.txt'),
121+
loadPrompt('compact/post_message.txt'),
122+
loadPrompt('compact/post_continuation.txt'),
123+
GlobalLoggerService.getLoggerService(),
124+
);
119125
const allMessages = await saver.getAllMessages();
120126
if (allMessages.length <= 1) return '消息过少,无需压缩';
121127

122-
const result = await compactor.compact(allMessages);
128+
const postMessage = await compactor.compact(allMessages, false);
123129
const compactedIds = allMessages.filter(m => m.id != null).map(m => m.id!);
124-
await saver.applyCompaction(compactedIds, ConversationCompactor.buildPostCompactMessage(result.summary, false));
130+
await saver.applyCompaction(compactedIds, postMessage);
125131
return `压缩完成:${allMessages.length} 条消息已压缩`;
126132
} finally {
127133
await saver.dispose();

packages/scorpio.ai/src/AgentTool/MCPUtilityTools.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ export interface MCPServerCaps {
1010
readResource?: (uri: string) => Promise<MCPResourceContent[]>;
1111
}
1212

13+
export interface MCPUtilityToolDescs {
14+
prompts: string;
15+
resources: string;
16+
}
17+
1318
export function createMCPUtilityTools(
1419
servers: Map<string, MCPServerCaps>,
20+
descs: MCPUtilityToolDescs,
1521
): DynamicStructuredTool[] {
1622
const tools: DynamicStructuredTool[] = [];
1723

@@ -21,7 +27,7 @@ export function createMCPUtilityTools(
2127
if (hasPrompts) {
2228
tools.push(new DynamicStructuredTool({
2329
name: "mcp_prompts",
24-
description: "List or get prompt templates from MCP servers. Use action 'list' to discover available prompts, or 'get' to render a specific prompt by name.",
30+
description: descs.prompts,
2531
schema: z.object({
2632
action: z.enum(["list", "get"]).describe("'list' to list prompts, 'get' to render a specific prompt"),
2733
name: z.string().optional().describe("Prompt name (required for 'get')"),
@@ -50,7 +56,7 @@ export function createMCPUtilityTools(
5056
if (hasResources) {
5157
tools.push(new DynamicStructuredTool({
5258
name: "mcp_resources",
53-
description: "List or read resources from MCP servers. Use action 'list' to discover available resources, or 'read' to fetch content by URI.",
59+
description: descs.resources,
5460
schema: z.object({
5561
action: z.enum(["list", "read"]).describe("'list' to list resources, 'read' to fetch resource content"),
5662
uri: z.string().optional().describe("Resource URI (required for 'read')"),

packages/scorpio.ai/src/AgentTool/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ export { AgentToolService } from "./AgentToolService";
1212
// ===== 类型定义 =====
1313
export { MCPServerConfig, MCPServers } from "./MCPServerConfig";
1414
export type { MCPPrompt, MCPPromptMessage, MCPResource, MCPResourceTemplate, MCPResourceContent, ProviderResult } from "./MCPTypes";
15+
16+
// ===== Utility 工具 =====
17+
export { createMCPUtilityTools, type MCPServerCaps, type MCPUtilityToolDescs } from "./MCPUtilityTools";

packages/scorpio.ai/src/Agents/Single/SingleAgentService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ export class SingleAgentService extends AgentServiceBase {
161161
const allMessages = await this.saverService.getAllMessages();
162162
const savedTokens = parseInt(await this.saverService.getMetadata(METADATA_KEY_INPUT_TOKENS) ?? '0', 10);
163163
if (this.compactor.shouldCompact(savedTokens, allMessages, contextWindow)) {
164-
const result = await this.compactor.compact(allMessages);
164+
const postMessage = await this.compactor.compact(allMessages);
165165
const compactedIds = allMessages.filter(m => m.id != null).map(m => m.id!);
166-
await this.saverService.applyCompaction(compactedIds, ConversationCompactor.buildPostCompactMessage(result.summary));
166+
await this.saverService.applyCompaction(compactedIds, postMessage);
167167
}
168168
}
169169

0 commit comments

Comments
 (0)