Spaces:
Build error
Build error
Update agentos_core.py
Browse files- agentos_core.py +42 -40
agentos_core.py
CHANGED
|
@@ -1,42 +1,44 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
class
|
| 6 |
def __init__(self, agent_id):
|
| 7 |
-
self.
|
| 8 |
-
|
| 9 |
-
self.
|
| 10 |
-
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
class AgentCore:
|
| 29 |
-
def __init__(self, model="gpt-
|
| 30 |
-
|
| 31 |
-
self.memory =
|
| 32 |
-
self.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def run(self, prompt):
|
| 38 |
-
response = self.agent.run(prompt)
|
| 39 |
-
return {
|
| 40 |
-
"response": response,
|
| 41 |
-
"memory_summary": self.memory.buffer
|
| 42 |
-
}
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
class MemoryManager:
|
| 6 |
def __init__(self, agent_id):
|
| 7 |
+
self.agent_id = agent_id
|
| 8 |
+
self.file_path = f"memory_{agent_id}.json"
|
| 9 |
+
self._init_memory()
|
| 10 |
+
|
| 11 |
+
def _init_memory(self):
|
| 12 |
+
if not os.path.exists(self.file_path):
|
| 13 |
+
with open(self.file_path, "w") as f:
|
| 14 |
+
json.dump({"history": []}, f)
|
| 15 |
+
|
| 16 |
+
def save(self, data):
|
| 17 |
+
with open(self.file_path, "r") as f:
|
| 18 |
+
memory = json.load(f)
|
| 19 |
+
memory["history"].append(data)
|
| 20 |
+
with open(self.file_path, "w") as f:
|
| 21 |
+
json.dump(memory, f, indent=2)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ContextGraph:
|
| 25 |
+
def __init__(self):
|
| 26 |
+
self.context = {}
|
| 27 |
+
|
| 28 |
+
def update(self, key, value):
|
| 29 |
+
self.context[key] = value
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def create_agent_identity():
|
| 33 |
+
return str(uuid.uuid4())
|
| 34 |
+
|
| 35 |
+
|
| 36 |
class AgentCore:
|
| 37 |
+
def __init__(self, model="gpt-4o-mini"):
|
| 38 |
+
self.agent_id = create_agent_identity()
|
| 39 |
+
self.memory = MemoryManager(self.agent_id)
|
| 40 |
+
self.context_graph = ContextGraph()
|
| 41 |
+
self.memory.save({
|
| 42 |
+
"event": "init",
|
| 43 |
+
"details": f"Agent {self.agent_id} initialized."
|
| 44 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|