-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerative_model.py
More file actions
69 lines (60 loc) · 2.35 KB
/
generative_model.py
File metadata and controls
69 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
The Generative Model for Active Inference.
Stores the agent's beliefs, current state, and the Preferred Distribution (goal).
"""
import copy
class AgentState:
"""Represents the current hidden state / beliefs of the agent."""
def __init__(self, context=None):
self.context = context or {}
self.history = []
self.known_facts = set()
def update(self, observation):
"""Update beliefs based on new observation."""
self.history.append(observation)
# Update known facts or context
if isinstance(observation, dict):
for k, v in observation.items():
self.context[k] = v
self.known_facts.add(f"{k}: {v}")
class PreferredDistribution:
"""
Mathematical representation of a successful task completion.
This encodes the user's intent as a prior preference P(o).
"""
def __init__(self, user_instruction: str):
self.user_instruction = user_instruction
self.expected_outcomes = []
self.constraints = []
def add_expected_outcome(self, outcome: str):
self.expected_outcomes.append(outcome)
def get_preferences(self):
return {
"instruction": self.user_instruction,
"outcomes": self.expected_outcomes,
"constraints": self.constraints
}
class GenerativeModel:
"""
Combines the current state (beliefs) with the preferred distribution (goals).
"""
def __init__(self):
self.current_state = AgentState()
self.preferences = None
def set_preference(self, user_prompt: str):
"""
Takes the user's prompt and encodes it as the expected outcome (Prior Preference).
"""
self.preferences = PreferredDistribution(user_prompt)
# In a real scenario, we might use an LLM here to extract specific measurable outcomes from the prompt
self.preferences.add_expected_outcome(f"Successfully complete: {user_prompt}")
def update_beliefs(self, action_result):
"""
Updates the internal state based on action results (Observations).
"""
self.current_state.update(action_result)
def get_context(self):
return {
"state": self.current_state.context,
"preferences": self.preferences.get_preferences() if self.preferences else {}
}