File size: 2,340 Bytes
2c41dce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
"""
Proof Builder Agent
Assembles final proof object from validated components.
"""
from typing import Dict, Any
import uuid
from core.agent_base import Agent
from core.errors import ProofSystemError
from models.proof import Proof
class ProofBuilderAgent(Agent):
"""
Combines hash, metadata, and validation results into a Proof object.
"""
def execute(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
"""
Build final proof object.
Expected input_data:
{
"content_hash": str,
"hash_algorithm": str,
"metadata": dict,
"validation_status": str,
"extracted_text": str | None,
"ocr_engine": str | None,
"ocr_status": str | None,
...
}
Returns:
{
"proof": Proof,
"proof_id": str
}
"""
try:
# Generate unique proof ID
proof_id = self._generate_proof_id()
# Extract required fields
metadata = input_data.get("metadata", {})
# Build proof object (including OCR fields)
proof = Proof(
proof_id=proof_id,
content_hash=input_data.get("content_hash"),
hash_algorithm=input_data.get("hash_algorithm"),
content_type=metadata.get("content_type"),
content_size=metadata.get("content_size"),
timestamp=metadata.get("created_at"),
validation_status=input_data.get("validation_status"),
metadata=metadata,
extracted_text=input_data.get("extracted_text"),
ocr_engine=input_data.get("ocr_engine"),
ocr_status=input_data.get("ocr_status")
)
return {
"proof": proof,
"proof_id": proof_id
}
except Exception as e:
raise ProofSystemError(f"Proof building failed: {str(e)}") from e
def _generate_proof_id(self) -> str:
"""
Generate unique proof identifier.
Returns:
UUID string
"""
return str(uuid.uuid4()) |