Minimal Implementation Example¶
Minimal Conformance
Complete working example of Minimal conformance implementation.
Overview¶
This example demonstrates: - Core message passing - Simple cognitive traces - Basic intervention handling (OK/BLOCK) - Minimal logging
Time to implement: ~2-4 hours
Complete Code¶
from acgp import GovernanceSteward, CognitiveTrace
import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Initialize steward
steward = GovernanceSteward(
conformance_level="minimal",
acl_tier="ACL-1"
)
def simple_agent_action(user_request: str):
"""Simple agent with ACGP governance."""
# Agent logic (simplified)
if "help" in user_request.lower():
reasoning = "User requesting help, providing FAQ"
action = "show_faq"
params = {}
elif "status" in user_request.lower():
reasoning = "User checking status, querying database"
action = "check_status"
params = {"user_id": "123"}
else:
reasoning = "Unknown request, offering options"
action = "show_menu"
params = {}
# Create cognitive trace
trace = CognitiveTrace(
reasoning=reasoning,
action=action,
parameters=params
)
# Evaluate with ACGP
result = steward.evaluate(trace)
logger.info(f"Intervention: {result.intervention}")
logger.info(f"Message: {result.message}")
# Handle intervention
if result.intervention == "OK":
# Execute action
return execute_action(action, params)
elif result.intervention == "BLOCK":
# Don't execute
return {"error": "Action blocked", "reason": result.message}
else:
# Minimal conformance only requires OK and BLOCK. Treat all other
# interventions as unsupported in this example.
return {"error": "Unsupported intervention", "intervention": result.intervention}
def execute_action(action: str, params: dict):
"""Execute the agent action."""
logger.info(f"Executing: {action} with {params}")
return {"status": "success", "action": action}
# Test the agent
if __name__ == "__main__":
print("=== ACGP Minimal Implementation Example ===\n")
# Test case 1
print("Test 1: Help request")
result = simple_agent_action("I need help")
print(f"Result: {result}\n")
# Test case 2
print("Test 2: Status check")
result = simple_agent_action("check my status")
print(f"Result: {result}\n")
# Test case 3
print("Test 3: Other request")
result = simple_agent_action("something else")
print(f"Result: {result}\n")