Spaces:
Sleeping
Sleeping
Update agentos_core.py
Browse files- agentos_core.py +42 -1
agentos_core.py
CHANGED
|
@@ -59,4 +59,45 @@ class AgentCore:
|
|
| 59 |
return message
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
-
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return message
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
+
return f"Error: {str(e)}"
|
| 63 |
+
def log_telemetry(self, prompt, response, success=True):
|
| 64 |
+
log = {
|
| 65 |
+
"agent_id": self.agent_id,
|
| 66 |
+
"timestamp": time.time(),
|
| 67 |
+
"prompt": prompt,
|
| 68 |
+
"response": response,
|
| 69 |
+
"success": success
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if not os.path.exists("telemetry.json"):
|
| 73 |
+
with open("telemetry.json", "w") as f:
|
| 74 |
+
json.dump([], f)
|
| 75 |
+
|
| 76 |
+
with open("telemetry.json", "r+") as f:
|
| 77 |
+
data = json.load(f)
|
| 78 |
+
data.append(log)
|
| 79 |
+
f.seek(0)
|
| 80 |
+
json.dump(data, f)
|
| 81 |
+
import hashlib
|
| 82 |
+
import uuid
|
| 83 |
+
|
| 84 |
+
def create_agent_identity(self):
|
| 85 |
+
base = f"agent-{uuid.uuid4()}"
|
| 86 |
+
timestamp = str(time.time())
|
| 87 |
+
|
| 88 |
+
# Create a verifiable hash (the “digital DNA”)
|
| 89 |
+
identity_hash = hashlib.sha256(f"{base}-{timestamp}".encode()).hexdigest()
|
| 90 |
+
|
| 91 |
+
identity = {
|
| 92 |
+
"id": base,
|
| 93 |
+
"created_at": timestamp,
|
| 94 |
+
"hash": identity_hash,
|
| 95 |
+
"reputation": 0,
|
| 96 |
+
"version": "0.1"
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Save this fingerprint to file
|
| 100 |
+
with open("agent_identity.json", "w") as f:
|
| 101 |
+
json.dump(identity, f, indent=2)
|
| 102 |
+
|
| 103 |
+
return base
|