#!/usr/bin/env python3
"""
GEP MCP Motor Control - Basic Usage Example
Author: Gary W. Floyd / Lumiea Systems Research Division
Paper: "Entropy-Guided Motor Control for Autonomous Tool Execution"
"""
from gep_mcp_motor import GEPMotorNeuron
import sys
def main():
# Initialize motor neuron
# Connection string from environment or config file
db_conn = "postgresql://nexus_mcp:password@localhost/gep_mcp_v2"
print("Initializing GEP Motor Neuron...")
motor = GEPMotorNeuron(db_conn_string=db_conn)
# Example 1: Check system health
print("\n=== Example 1: System Health Check ===")
result = motor.execute_intent(
session_id="example_session_001",
operator_id="gary",
intent="check system health",
input_data={"verbose": True}
)
print(f"Action: {result['action']}")
print(f"Outcome: {result['outcome']}")
print(f"Tool: {result['tool_name']}")
print(f"GEP Metrics:")
print(f" Entropy Before: {result['gep_metrics']['entropy_before']:.3f}")
print(f" Entropy After: {result['gep_metrics']['entropy_after']:.3f}")
print(f" Delta S: {result['gep_metrics']['delta_s']:.3f}")
print(f" Alignment: {result['gep_metrics']['alignment']:.3f}")
if result['outcome'] == 'ok':
print(f"\nOutput: {result['output']}")
# Example 2: View logs
print("\n=== Example 2: View System Logs ===")
result = motor.execute_intent(
session_id="example_session_001",
operator_id="gary",
intent="view system logs",
input_data={"lines": 20, "priority": "info"}
)
print(f"Action: {result['action']}")
print(f"Outcome: {result['outcome']}")
print(f"Entropy: {result['gep_metrics']['entropy_after']:.3f}")
# Example 3: Get tool statistics
print("\n=== Tool Performance Statistics ===")
stats = motor.get_tool_stats()
for stat in stats:
print(f"\n{stat['name']}:")
print(f" Uses: {stat['uses_total']}")
print(f" Success Rate: {stat['success_rate']:.2%}")
print(f" Current Entropy: {stat['current_entropy']:.3f}")
print(f" Avg Latency: {stat['avg_latency_ms']:.0f}ms")
# Example 4: View recent events
print("\n=== Recent Events ===")
events = motor.get_recent_events(limit=5)
for event in events:
print(f"\n{event['ts']}: {event['tool_name']}")
print(f" Action: {event['action']}, Outcome: {event['outcome']}")
print(f" Entropy: {event['entropy_before']:.3f} → {event['entropy_after']:.3f}")
print(f" Delta S: {event['delta_s']:.3f}")
motor.close()
print("\n=== Complete ===")
if __name__ == '__main__':
main()