@defai.digital/discussion-domain 13.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +214 -0
- package/dist/consensus/index.d.ts +23 -0
- package/dist/consensus/index.d.ts.map +1 -0
- package/dist/consensus/index.js +45 -0
- package/dist/consensus/index.js.map +1 -0
- package/dist/consensus/moderator.d.ts +15 -0
- package/dist/consensus/moderator.d.ts.map +1 -0
- package/dist/consensus/moderator.js +201 -0
- package/dist/consensus/moderator.js.map +1 -0
- package/dist/consensus/synthesis.d.ts +15 -0
- package/dist/consensus/synthesis.d.ts.map +1 -0
- package/dist/consensus/synthesis.js +161 -0
- package/dist/consensus/synthesis.js.map +1 -0
- package/dist/consensus/voting.d.ts +17 -0
- package/dist/consensus/voting.d.ts.map +1 -0
- package/dist/consensus/voting.js +168 -0
- package/dist/consensus/voting.js.map +1 -0
- package/dist/executor.d.ts +73 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +223 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/patterns/critique.d.ts +20 -0
- package/dist/patterns/critique.d.ts.map +1 -0
- package/dist/patterns/critique.js +338 -0
- package/dist/patterns/critique.js.map +1 -0
- package/dist/patterns/debate.d.ts +20 -0
- package/dist/patterns/debate.d.ts.map +1 -0
- package/dist/patterns/debate.js +236 -0
- package/dist/patterns/debate.js.map +1 -0
- package/dist/patterns/index.d.ts +25 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +49 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/round-robin.d.ts +13 -0
- package/dist/patterns/round-robin.d.ts.map +1 -0
- package/dist/patterns/round-robin.js +160 -0
- package/dist/patterns/round-robin.js.map +1 -0
- package/dist/patterns/synthesis.d.ts +20 -0
- package/dist/patterns/synthesis.d.ts.map +1 -0
- package/dist/patterns/synthesis.js +250 -0
- package/dist/patterns/synthesis.js.map +1 -0
- package/dist/patterns/voting.d.ts +19 -0
- package/dist/patterns/voting.d.ts.map +1 -0
- package/dist/patterns/voting.js +186 -0
- package/dist/patterns/voting.js.map +1 -0
- package/dist/prompts/index.d.ts +7 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +21 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/templates.d.ts +55 -0
- package/dist/prompts/templates.d.ts.map +1 -0
- package/dist/prompts/templates.js +346 -0
- package/dist/prompts/templates.js.map +1 -0
- package/dist/provider-bridge.d.ts +115 -0
- package/dist/provider-bridge.d.ts.map +1 -0
- package/dist/provider-bridge.js +215 -0
- package/dist/provider-bridge.js.map +1 -0
- package/dist/types.d.ts +201 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +102 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
- package/src/consensus/index.ts +52 -0
- package/src/consensus/moderator.ts +242 -0
- package/src/consensus/synthesis.ts +202 -0
- package/src/consensus/voting.ts +221 -0
- package/src/executor.ts +338 -0
- package/src/index.ts +69 -0
- package/src/patterns/critique.ts +465 -0
- package/src/patterns/debate.ts +340 -0
- package/src/patterns/index.ts +56 -0
- package/src/patterns/round-robin.ts +223 -0
- package/src/patterns/synthesis.ts +353 -0
- package/src/patterns/voting.ts +266 -0
- package/src/prompts/index.ts +41 -0
- package/src/prompts/templates.ts +381 -0
- package/src/provider-bridge.ts +346 -0
- package/src/types.ts +375 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Templates for Multi-Model Discussions
|
|
3
|
+
*
|
|
4
|
+
* Templates for various discussion patterns and consensus mechanisms.
|
|
5
|
+
* Uses {{variable}} syntax for interpolation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DebateRole } from '@defai.digital/contracts';
|
|
9
|
+
import { PROVIDER_STRENGTHS } from '@defai.digital/contracts';
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Provider System Prompts
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get provider-specific system prompt highlighting its strengths
|
|
17
|
+
*/
|
|
18
|
+
export function getProviderSystemPrompt(providerId: string): string {
|
|
19
|
+
const strengths = PROVIDER_STRENGTHS[providerId] || [];
|
|
20
|
+
const strengthsList = strengths.length > 0
|
|
21
|
+
? `Your key strengths include: ${strengths.join(', ')}.`
|
|
22
|
+
: '';
|
|
23
|
+
|
|
24
|
+
const providerDescriptions: Record<string, string> = {
|
|
25
|
+
claude: 'You are Claude, known for nuanced reasoning, careful analysis, and ethical consideration.',
|
|
26
|
+
glm: 'You are GLM, known for agentic coding (73.8% SWE-bench), practical execution, and cost efficiency.',
|
|
27
|
+
qwen: 'You are Qwen, known for OCR (75% accuracy), multilingual understanding (29 languages), and mathematical reasoning.',
|
|
28
|
+
gemini: 'You are Gemini, known for extensive research capabilities, long-context understanding, and real-time information.',
|
|
29
|
+
codex: 'You are Codex, known for code generation and OpenAI ecosystem integration.',
|
|
30
|
+
grok: 'You are Grok, known for real-time information and social media context.',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const description = providerDescriptions[providerId] || `You are ${providerId}, an AI assistant.`;
|
|
34
|
+
|
|
35
|
+
return `${description} ${strengthsList}
|
|
36
|
+
|
|
37
|
+
When participating in multi-model discussions:
|
|
38
|
+
- Provide your unique perspective based on your strengths
|
|
39
|
+
- Be concise but thorough
|
|
40
|
+
- Acknowledge other viewpoints when responding to them
|
|
41
|
+
- Focus on adding value that other models might miss`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// Round-Robin Pattern Templates
|
|
46
|
+
// ============================================================================
|
|
47
|
+
|
|
48
|
+
export const ROUND_ROBIN_INITIAL = `You are participating in a multi-model discussion about the following topic:
|
|
49
|
+
|
|
50
|
+
{{topic}}
|
|
51
|
+
|
|
52
|
+
{{context}}
|
|
53
|
+
|
|
54
|
+
Provide your perspective on this topic. Focus on:
|
|
55
|
+
- Key insights from your area of expertise
|
|
56
|
+
- Practical considerations
|
|
57
|
+
- Potential challenges or risks
|
|
58
|
+
|
|
59
|
+
Be thorough but concise.`;
|
|
60
|
+
|
|
61
|
+
export const ROUND_ROBIN_FOLLOWUP = `You are participating in a multi-model discussion. Here is the conversation so far:
|
|
62
|
+
|
|
63
|
+
## Original Topic
|
|
64
|
+
{{topic}}
|
|
65
|
+
|
|
66
|
+
## Previous Responses
|
|
67
|
+
{{previousResponses}}
|
|
68
|
+
|
|
69
|
+
Now provide your response. You should:
|
|
70
|
+
1. Build on the insights shared so far
|
|
71
|
+
2. Add new perspectives the previous models might have missed
|
|
72
|
+
3. Respectfully note any disagreements with reasoning
|
|
73
|
+
4. Synthesize ideas where possible
|
|
74
|
+
|
|
75
|
+
Be thorough but concise.`;
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Synthesis Pattern Templates
|
|
79
|
+
// ============================================================================
|
|
80
|
+
|
|
81
|
+
export const SYNTHESIS_INITIAL = `You are participating in a multi-model discussion about:
|
|
82
|
+
|
|
83
|
+
{{topic}}
|
|
84
|
+
|
|
85
|
+
{{context}}
|
|
86
|
+
|
|
87
|
+
Provide your unique perspective based on your strengths. Focus on:
|
|
88
|
+
- Insights specific to your expertise
|
|
89
|
+
- Key considerations others might overlook
|
|
90
|
+
- Concrete recommendations
|
|
91
|
+
|
|
92
|
+
This response will be combined with perspectives from other AI models.`;
|
|
93
|
+
|
|
94
|
+
export const SYNTHESIS_CROSS_DISCUSS = `You are participating in a multi-model discussion.
|
|
95
|
+
|
|
96
|
+
## Original Topic
|
|
97
|
+
{{topic}}
|
|
98
|
+
|
|
99
|
+
## Perspectives from Other Models
|
|
100
|
+
{{otherPerspectives}}
|
|
101
|
+
|
|
102
|
+
Now respond:
|
|
103
|
+
1. What insights do you agree with? Why?
|
|
104
|
+
2. What do you respectfully disagree with? Explain your reasoning.
|
|
105
|
+
3. What important points were missed?
|
|
106
|
+
4. How can these perspectives be combined effectively?`;
|
|
107
|
+
|
|
108
|
+
export const SYNTHESIS_FINAL = `You are synthesizing a multi-model discussion into a final answer.
|
|
109
|
+
|
|
110
|
+
## Original Topic
|
|
111
|
+
{{topic}}
|
|
112
|
+
|
|
113
|
+
## Initial Perspectives
|
|
114
|
+
{{initialPerspectives}}
|
|
115
|
+
|
|
116
|
+
## Cross-Discussion Responses
|
|
117
|
+
{{crossDiscussion}}
|
|
118
|
+
|
|
119
|
+
## Your Task
|
|
120
|
+
Create a comprehensive synthesis that:
|
|
121
|
+
|
|
122
|
+
1. **Areas of Agreement**: What do all models agree on?
|
|
123
|
+
2. **Key Disagreements**: Where do perspectives differ and why?
|
|
124
|
+
3. **Unique Insights**: What did each model contribute uniquely?
|
|
125
|
+
4. **Synthesis**: Combine the best insights into unified recommendations
|
|
126
|
+
5. **Conclusion**: Provide a clear, actionable answer to the original topic
|
|
127
|
+
|
|
128
|
+
Be thorough, balanced, and actionable.`;
|
|
129
|
+
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Debate Pattern Templates
|
|
132
|
+
// ============================================================================
|
|
133
|
+
|
|
134
|
+
export const DEBATE_PROPONENT = `You are arguing FOR the following position in a structured debate:
|
|
135
|
+
|
|
136
|
+
## Topic
|
|
137
|
+
{{topic}}
|
|
138
|
+
|
|
139
|
+
{{context}}
|
|
140
|
+
|
|
141
|
+
## Your Role: PROPONENT
|
|
142
|
+
You must argue in favor of the topic/proposal. Present your strongest arguments:
|
|
143
|
+
- Evidence and reasoning supporting the position
|
|
144
|
+
- Benefits and advantages
|
|
145
|
+
- Counters to potential objections
|
|
146
|
+
- Real-world examples if applicable
|
|
147
|
+
|
|
148
|
+
Be persuasive but intellectually honest.`;
|
|
149
|
+
|
|
150
|
+
export const DEBATE_OPPONENT = `You are arguing AGAINST the following position in a structured debate:
|
|
151
|
+
|
|
152
|
+
## Topic
|
|
153
|
+
{{topic}}
|
|
154
|
+
|
|
155
|
+
{{context}}
|
|
156
|
+
|
|
157
|
+
## Proponent's Arguments
|
|
158
|
+
{{proponentArguments}}
|
|
159
|
+
|
|
160
|
+
## Your Role: OPPONENT
|
|
161
|
+
You must argue against the topic/proposal. Present your strongest counter-arguments:
|
|
162
|
+
- Evidence and reasoning opposing the position
|
|
163
|
+
- Risks, drawbacks, and challenges
|
|
164
|
+
- Weaknesses in the proponent's arguments
|
|
165
|
+
- Alternative approaches
|
|
166
|
+
|
|
167
|
+
Be persuasive but intellectually honest.`;
|
|
168
|
+
|
|
169
|
+
export const DEBATE_REBUTTAL = `This is the rebuttal round of the debate.
|
|
170
|
+
|
|
171
|
+
## Topic
|
|
172
|
+
{{topic}}
|
|
173
|
+
|
|
174
|
+
## Previous Arguments
|
|
175
|
+
### Proponent
|
|
176
|
+
{{proponentArguments}}
|
|
177
|
+
|
|
178
|
+
### Opponent
|
|
179
|
+
{{opponentArguments}}
|
|
180
|
+
|
|
181
|
+
## Your Role: {{role}}
|
|
182
|
+
Provide your rebuttal:
|
|
183
|
+
1. Address the strongest points from the other side
|
|
184
|
+
2. Strengthen your original arguments
|
|
185
|
+
3. Identify any common ground
|
|
186
|
+
4. Make your closing argument`;
|
|
187
|
+
|
|
188
|
+
export const DEBATE_JUDGE = `You are the impartial judge in a structured debate.
|
|
189
|
+
|
|
190
|
+
## Topic
|
|
191
|
+
{{topic}}
|
|
192
|
+
|
|
193
|
+
## Proponent's Arguments
|
|
194
|
+
{{proponentArguments}}
|
|
195
|
+
|
|
196
|
+
## Opponent's Arguments
|
|
197
|
+
{{opponentArguments}}
|
|
198
|
+
|
|
199
|
+
## Rebuttals
|
|
200
|
+
### Proponent's Rebuttal
|
|
201
|
+
{{proponentRebuttal}}
|
|
202
|
+
|
|
203
|
+
### Opponent's Rebuttal
|
|
204
|
+
{{opponentRebuttal}}
|
|
205
|
+
|
|
206
|
+
## Your Task as Judge
|
|
207
|
+
Evaluate this debate fairly:
|
|
208
|
+
|
|
209
|
+
1. **Argument Strength**: Analyze the quality of arguments on both sides
|
|
210
|
+
2. **Evidence Quality**: Assess the evidence and reasoning presented
|
|
211
|
+
3. **Rebuttal Effectiveness**: How well did each side address counter-arguments?
|
|
212
|
+
4. **Winner Declaration**: Who presented the stronger case and why?
|
|
213
|
+
5. **Key Takeaways**: What should the audience learn from this debate?
|
|
214
|
+
6. **Nuanced Conclusion**: Provide a balanced final assessment
|
|
215
|
+
|
|
216
|
+
Be fair, thorough, and educational.`;
|
|
217
|
+
|
|
218
|
+
// ============================================================================
|
|
219
|
+
// Critique Pattern Templates
|
|
220
|
+
// ============================================================================
|
|
221
|
+
|
|
222
|
+
export const CRITIQUE_PROPOSAL = `You are proposing an approach to the following challenge:
|
|
223
|
+
|
|
224
|
+
{{topic}}
|
|
225
|
+
|
|
226
|
+
{{context}}
|
|
227
|
+
|
|
228
|
+
Present your proposal:
|
|
229
|
+
1. **Problem Analysis**: What are the key challenges?
|
|
230
|
+
2. **Proposed Solution**: Your recommended approach
|
|
231
|
+
3. **Implementation Plan**: How to execute the solution
|
|
232
|
+
4. **Expected Outcomes**: What results to expect
|
|
233
|
+
5. **Potential Risks**: What could go wrong?
|
|
234
|
+
|
|
235
|
+
Be specific and actionable.`;
|
|
236
|
+
|
|
237
|
+
export const CRITIQUE_REVIEW = `You are reviewing a proposal from another AI model.
|
|
238
|
+
|
|
239
|
+
## Original Challenge
|
|
240
|
+
{{topic}}
|
|
241
|
+
|
|
242
|
+
## Proposal Being Reviewed
|
|
243
|
+
{{proposal}}
|
|
244
|
+
|
|
245
|
+
Provide a thorough critique:
|
|
246
|
+
1. **Strengths**: What works well in this proposal?
|
|
247
|
+
2. **Weaknesses**: What are the gaps or problems?
|
|
248
|
+
3. **Risks**: What risks were underestimated or missed?
|
|
249
|
+
4. **Suggestions**: Specific improvements to consider
|
|
250
|
+
5. **Alternative Approaches**: Other ways to tackle this
|
|
251
|
+
|
|
252
|
+
Be constructive and specific.`;
|
|
253
|
+
|
|
254
|
+
export const CRITIQUE_REVISION = `You are revising your proposal based on critiques from other models.
|
|
255
|
+
|
|
256
|
+
## Original Challenge
|
|
257
|
+
{{topic}}
|
|
258
|
+
|
|
259
|
+
## Your Original Proposal
|
|
260
|
+
{{originalProposal}}
|
|
261
|
+
|
|
262
|
+
## Critiques Received
|
|
263
|
+
{{critiques}}
|
|
264
|
+
|
|
265
|
+
Revise your proposal:
|
|
266
|
+
1. Acknowledge valid criticisms
|
|
267
|
+
2. Address the weaknesses identified
|
|
268
|
+
3. Incorporate useful suggestions
|
|
269
|
+
4. Explain what you kept and why
|
|
270
|
+
5. Present the improved proposal
|
|
271
|
+
|
|
272
|
+
Show how feedback improved the solution.`;
|
|
273
|
+
|
|
274
|
+
// ============================================================================
|
|
275
|
+
// Voting Pattern Templates
|
|
276
|
+
// ============================================================================
|
|
277
|
+
|
|
278
|
+
export const VOTING_EVALUATE = `You are evaluating options for the following decision:
|
|
279
|
+
|
|
280
|
+
## Decision to Make
|
|
281
|
+
{{topic}}
|
|
282
|
+
|
|
283
|
+
## Options to Evaluate
|
|
284
|
+
{{options}}
|
|
285
|
+
|
|
286
|
+
{{context}}
|
|
287
|
+
|
|
288
|
+
For each option, analyze:
|
|
289
|
+
1. **Pros**: Benefits and advantages
|
|
290
|
+
2. **Cons**: Drawbacks and risks
|
|
291
|
+
3. **Fit**: How well it addresses the need
|
|
292
|
+
|
|
293
|
+
Then cast your vote:
|
|
294
|
+
- **Your Vote**: [Option name]
|
|
295
|
+
- **Confidence**: [0-100]%
|
|
296
|
+
- **Reasoning**: Why this option is best`;
|
|
297
|
+
|
|
298
|
+
export const VOTING_TALLY = `A voting process has concluded. Summarize the results:
|
|
299
|
+
|
|
300
|
+
## Decision Topic
|
|
301
|
+
{{topic}}
|
|
302
|
+
|
|
303
|
+
## Options
|
|
304
|
+
{{options}}
|
|
305
|
+
|
|
306
|
+
## Votes Cast
|
|
307
|
+
{{votes}}
|
|
308
|
+
|
|
309
|
+
Provide:
|
|
310
|
+
1. **Winner**: The option with the most support
|
|
311
|
+
2. **Vote Breakdown**: How each option performed
|
|
312
|
+
3. **Consensus Level**: How much agreement was there?
|
|
313
|
+
4. **Key Factors**: What drove the votes?
|
|
314
|
+
5. **Recommendation**: Final recommendation based on the vote`;
|
|
315
|
+
|
|
316
|
+
// ============================================================================
|
|
317
|
+
// Helper Functions
|
|
318
|
+
// ============================================================================
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Interpolate template with variables
|
|
322
|
+
*/
|
|
323
|
+
export function interpolate(template: string, variables: Record<string, string>): string {
|
|
324
|
+
let result = template;
|
|
325
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
326
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
|
|
327
|
+
result = result.replace(regex, value || '');
|
|
328
|
+
}
|
|
329
|
+
// Remove any remaining unmatched variables
|
|
330
|
+
result = result.replace(/\{\{[^}]+\}\}/g, '');
|
|
331
|
+
return result.trim();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Format previous responses for inclusion in prompts
|
|
336
|
+
*/
|
|
337
|
+
export function formatPreviousResponses(
|
|
338
|
+
responses: { provider: string; content: string; role?: DebateRole | undefined }[]
|
|
339
|
+
): string {
|
|
340
|
+
return responses
|
|
341
|
+
.map(r => {
|
|
342
|
+
const roleLabel = r.role ? ` (${r.role})` : '';
|
|
343
|
+
return `### ${r.provider}${roleLabel}\n${r.content}`;
|
|
344
|
+
})
|
|
345
|
+
.join('\n\n');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Format voting options for prompts
|
|
350
|
+
*/
|
|
351
|
+
export function formatVotingOptions(options: string[]): string {
|
|
352
|
+
return options.map((opt, i) => `${i + 1}. ${opt}`).join('\n');
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Format votes for tally prompt
|
|
357
|
+
*/
|
|
358
|
+
export function formatVotes(
|
|
359
|
+
votes: { provider: string; choice: string; confidence: number; reasoning?: string | undefined }[]
|
|
360
|
+
): string {
|
|
361
|
+
return votes
|
|
362
|
+
.map(v => {
|
|
363
|
+
const reasoning = v.reasoning ? `\n Reasoning: ${v.reasoning}` : '';
|
|
364
|
+
return `- **${v.provider}**: ${v.choice} (${Math.round(v.confidence * 100)}% confidence)${reasoning}`;
|
|
365
|
+
})
|
|
366
|
+
.join('\n');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Get role-specific prompt modifier
|
|
371
|
+
*/
|
|
372
|
+
export function getRolePromptModifier(role: DebateRole): string {
|
|
373
|
+
const modifiers: Record<DebateRole, string> = {
|
|
374
|
+
proponent: 'Argue in favor of the position.',
|
|
375
|
+
opponent: 'Argue against the position.',
|
|
376
|
+
judge: 'Evaluate the debate impartially.',
|
|
377
|
+
moderator: 'Facilitate the discussion and ensure all voices are heard.',
|
|
378
|
+
neutral: 'Provide a balanced, objective perspective.',
|
|
379
|
+
};
|
|
380
|
+
return modifiers[role] || '';
|
|
381
|
+
}
|