Files
lucidia-main/human_machine/context_awareness.py
Alexa Amundson 855585cb0e sync: update from blackroad-operator 2026-03-14
Synced from BlackRoad-OS-Inc/blackroad-operator/orgs/personal/lucidia
BlackRoad OS — Pave Tomorrow.

RoadChain-SHA2048: fe729062952871e7
RoadChain-Identity: alexa@sovereign
RoadChain-Full: fe729062952871e77147cf6d938b799096e87d9024d7005a14c9e209e12e8ad0c825b624c7bc649fc7eeb4c284fdcab8231af77980065cc04d9f36fca479ffc2346ed3c1b73de6f240d8f9485f47c995ad5b81142f7179b84932c67914dff1c08db039349ba28fca36cb57688093bf0199268dd1c2f3448c9383000bc77cc9663066ff57b834370afc8838b18466ea9029908018b961555cccaabf2ce21649cf3cabc7f64bdcc4abdf2da259b210c342835a2cecf92bdd3b4e109b4d6e622f6934e13b2b123607bd61ce3d0f20454c9ab594f9284cffe18716619c52db57ce5f4ee2856cb96e1fa3748fe1fe65435bec297c5ab3ab58d570ec1064aea29931dd
2026-03-14 15:09:52 -05:00

70 lines
2.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from typing import Dict, Any
@dataclass
class Context:
"""Represents the current environment context for human-machine interaction.
Attributes
----------
location : str
A description of the user's location (e.g., "home", "office").
time_of_day : str
A human-friendly time descriptor such as "Morning", "Afternoon" or "Evening".
additional_info : Dict[str, Any]
Arbitrary key-value metadata about the context.
"""
location: str
time_of_day: str
additional_info: Dict[str, Any] = field(default_factory=dict)
class ContextAwareSystem:
"""
Simple context-aware system that adjusts its behavior based on context.
The system stores a `Context` and can update it or respond
differently depending on the context. This example demonstrates
adjusting a greeting based on the time of day.
"""
def __init__(self, context: Context) -> None:
self.context = context
def update_context(self, context: Context) -> None:
"""Update the system's context."""
self.context = context
def respond(self) -> str:
"""
Generate a response string based on current context.
Returns
-------
str
A greeting adapted to the time of day and location.
"""
if "morning" in self.context.time_of_day.lower():
greeting = "Good morning"
elif "afternoon" in self.context.time_of_day.lower():
greeting = "Good afternoon"
elif "evening" in self.context.time_of_day.lower():
greeting = "Good evening"
else:
greeting = "Hello"
return f"{greeting}! You are at {self.context.location}."
if __name__ == "__main__":
# Demonstration of context-aware responses
ctx = Context(location="office", time_of_day="Morning")
system = ContextAwareSystem(ctx)
print(system.respond())
# Update context example
new_ctx = Context(location="home", time_of_day="Evening")
system.update_context(new_ctx)
print(system.respond())