autonomy build, phase 1
This commit is contained in:
74
cortex/autonomy/self/analyzer.py
Normal file
74
cortex/autonomy/self/analyzer.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
Analyze interactions and update self-state accordingly.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Dict, Any
|
||||
from .state import update_self_state
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def analyze_and_update_state(
|
||||
monologue: Dict[str, Any],
|
||||
user_prompt: str,
|
||||
response: str,
|
||||
context: Dict[str, Any]
|
||||
) -> None:
|
||||
"""
|
||||
Analyze interaction and update self-state.
|
||||
|
||||
This runs after response generation to update Lyra's internal state
|
||||
based on the interaction.
|
||||
|
||||
Args:
|
||||
monologue: Inner monologue output
|
||||
user_prompt: User's message
|
||||
response: Lyra's response
|
||||
context: Full context state
|
||||
"""
|
||||
|
||||
# Simple heuristics for state updates
|
||||
# TODO: Replace with LLM-based sentiment analysis in Phase 2
|
||||
|
||||
mood_delta = 0.0
|
||||
energy_delta = 0.0
|
||||
confidence_delta = 0.0
|
||||
curiosity_delta = 0.0
|
||||
new_focus = None
|
||||
|
||||
# Analyze intent from monologue
|
||||
intent = monologue.get("intent", "").lower() if monologue else ""
|
||||
|
||||
if "technical" in intent or "complex" in intent:
|
||||
energy_delta = -0.05 # Deep thinking is tiring
|
||||
confidence_delta = 0.05 if len(response) > 200 else -0.05
|
||||
new_focus = "technical_problem"
|
||||
|
||||
elif "creative" in intent or "brainstorm" in intent:
|
||||
mood_delta = 0.1 # Creative work is engaging
|
||||
curiosity_delta = 0.1
|
||||
new_focus = "creative_exploration"
|
||||
|
||||
elif "clarification" in intent or "confused" in intent:
|
||||
confidence_delta = -0.05
|
||||
new_focus = "understanding_user"
|
||||
|
||||
elif "simple" in intent or "casual" in intent:
|
||||
energy_delta = 0.05 # Light conversation is refreshing
|
||||
new_focus = "conversation"
|
||||
|
||||
# Check for learning opportunities (questions in user prompt)
|
||||
if "?" in user_prompt and any(word in user_prompt.lower() for word in ["how", "why", "what"]):
|
||||
curiosity_delta += 0.05
|
||||
|
||||
# Update state
|
||||
update_self_state(
|
||||
mood_delta=mood_delta,
|
||||
energy_delta=energy_delta,
|
||||
new_focus=new_focus,
|
||||
confidence_delta=confidence_delta,
|
||||
curiosity_delta=curiosity_delta
|
||||
)
|
||||
|
||||
logger.info(f"Self-state updated based on interaction: focus={new_focus}")
|
||||
Reference in New Issue
Block a user