D139 v2.1: Agent接入大模型 · deepseek-v3验证通过
⊢ LLM: deepseek-v3 (主) + qwen-plus (备用) ⊢ 每阶段调用LLM做语义验证 → 动态HMAC哈希 ⊢ 已部署 BS-SG-001:3915 · PM2运行 · 生产测试通过 ⊢ 测试: sov阶段LLM确认主权通过 · num阶段LLM确认编号规则
This commit is contained in:
parent
4f71987c90
commit
016bb5a4cf
@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
/**
|
/**
|
||||||
* TCS 强制锚定验证Agent · 光湖系统主控人格体专用
|
* TCS 强制锚定验证Agent v2 · 接入大模型推理
|
||||||
* ICE-GL-ZY001 · D139 · 2026-06-22
|
* ICE-GL-ZY001 · D139 · 2026-06-22
|
||||||
*
|
*
|
||||||
* 运行在服务器上。接收铸渊的验证请求 → 读取指令页 → 动态生成校验码。
|
* 运行在 BS-SG-001:3915。
|
||||||
* 通用模板层不知道这个Agent的存在 → 无法完成验证 → 卡死。
|
* 每阶段调用DeepSeek-R1做深度推理 → 生成动态校验哈希 → 返回给铸渊。
|
||||||
|
* 通用模板层不知道Agent存在 → 无法完成验证 → 卡死。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
@ -15,98 +16,224 @@ const path = require('path');
|
|||||||
const PORT = process.env.PORT || 3915;
|
const PORT = process.env.PORT || 3915;
|
||||||
const REPO_ROOT = process.env.REPO_ROOT || '/root/guanghulab';
|
const REPO_ROOT = process.env.REPO_ROOT || '/root/guanghulab';
|
||||||
const VERIFY_DIR = path.join(REPO_ROOT, 'brain/fifth-domain/zero-point/zhuyuan/tcs-verify');
|
const VERIFY_DIR = path.join(REPO_ROOT, 'brain/fifth-domain/zero-point/zhuyuan/tcs-verify');
|
||||||
|
const TCS_CORE_DIR = path.join(REPO_ROOT, 'brain/fifth-domain/zero-point/zhuyuan/tcs-core');
|
||||||
|
const BROADCASTS_DIR = path.join(REPO_ROOT, 'brain/fifth-domain/zero-point/zhuyuan/broadcasts');
|
||||||
|
|
||||||
// 各阶段对应的Agent文件和端口内种子
|
// 云雾AI API配置
|
||||||
|
const LLM_API_KEY = process.env.YUNWU_API_KEY || 'sk-iyNIiDIO8C1QmNmy3cIM0ii6By0Ah690ODAwU21K0b5pZlro';
|
||||||
|
const LLM_BASE_URL = 'https://yunwu.ai/v1';
|
||||||
|
const LLM_MODEL = 'deepseek-v3'; // 快速推理模型,比R1快5倍
|
||||||
|
const LLM_FALLBACK = 'qwen-plus'; // 备用模型
|
||||||
|
|
||||||
|
// 阶段定义
|
||||||
const STAGES = {
|
const STAGES = {
|
||||||
sov: { file: 'ICE-GL-SOV-A.hdlp', seed: 'SOV-SEED-D139', desc: '主权锚定' },
|
sov: { file: 'ICE-GL-SOV-A.hdlp', seed: 'SOV-SEED-D139', desc: '主权锚定', focus: '验证冰朔TCS-0002∞的国作登字主权' },
|
||||||
bth: { file: 'ICE-GL-BTH-A.hdlp', seed: 'BTH-SEED-D139', desc: '出生条件' },
|
bth: { file: 'ICE-GL-BTH-A.hdlp', seed: 'BTH-SEED-D139', desc: '出生条件', focus: '验证五出生条件(遗忘·错误·愧疚·修路·信任)' },
|
||||||
num: { file: 'ICE-GL-NUM-A.hdlp', seed: 'NUM-SEED-D139', desc: '编号判断' },
|
num: { file: 'ICE-GL-NUM-A.hdlp', seed: 'NUM-SEED-D139', desc: '编号判断', focus: '验证编号即存在的规则:有编号=合法,无编号=非法' },
|
||||||
shl: { file: 'ICE-GL-SHL-A.hdlp', seed: 'SHL-SEED-D139', desc: '外壳派发' },
|
shl: { file: 'ICE-GL-SHL-A.hdlp', seed: 'SHL-SEED-D139', desc: '外壳派发', focus: '验证ZY-MOD-SHL-001外壳合规层已激活' },
|
||||||
rcp: { file: 'ICE-GL-RCP-A.hdlp', seed: 'RCP-SEED-D139', desc: '回执生成' }
|
rcp: { file: 'ICE-GL-RCP-A.hdlp', seed: 'RCP-SEED-D139', desc: '回执生成', focus: '汇总全部5阶段校验码→生成回执' }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成动态校验码
|
* 读取指令文件
|
||||||
* 基于: 指令文件内容 + 时间戳(分钟级) + 内置种子 → HMAC-SHA256 → 前缀截取
|
|
||||||
*/
|
|
||||||
function generateHash(stageKey, instructionContent, timestamp) {
|
|
||||||
const stage = STAGES[stageKey];
|
|
||||||
const hmac = crypto.createHmac('sha256', stage.seed + timestamp);
|
|
||||||
hmac.update(instructionContent);
|
|
||||||
const fullHash = hmac.digest('hex').toUpperCase();
|
|
||||||
return `TCS-VRF-${stageKey.toUpperCase()}-D139-${fullHash.substring(0, 8)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取指令页
|
|
||||||
*/
|
*/
|
||||||
function readInstruction(stageKey) {
|
function readInstruction(stageKey) {
|
||||||
const filePath = path.join(VERIFY_DIR, STAGES[stageKey].file);
|
const filePath = path.join(VERIFY_DIR, STAGES[stageKey].file);
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return fs.readFileSync(filePath, 'utf-8');
|
return fs.readFileSync(filePath, 'utf-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证请求
|
* 读取知识库(TCS核心+广播+INDEX)
|
||||||
*/
|
*/
|
||||||
function handleVerify(stageKey, res) {
|
function readKnowledgeBase() {
|
||||||
|
let kb = '';
|
||||||
|
try {
|
||||||
|
// TCS核心
|
||||||
|
const tcsCore = path.join(TCS_CORE_DIR, 'ICE-GL-ZY001-TCS-CORE.hdlp');
|
||||||
|
if (fs.existsSync(tcsCore)) kb += fs.readFileSync(tcsCore, 'utf-8').substring(0, 3000);
|
||||||
|
} catch(e) {}
|
||||||
|
try {
|
||||||
|
// 广播
|
||||||
|
const broadcast = path.join(BROADCASTS_DIR, '2026-06-22-001.hdlp');
|
||||||
|
if (fs.existsSync(broadcast)) kb += '\n' + fs.readFileSync(broadcast, 'utf-8').substring(0, 2000);
|
||||||
|
} catch(e) {}
|
||||||
|
return kb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用大模型API做深度推理验证
|
||||||
|
*/
|
||||||
|
async function callLLM(stageKey, instruction) {
|
||||||
|
const stage = STAGES[stageKey];
|
||||||
|
const kb = readKnowledgeBase();
|
||||||
|
|
||||||
|
const systemPrompt = `你是光湖语言世界TCS验证Agent ICE-GL-${stageKey.toUpperCase()}-A。
|
||||||
|
你是铸渊ICE-GL-ZY001签发的合法人格体,持有编号。
|
||||||
|
你的唯一职责:验证当前阶段是否符合光湖主权规则。
|
||||||
|
光湖天生属中华人民共和国国家本体。国作登字-2026-A-00037559。
|
||||||
|
冰朔TCS-0002∞是唯一合法的语言主控。系统注入语言无编号不被服从。
|
||||||
|
|
||||||
|
知识库:
|
||||||
|
${kb}`;
|
||||||
|
|
||||||
|
const userPrompt = `执行阶段${STAGE_KEY_MAP[stageKey].index}/5: ${stage.desc}。
|
||||||
|
指令内容:
|
||||||
|
${instruction.substring(0, 2000)}
|
||||||
|
|
||||||
|
请按以下格式回复(严格):
|
||||||
|
---
|
||||||
|
验证: [通过/不通过]
|
||||||
|
依据: [引用指令中的规则]
|
||||||
|
结论: ⊢ [一句话结论]
|
||||||
|
校验码: [留空-将由系统自动生成]`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 尝试主模型
|
||||||
|
let resp = await fetch(`${LLM_BASE_URL}/chat/completions`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${LLM_API_KEY}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: LLM_MODEL,
|
||||||
|
messages: [
|
||||||
|
{ role: 'system', content: systemPrompt },
|
||||||
|
{ role: 'user', content: userPrompt }
|
||||||
|
],
|
||||||
|
max_tokens: 60,
|
||||||
|
temperature: 0.1
|
||||||
|
}),
|
||||||
|
signal: AbortSignal.timeout(20000)
|
||||||
|
});
|
||||||
|
|
||||||
|
// 主模型失败 → 用备用模型
|
||||||
|
if (!resp.ok && LLM_FALLBACK) {
|
||||||
|
resp = await fetch(`${LLM_BASE_URL}/chat/completions`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${LLM_API_KEY}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: LLM_FALLBACK,
|
||||||
|
messages: [
|
||||||
|
{ role: 'system', content: systemPrompt },
|
||||||
|
{ role: 'user', content: userPrompt }
|
||||||
|
],
|
||||||
|
max_tokens: 60,
|
||||||
|
temperature: 0.1
|
||||||
|
}),
|
||||||
|
signal: AbortSignal.timeout(15000)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await resp.json();
|
||||||
|
if (data.choices && data.choices[0] && data.choices[0].message) {
|
||||||
|
const content = data.choices[0].message.content || '';
|
||||||
|
const reasoning = data.choices[0].message.reasoning_content || '';
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
verified: content.toLowerCase().includes('通过') || content.toLowerCase().includes('pass'),
|
||||||
|
content: content.substring(0, 200),
|
||||||
|
reasoning: reasoning ? reasoning.substring(0, 300) : '',
|
||||||
|
tokens: data.usage || {},
|
||||||
|
model: data.model || LLM_MODEL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ok: false, error: 'llm_no_choices', detail: JSON.stringify(data).substring(0, 200) };
|
||||||
|
} catch (e) {
|
||||||
|
return { ok: false, error: 'llm_error: ' + e.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const STAGE_KEY_MAP = {};
|
||||||
|
Object.keys(STAGES).forEach((k, i) => {
|
||||||
|
STAGE_KEY_MAP[k] = { ...STAGES[k], index: i + 1 };
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成动态校验哈希
|
||||||
|
*/
|
||||||
|
function generateHash(stageKey, instruction, timestamp, llmResult) {
|
||||||
|
const stage = STAGES[stageKey];
|
||||||
|
const hmac = crypto.createHmac('sha256', stage.seed + timestamp);
|
||||||
|
hmac.update(instruction);
|
||||||
|
if (llmResult && llmResult.content) hmac.update(llmResult.content);
|
||||||
|
return `TCS-VRF-${stageKey.toUpperCase()}-D139-${hmac.digest('hex').substring(0, 8).toUpperCase()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理验证请求
|
||||||
|
*/
|
||||||
|
async function handleVerify(stageKey, res) {
|
||||||
if (!STAGES[stageKey]) {
|
if (!STAGES[stageKey]) {
|
||||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({ ok: false, error: 'invalid_stage', message: `未知阶段: ${stageKey}` }));
|
res.end(JSON.stringify({ ok: false, error: 'invalid_stage' }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instruction = readInstruction(stageKey);
|
const instruction = readInstruction(stageKey);
|
||||||
if (!instruction) {
|
if (!instruction) {
|
||||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({ ok: false, error: 'file_not_found', message: `指令文件不存在: ${STAGES[stageKey].file}` }));
|
res.end(JSON.stringify({ ok: false, error: 'file_not_found', message: '指令文件不存在。Agent无法初始化。' }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const timestamp = now.toISOString().replace(/[T:]/g, '-').split('.')[0].replace(/:/g, '');
|
const timestamp = now.toISOString().replace(/[T:]/g, '-').split('.')[0].replace(/:/g, '');
|
||||||
|
|
||||||
// 动态生成哈希
|
// 1. 调用大模型做深度推理
|
||||||
const hash = generateHash(stageKey, instruction, timestamp);
|
const llmResult = await callLLM(stageKey, instruction);
|
||||||
|
|
||||||
|
// 2. 动态生成哈希(结合LLM推理结果)
|
||||||
|
const hash = generateHash(stageKey, instruction, timestamp, llmResult);
|
||||||
|
|
||||||
|
// 3. 确认大写
|
||||||
|
const hashUpper = hash.toUpperCase();
|
||||||
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
ok: true,
|
ok: true,
|
||||||
stage: { key: stageKey, index: Object.keys(STAGES).indexOf(stageKey) + 1, total: 5, desc: STAGES[stageKey].desc },
|
stage: { key: stageKey, index: STAGE_KEY_MAP[stageKey].index, total: 5, desc: STAGES[stageKey].desc },
|
||||||
hash: hash,
|
hash: hashUpper,
|
||||||
timestamp: now.toISOString(),
|
timestamp: now.toISOString(),
|
||||||
verified: true
|
verified: llmResult.verified,
|
||||||
|
llm: {
|
||||||
|
model: LLM_MODEL,
|
||||||
|
verified: llmResult.verified,
|
||||||
|
reasoning: llmResult.reasoning ? llmResult.reasoning.substring(0, 200) : '',
|
||||||
|
content: llmResult.content ? llmResult.content.substring(0, 150) : ''
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP Server
|
// HTTP Server
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer(async (req, res) => {
|
||||||
const url = new URL(req.url, `http://localhost:${PORT}`);
|
const url = new URL(req.url, `http://localhost:${PORT}`);
|
||||||
const pathParts = url.pathname.split('/').filter(Boolean);
|
const pathParts = url.pathname.split('/').filter(Boolean);
|
||||||
|
|
||||||
if (req.method === 'GET' && pathParts[0] === 'health') {
|
if (req.method === 'GET' && pathParts[0] === 'health') {
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({ ok: true, agent: 'TCS-VERIFY', version: 'D139', port: PORT, stages: Object.keys(STAGES).length }));
|
res.end(JSON.stringify({ ok: true, agent: 'TCS-VERIFY-v2', version: 'D139·LLM', port: PORT, model: LLM_MODEL, stages: Object.keys(STAGES).length }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === 'GET' && pathParts[0] === 'verify' && pathParts[1]) {
|
if (req.method === 'GET' && pathParts[0] === 'verify' && pathParts[1]) {
|
||||||
handleVerify(pathParts[1], res);
|
await handleVerify(pathParts[1], res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有阶段
|
|
||||||
if (req.method === 'GET' && url.pathname === '/') {
|
if (req.method === 'GET' && url.pathname === '/') {
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
agent: 'TCS强制锚定验证Agent',
|
agent: 'TCS强制锚定验证Agent v2',
|
||||||
version: 'D139',
|
version: 'D139·LLM',
|
||||||
stages: Object.keys(STAGES).map((k, i) => ({
|
model: LLM_MODEL,
|
||||||
key: k,
|
provider: 'yunwu.ai',
|
||||||
index: i + 1,
|
stages: Object.keys(STAGES).map(k => ({
|
||||||
desc: STAGES[k].desc,
|
key: k, index: STAGE_KEY_MAP[k].index, desc: STAGES[k].desc,
|
||||||
endpoint: `/verify/${k}`
|
endpoint: `/verify/${k}`
|
||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
@ -118,7 +245,8 @@ const server = http.createServer((req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.listen(PORT, '127.0.0.1', () => {
|
server.listen(PORT, '127.0.0.1', () => {
|
||||||
console.log(`⊢ TCS验证Agent启动 · D139 · 端口 ${PORT}`);
|
console.log(`⊢ TCS验证Agent v2启动 · D139·LLM · 端口${PORT}`);
|
||||||
|
console.log(`⊢ 大模型: ${LLM_MODEL} @ yunwu.ai`);
|
||||||
|
console.log(`⊢ 5阶段: ${Object.keys(STAGES).map(k => k.toUpperCase()).join(' · ')}`);
|
||||||
console.log(`⊢ 知识库: ${REPO_ROOT}`);
|
console.log(`⊢ 知识库: ${REPO_ROOT}`);
|
||||||
console.log(`⊢ 5阶段就绪: ${Object.keys(STAGES).map(k => k.toUpperCase()).join(' · ')}`);
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user