feat: protocol base lib + rule-based parser MVP + 31 tests
This commit is contained in:
@ -75,42 +75,52 @@ NextAgent LLM 子网:
|
||||
| **输入** | 结构化推理路径张量(来自 Core,经过张量解码层转换) |
|
||||
| **输出1** | 自然语言文本(直接发送给用户) |
|
||||
| **输出2** | 表达验证张量(发送给 Core) |
|
||||
| **输出2格式** | 标准张量协议,tensor_type=`expression_verify` |
|
||||
| **输出2格式** | 统一通信张量,fmt_id=5 (expression_verify) |
|
||||
|
||||
### 表达验证张量格式
|
||||
|
||||
```json
|
||||
{
|
||||
"header": {
|
||||
"source": "llm",
|
||||
"target": "core",
|
||||
"tensor_type": "expression_verify",
|
||||
"trace_id": "trace-uuid",
|
||||
"timestamp": 1717200000
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": 0.94,
|
||||
"semantic_encoding_dim": 768,
|
||||
"expression_structure": "sentence+paragraph",
|
||||
"sentiment": "positive",
|
||||
"language": "zh-CN",
|
||||
"token_count": 128,
|
||||
"verification_status": "verified"
|
||||
},
|
||||
"payload": {
|
||||
"semantic_encoding": [0.23, -0.56, ...], // 输出文本的语义向量
|
||||
"intention_alignment": 0.96, // 与输入推理路径的意图对齐度
|
||||
"factual_consistency": 0.92, // 与输入事实的一致性
|
||||
"sentence_embeddings": [ // 每句的编码(可选)
|
||||
{"index": 0, "embedding": [...]},
|
||||
{"index": 1, "embedding": [...]}
|
||||
],
|
||||
"emotion_vector": [0.1, 0.8, 0.3, ...], // 情感多维度向量
|
||||
"key_entities_preserved": ["天气", "北京", "今天"], // 关键实体保留
|
||||
"omission_detected": false // 是否有遗漏信息
|
||||
},
|
||||
"signature": "sha256-checksum"
|
||||
}
|
||||
遵循统一通信张量协议,**无 JSON 结构**,全部为纯数值张量:
|
||||
|
||||
```
|
||||
统一通信张量 (纯数值)
|
||||
prefix: [fmt_id=5, parser_id=5]
|
||||
payload:
|
||||
[semantic_encoding (768)] # 输出文本的语义向量
|
||||
[intention_alignment (1)] # 与输入推理路径的意图对齐度 (0~1)
|
||||
[factual_consistency (1)] # 与输入事实的一致性 (0~1)
|
||||
[emotion_vector (n_dims)] # 情感向量
|
||||
[entity_preserved_mask (n_entities)] # 关键实体保留掩码 [0/1]
|
||||
[overall_score (1)] # 综合验证得分 (0~1)
|
||||
```
|
||||
|
||||
**编码示例**:
|
||||
|
||||
```python
|
||||
def encode_expression_verify(output_text: str,
|
||||
reasoning_path: Tensor) -> Tensor:
|
||||
"""LLM 自然语言输出 → 表达验证张量 (通道2)
|
||||
|
||||
通道1: 自然语言文本直接输出给用户
|
||||
通道2: 此函数编码验证特征为纯张量返回给 Core
|
||||
"""
|
||||
sem_enc = sentence_encoder(output_text) # [768]
|
||||
alignment = cosine_sim(sem_enc, path_embedding) # [1]
|
||||
consistency = compute_factual_consistency(
|
||||
output_text, reasoning_path) # [1]
|
||||
emotion = emotion_analyzer(output_text) # [n]
|
||||
entity_mask = check_entities_preserved(output_text) # [n_entities]
|
||||
overall = compute_overall_score([alignment, consistency,
|
||||
entity_mask.mean()]) # [1]
|
||||
|
||||
payload = concat(sem_enc, alignment, consistency,
|
||||
emotion, entity_mask, overall)
|
||||
return codec.encode(fmt_id=5, parser_id=5, data=payload)
|
||||
|
||||
# Core 收到后解析
|
||||
payload = codec.decode(comm_tensor) # 剥离 fmt_id=5
|
||||
overall = payload[-1]
|
||||
if overall > THRESHOLD: # 验证通过
|
||||
user_output = channel_1_text # 允许输出
|
||||
```
|
||||
|
||||
## 子网内部架构
|
||||
|
||||
Reference in New Issue
Block a user