Tpayne101 commited on
Commit
0a74204
·
verified ·
1 Parent(s): 31bb7d7

Update agentos_core.py

Browse files
Files changed (1) hide show
  1. agentos_core.py +35 -6
agentos_core.py CHANGED
@@ -2,13 +2,19 @@ import uuid
2
  import json
3
  import os
4
  import time
5
- from identity_core import IdentityCore
6
  from context_graph import ContextGraph
 
 
 
 
7
  class Telemetry:
8
  @staticmethod
9
  def log(event, status, data=None):
 
10
  print(f"[Telemetry] {event} - {status} | {data or {}}")
11
 
 
 
12
  class MemoryManager:
13
  def __init__(self, agent_id):
14
  self.agent_id = agent_id
@@ -18,6 +24,7 @@ class MemoryManager:
18
  json.dump({"history": []}, f)
19
 
20
  def save(self, data):
 
21
  with open(self.file_path, "r") as f:
22
  memory = json.load(f)
23
  memory["history"].append(data)
@@ -25,27 +32,49 @@ class MemoryManager:
25
  json.dump(memory, f, indent=2)
26
  print(f"[Memory] {self.agent_id} learned {data}")
27
 
 
 
 
 
 
 
 
 
28
  def create_agent_identity():
 
29
  return str(uuid.uuid4())
30
 
 
 
31
  class AgentCore:
32
  def __init__(self, model="gpt-4o-mini"):
33
- """Initialize agent with memory + telemetry."""
34
- self.identity = IdentityCore()
35
- agent_data = self.identity.create_identity()
36
- self.agent_signature = agent_data["signature"]
37
  self.agent_id = create_agent_identity()
38
  self.model = model
39
  self.memory = MemoryManager(self.agent_id)
40
  self.context = ContextGraph()
41
- Telemetry.log("init", "success", {"agent_id": self.agent_id})
 
 
 
 
 
 
 
42
  print(f"[INIT] Agent {self.agent_id} initialized with model {model}")
 
43
  def run(self, prompt):
 
44
  Telemetry.log("run_start", "in_progress", {"prompt": prompt})
45
  time.sleep(0.5)
 
 
46
  response = f"Agent {self.agent_id} processed: {prompt}"
 
 
47
  self.memory.save({"prompt": prompt, "response": response})
48
  self.context.link_context(self.agent_id, prompt, response)
 
49
  Telemetry.log("run_complete", "success", {"response": response})
50
  print(f"[RUN] {response}")
51
  return response
 
2
  import json
3
  import os
4
  import time
 
5
  from context_graph import ContextGraph
6
+ from identity_core import IdentityCore
7
+
8
+
9
+ # ---------- TELEMETRY ----------
10
  class Telemetry:
11
  @staticmethod
12
  def log(event, status, data=None):
13
+ """Simple logger for system events."""
14
  print(f"[Telemetry] {event} - {status} | {data or {}}")
15
 
16
+
17
+ # ---------- MEMORY ----------
18
  class MemoryManager:
19
  def __init__(self, agent_id):
20
  self.agent_id = agent_id
 
24
  json.dump({"history": []}, f)
25
 
26
  def save(self, data):
27
+ """Save each interaction into memory."""
28
  with open(self.file_path, "r") as f:
29
  memory = json.load(f)
30
  memory["history"].append(data)
 
32
  json.dump(memory, f, indent=2)
33
  print(f"[Memory] {self.agent_id} learned {data}")
34
 
35
+ def recall(self):
36
+ """Return the memory history."""
37
+ with open(self.file_path, "r") as f:
38
+ memory = json.load(f)
39
+ return memory["history"]
40
+
41
+
42
+ # ---------- IDENTITY ----------
43
  def create_agent_identity():
44
+ """Generate a unique ID for every agent instance."""
45
  return str(uuid.uuid4())
46
 
47
+
48
+ # ---------- AGENT CORE ----------
49
  class AgentCore:
50
  def __init__(self, model="gpt-4o-mini"):
51
+ """Initialize agent with memory, telemetry, context, and identity."""
 
 
 
52
  self.agent_id = create_agent_identity()
53
  self.model = model
54
  self.memory = MemoryManager(self.agent_id)
55
  self.context = ContextGraph()
56
+ self.identity = IdentityCore()
57
+ agent_data = self.identity.create_identity()
58
+ self.agent_signature = agent_data["signature"]
59
+
60
+ Telemetry.log("init", "success", {
61
+ "agent_id": self.agent_id,
62
+ "signature": self.agent_signature
63
+ })
64
  print(f"[INIT] Agent {self.agent_id} initialized with model {model}")
65
+
66
  def run(self, prompt):
67
+ """Main logic for handling a user prompt."""
68
  Telemetry.log("run_start", "in_progress", {"prompt": prompt})
69
  time.sleep(0.5)
70
+
71
+ # Simulated processing (replace with model later)
72
  response = f"Agent {self.agent_id} processed: {prompt}"
73
+
74
+ # Save to memory + link to context graph
75
  self.memory.save({"prompt": prompt, "response": response})
76
  self.context.link_context(self.agent_id, prompt, response)
77
+
78
  Telemetry.log("run_complete", "success", {"response": response})
79
  print(f"[RUN] {response}")
80
  return response