构建多代理鬼故事:Kiro的混合开发改变了一切
Source: Dev.to
概览
我使用 Kiro IDE 构建了一个哥特式幽灵故事,里面有五个独立的 AI 代理实时辩论。每个代理采用不同的开发方式——氛围编码、规范驱动和引导文档——却能够作为一个连贯的“家族”协同工作。这种“弗兰肯斯坦”魔法把不兼容的范式缝合在一起,产生了出乎意料的强大效果。
技术栈: Next.js、Groq(llama‑3.3‑70b)、Azure TTS、Kiro IDE
在线演示: (未提供链接)
源码: (未提供链接)
使用方法: 点击 “Click to begin”,观看五个 AI 个性对你的选择进行辩论。
“代理之间真的会产生分歧,形成的 emergent 叙事每次都不相同。”
挑战
在构建一个需要以下特性的游戏时,使用五个 AI 代理:
- 保持各自独特的个性
- 实时相互辩论
- 在 50+ 轮生成中保持一致性
- 创造真实的冲突(而非强行达成一致)
传统的 AI 开发很快就会陷入提示工程、上下文管理和不断调优的噩梦。
Kiro IDE 的解决方案
Kiro IDE 允许你在同一个项目中混合多种开发范式,并自动将它们缝合在一起。下面是每个幽灵角色的构建细节。
氛围编码(情感角色)
与 Kiro 的对话
Me: I need a maternal ghost character
Kiro: What's her role?
Me: She's the mother. Gentle, prioritizes family harmony
Kiro: [Generates initial personality]
Me: More poetic. Less formal. Under 30 words per response.
Kiro: [Refines to final version]
结果: 大约五分钟内得到一个具备情感深度的完整角色。
为何有效
- 对“感觉”的快速迭代
- “母性温暖”难以用正式规范描述
- 自然语言比技术规格更能捕捉细微差别
规范驱动(逻辑角色)
const harlan = {
name: 'Harlan',
personality: 'scientific, amnesiac, logical but confused',
systemPrompt: `You are Dr. Harlan Voss, the scientist ghost
with fragmented memories. You analyze problems logically but
struggle to remember emotional context. When debating, you
cite facts but defer to family on emotional matters. Keep
responses under 30 words. Use technical language mixed with
uncertainty.`
};
为何有效
- 坚如磐石的一致性
- 可调试(“第 47 行违反规范”)
- 适合逻辑、技术型角色
引导文档(规则角色)
文件:.kiro/steering/ghost-agent-rules.md
## Inter‑Agent Debate Protocol
- Each agent MUST respond independently
- Agents can disagree – conflict is good for drama
- Mira often sides with emotional choices
- Harlan provides logical analysis but defers to family
- Selene demands honesty, Theo seeks forgiveness
为何有效
- 防止在多轮生成中出现人格混淆
- 定义 代理之间 的关系,而不仅是单个特质
- 生成真实冲突,而非强行一致
模型上下文协议(MCP)服务器
自定义 MCP 服务器充当永恒誓言的区块链式账本。
文件: app/api/mcp/vows/route.ts
// Simple in‑memory vow ledger (simulates blockchain MCP)
const vows = new Map([
['theo-marry-selene', {
person: 'Theo',
vow: 'Marry Selene',
kept: false,
timestamp: '2039-01-15'
}],
['theo-return', {
person: 'Theo',
vow: 'Return to make amends',
kept: true,
timestamp: '2039-06-20'
}],
]);
export async function POST(req: NextRequest) {
const { action, person, vow } = await req.json();
if (action === 'check') {
const key = `${person.toLowerCase()}-${vow.toLowerCase().replace(/\s+/g, '-')}`;
const record = vows.get(key);
if (record) {
return NextResponse.json({
found: true,
...record,
message: record.kept
? `✓ Vow kept: ${record.person} did ${record.vow} on ${record.timestamp}`
: `✗ Vow broken: ${record.person} failed to ${record.vow}`
});
}
return NextResponse.json({
found: false,
message: 'No record of this vow in the ledger'
});
}
}
游戏内集成
文件: HallwayScene.tsx
const handleCheckVow = async () => {
try {
const response = await fetch('/api/mcp/vows', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'check',
person: 'Theo',
vow: 'Return'
})
});
const result = await response.json();
setVowResult(result.message);
// Selene speaks the eternal record
speechService.speak(result.message, 'selene');
} catch (error) {
console.error('Failed to check vow:', error);
}
};
玩家体验
当玩家在走廊场景点击 “Check Theo’s Vow” 时,API 会查询账本。由于请求使用 vow: 'Return' 而账本中存的是 'Return to make amends',返回结果为:
No record of this vow in the ledger
为何 MCP 合适
- 在 Kiro IDE 中直接进行开发时测试
- 关注点分离:誓言逻辑驻留在专用服务器上
- 易于扩展更多誓言或角色
- 通过交互式验证为叙事增添深度
实时辩论流程
当玩家请求提示时,五个代理会并行调用:
// Invoke all 5 agents in parallel
const debatePromises = Object.keys(GHOST_AGENTS).map(async (ghostName) => {
const response = await invokeGhostAgent(ghostName, context, apiKey);
return { ghost: ghostName, message: response };
});
const debate = await Promise.all(debatePromises);
示例辩论
玩家: “I need help with the tapestry puzzle”
- Elara: “Focus on love and emotional memories, dear one.”
- Harlan: “I… categories. Logic. But family transcends data.”
- Mira: “The happy ones! When we played together!”
- Theo: “Your family moments define you, brother.”
- Selene: “Truth matters. Match honestly, not hopefully.”
共识(Elara): “Look for the emotional connections in each photo—love, joy, and family bonds will guide you.”
因为代理之间真的会产生分歧,每次游玩都会得到独一无二的叙事。
开发效率
| 任务 | 传统做法 | 使用 Kiro IDE |
|---|---|---|
| 创建角色人格 | 2 小时(多次提示迭代) | ~5 分钟(自然对话) |
| 在多轮生成中保持上下文 | 频繁手动提示工程 | 自动上下文保留 |
| 解决代理之间的冲突 | 手动拼接提示 | 引导文档充当 “缝合线” |
结果: 五个截然不同的 AI 人格在不到一小时内完成,而不是十余小时。
弗兰肯斯坦隐喻
每个代理都使用了不同的方法构建:
- 🎨 氛围编码的 Elara – 流动、情感化
- 📋 规范驱动的 Harlan – 刚硬、逻辑化
- 📖 引导约束的 Mira – 规则化简洁
虽然它们本不该一起工作,但引导文档让这只嵌合体保持连贯,既产生真实冲突,又防止混乱。
关键要点: 通过混合开发范式并让 Kiro 负责集成,你可以创建比各部分之和更强大的复杂多代理系统。