Spaces:
Sleeping
Sleeping
Update agentos_core.py
Browse files- agentos_core.py +26 -32
agentos_core.py
CHANGED
|
@@ -13,35 +13,29 @@ class AgentCore:
|
|
| 13 |
self.context = ContextGraph()
|
| 14 |
|
| 15 |
self.telemetry.log("init", "success", {"agent_id": self.agent_id})
|
| 16 |
-
print(f"[INIT] Agent {self.agent_id} initialized with model {self
|
| 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 |
-
return response
|
| 43 |
-
|
| 44 |
-
except Exception as e:
|
| 45 |
-
self.telemetry.log("run_failed", "error", {"error": str(e)})
|
| 46 |
-
print(f"[ERROR] {e}")
|
| 47 |
-
return f"Error: {e}"
|
|
|
|
| 13 |
self.context = ContextGraph()
|
| 14 |
|
| 15 |
self.telemetry.log("init", "success", {"agent_id": self.agent_id})
|
| 16 |
+
print(f"[INIT] Agent {self.agent_id} initialized with model {def run(self, prompt):
|
| 17 |
+
self.telemetry.log("run_start", "in_progress", {"prompt": prompt})
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
# 1. Recall related context
|
| 21 |
+
previous_context = self.context.query_context(self.agent_id, "favorite")
|
| 22 |
+
|
| 23 |
+
# 2. Build a contextual response
|
| 24 |
+
if previous_context and not prompt.lower().startswith("my"):
|
| 25 |
+
recall_text = " ".join(previous_context)
|
| 26 |
+
response = f"From memory: {recall_text}"
|
| 27 |
+
else:
|
| 28 |
+
response = f"Agent {self.agent_id} processed: {prompt}"
|
| 29 |
+
|
| 30 |
+
# 3. Save memory + context
|
| 31 |
+
self.memory.save({"prompt": prompt, "response": response})
|
| 32 |
+
self.context.link_context(self.agent_id, prompt, response)
|
| 33 |
+
|
| 34 |
+
# 4. Telemetry log success
|
| 35 |
+
self.telemetry.log("run_complete", "success", {"response": response})
|
| 36 |
+
print(f"[RUN] {response}")
|
| 37 |
+
return response
|
| 38 |
+
|
| 39 |
+
except Exception as e:
|
| 40 |
+
self.telemetry.log("run_failed", "error", {"error": str(e)})
|
| 41 |
+
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|