Skip to content

Latest commit

Β 

History

History
164 lines (129 loc) Β· 5.78 KB

File metadata and controls

164 lines (129 loc) Β· 5.78 KB

Technical Deep-Dive: Agent Chat Static Response Issue

Problem Statement

Agents in MODUS v9.5.0 are giving static, pre-scripted responses instead of dynamic LLM-generated conversations, making them appear less "conscious" and more like chatbots.

Code Flow Analysis

1. Chat Request Path

User Input β†’ LiveView β†’ WorldChannel β†’ Protocol.Bridge β†’ LlmProvider β†’ Response

2. Key Components Investigation

A. Protocol.Bridge (Main Orchestrator)

File: /lib/modus/protocol/bridge.ex Function: process/3

Critical Finding: Multiple fallback layers cause static responses:

  1. Rate Limiting Check (Line 60-62):
rate_limited?(agent_id) ->
  {:ok, "*#{agent_name} holds up a hand, still thinking about the last thing you said.*"}
  • Issue: 3-second rate limit per agent
  • Impact: With 3,449 agents and user interactions, high chance of rate limiting
  • User Experience: Appears as broken/robotic behavior
  1. LLM Failure Cascade (Lines 234-263):
case config.provider do
  :gemini -> GeminiClient.chat_completion_direct(messages, config)
  # If fails β†’ Gemini direct fallback
  # If fails β†’ hardcoded fallback_reply(agent)
end

B. Fallback Response Generation

Static Response Patterns Found:

  1. personality_fallback/1 (Lines 277-308):
# Extraversion-based responses
extraversion < 0.3 -> "*#{name} looks at you thoughtfully but says nothing.*"
current_action in [:gathering, :exploring] -> "*#{name} seems too focused to respond.*"
neuroticism > 0.7 -> "*#{name} fidgets nervously and doesn't quite manage a response.*"
  1. fallback_reply/1 (Lines 310-375):
def fallback_reply(agent) do
  greeting = pick_greeting(personality)
  mood = mood_expression(affect_state, needs)  
  activity = activity_description(current_action, personality)
  "#{greeting} #{mood} #{activity}"
end

3. Root Cause Analysis

Primary Causes:

  1. Scale Performance Issues:

    • 3,449 agents overwhelming tick system (226ms vs 10ms target)
    • LLM provider rate limits at scale
    • Memory pressure affecting response times
  2. Aggressive Fallback Logic:

    • Rate limiting triggering too frequently
    • LLM failure chain too quick to fallback
    • No distinction between temporary vs permanent failures
  3. Missing Context Awareness:

    • Rate limit responses don't consider conversation context
    • Fallbacks don't maintain conversation coherence
    • No user feedback about system state

Secondary Issues:

  1. Cache Behavior: 30-second TTL may serve stale responses
  2. Error Handling: Silent fallbacks mask actual problems
  3. User Interface: No indication of LLM vs fallback responses

Evidence from Production Environment

Performance Metrics Observed:

  • Tick Lag: 119-226ms (target: 10ms)
  • Agent Count: 3,449 active agents
  • Rate Limit Window: 3 seconds per agent
  • LLM Provider: Gemini API configured

Log Analysis Patterns:

[warning] Tick lag detected: tick #8871580 took 185ms (interval: 10ms, agents: 3449, streak: 1)
[debug] LLM idle skip: 10 agents unchanged, 0 need decisions  
[info] MODUS chat_agent received: agent_id=123 message="Hello"
[warning] Bridge: primary LLM failed, trying Gemini direct fallback

Impact Assessment

User Experience Issues:

  1. Broken Immersion: Static responses break the illusion of conscious agents
  2. Inconsistent Behavior: Some agents respond dynamically, others statically
  3. No Feedback: Users don't understand why agents seem "dumb" sometimes

Technical Debt:

  1. Scaling Problems: Current architecture doesn't handle 3k+ agents gracefully
  2. Observability Gap: No monitoring of LLM success/failure rates
  3. UX Regression: Fallbacks designed for rare failures now common

Proposed Solutions

Immediate (Sprint 1):

  1. Rate Limit UX Fix:

    # Instead of generic fallback
    rate_limited?(agent_id) ->
      {:ok, "*#{agent_name} is still processing your last message... (thinking)*"}
  2. LLM Status Indicators:

    • Add response_type: :ai | :fallback to chat replies
    • Surface this to UI with visual indicators

Short-term (Sprint 2-3):

  1. Performance Optimization:

    • Implement agent hibernation for inactive agents
    • Batch LLM requests to reduce API pressure
    • Circuit breaker pattern for LLM failures
  2. Smart Fallbacks:

    • Context-aware fallback responses
    • Escalating fallback strategy (cache β†’ personality β†’ static)
    • User notification of system issues

Long-term (Sprint 4+):

  1. Architecture Improvements:
    • Multi-tier agent system (active/inactive/background)
    • Distributed LLM provider support
    • Advanced caching strategies

Testing Strategy

Validation Methods:

  1. Response Type Tracking: Monitor AI vs fallback ratio
  2. Performance Profiling: Measure LLM response times under load
  3. User Testing: A/B test fallback messaging strategies
  4. Load Testing: Agent count vs chat quality correlation

Success Metrics:

  • LLM response rate >80% (currently estimated <30%)
  • Average response time <3 seconds
  • User satisfaction with chat interactions
  • Tick performance <50ms with 3k+ agents

Conclusion

The "static response problem" is primarily a performance and scale issue, not a fundamental AI capability problem. The Spinoza Mind Engine and conscious chat system are architecturally sound but being overwhelmed by scale.

Priority: Critical - impacts core product value proposition Complexity: High - requires both performance optimization and UX redesign
Timeline: 3-4 sprints for full resolution with incremental improvements possible

The solution requires both technical optimization and user experience improvements to maintain the illusion of consciousness even when the system is under stress.