This directory contains example code demonstrating how to use the Aifeels library.
Demonstrates core functionality:
- Initializing emotional state
- Processing events
- Getting recommended actions
- Viewing state history
- Resetting state
Run it:
python examples/basic_usage.pyShows a realistic scenario of an autonomous agent using emotional state to guide task execution:
- Processing successful and failed tasks
- Handling user feedback
- Managing deadline pressure
- Escalating when frustration is high
- Requesting confirmation for risky operations
Run it:
python examples/task_automation.pyfrom aifeels import EmotionalState
from aifeels.events import StandardEvents
state = EmotionalState()
state.process_event(StandardEvents.TASK_FAILED)
print(state.frustration) # 0.3# Get simple action string
action = state.recommended_action()
# Returns: 'continue_autonomy', 'increase_caution', 'request_confirmation', or 'escalate_to_human'
# Get detailed recommendation
recommendation = state.get_action_recommendation()
print(recommendation.action) # Action enum
print(recommendation.reason) # Explanation
print(recommendation.triggered_by) # Which emotions triggered itimport time
state = EmotionalState()
state.process_event(StandardEvents.TASK_FAILED)
print(state.frustration) # 0.3
# Wait 5 minutes
time.sleep(300)
# Decay applied automatically
print(state.frustration) # 0.25 (decayed by 0.05)state = EmotionalState()
state.process_event(StandardEvents.TASK_STARTED)
state.process_event(StandardEvents.TASK_COMPLETED)
history = state.get_history()
for transition in history:
print(f"Event: {transition.event_name}")
print(f"Deltas: {transition.deltas}")
print(f"Before: {transition.state_before}")
print(f"After: {transition.state_after}")When creating your own implementations:
- Initialize state:
state = EmotionalState() - Process events: Use
StandardEventsor create customEventobjects - Check recommendations: Use
recommended_action()to guide behavior - Monitor history: Use
get_history()for debugging and auditing - Handle decay: Decay is applied automatically, or manually with
_apply_decay()