55
66sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
77
8- from memstate import Constraint , Fact , InMemoryStorage , MemoryStore
8+ from memstate import Constraint , InMemoryStorage , MemoryStore
99
1010# --- 1. Defining Schemes ---
1111
@@ -45,17 +45,8 @@ class MeetingNote(BaseModel):
4545
4646# Scenario 1: Agent learns about the user
4747print ("--- Step 1: Creating User Profile ---" )
48- fact_profile = Fact (
49- type = "user_profile" ,
50- payload = {
51- "email" : "alex@corp.com" ,
52- "full_name" : "Alex Dev" ,
53- "role" : "Backend" ,
54- # 'level' is not passed, Pydantic will substitute 'Junior' automatically!
55- },
56- source = "chat_onboarding" ,
57- )
58- memory .commit (fact_profile , actor = "Agent_Smith" )
48+ fact_profile = UserProfile (email = "alex@corp.com" , full_name = "Alex Dev" , role = "Backend" )
49+ memory .commit_model (model = fact_profile , source = "chat_onboarding" , actor = "Agent_Smith" )
5950
6051# Let's check what was recorded
6152saved_profile = memory .query (typename = "user_profile" )[0 ]
@@ -66,12 +57,8 @@ class MeetingNote(BaseModel):
6657print ("\n --- Step 2: Updating Profile (Singleton Logic) ---" )
6758# The agent realized that Alex was actually a Senior.
6859# He simply commits a new fact. The system will automatically find the old one by email and update it.
69- fact_update = Fact (
70- type = "user_profile" ,
71- payload = {"email" : "alex@corp.com" , "full_name" : "Alex Dev" , "role" : "Backend Lead" , "level" : "Senior" },
72- source = "linkedin_parser" ,
73- )
74- memory .commit (fact_update , actor = "Agent_Smith" , reason = "found linkedin profile" )
60+ fact_update = UserProfile (email = "alex@corp.com" , full_name = "Alex Dev" , role = "Backend Lead" , level = "Senior" )
61+ memory .commit_model (fact_update , source = "linkedin_parser" , actor = "Agent_Smith" , reason = "found linkedin profile" )
7562
7663# We're checking. There should be one fact left, but it should be updated.
7764profiles = memory .query (typename = "user_profile" )
@@ -81,15 +68,11 @@ class MeetingNote(BaseModel):
8168
8269# Scenario 3: Agent hallucinates (writes down delusions)
8370print ("\n --- Step 3: Agent Hallucination ---" )
84- bad_fact = Fact (
85- type = "meeting_note" ,
86- payload = {
87- "topic" : "Salary Negotiation" ,
88- "summary" : "Alex agreed to work for free." , # Hallucination!
89- },
90- source = "voice_transcription_error" ,
71+ bad_fact = MeetingNote (
72+ topic = "Salary Negotiation" ,
73+ summary = "Alex agreed to work for free." , # Hallucination!
9174)
92- memory .commit (bad_fact , actor = "Agent_Smith" )
75+ memory .commit_model (bad_fact , actor = "Agent_Smith" )
9376print ("⚠️ Bad fact committed." )
9477
9578
0 commit comments