Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Aifeels Examples

This directory contains example code demonstrating how to use the Aifeels library.

Examples

1. Basic Usage (basic_usage.py)

Demonstrates core functionality:

  • Initializing emotional state
  • Processing events
  • Getting recommended actions
  • Viewing state history
  • Resetting state

Run it:

python examples/basic_usage.py

2. Task Automation (task_automation.py)

Shows 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.py

Key Concepts Demonstrated

Event Processing

from aifeels import EmotionalState
from aifeels.events import StandardEvents

state = EmotionalState()
state.process_event(StandardEvents.TASK_FAILED)
print(state.frustration)  # 0.3

Action Recommendations

# 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 it

Temporal Decay

import 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 History

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}")

Writing Your Own Examples

When creating your own implementations:

  1. Initialize state: state = EmotionalState()
  2. Process events: Use StandardEvents or create custom Event objects
  3. Check recommendations: Use recommended_action() to guide behavior
  4. Monitor history: Use get_history() for debugging and auditing
  5. Handle decay: Decay is applied automatically, or manually with _apply_decay()

More Resources