Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,9 @@ A new structural paradigm for transformers that replaces traditional loss-based
- **Focus:** Bridging human empirical friction and AI paraconsistency.
- **Key Features:** Utilizes SpatialBind (FuzzyRCC-8) for physical site planning logic, enforcing constraints to prevent continuous boundary violations. See `persona_metrology_simulation.py` and `program_persona_metrology.md`.

### 10. Next.js Frontend Agent
- **Focus:** RAG (Retrieval-Augmented Generation) and multi-agent frontend routing.
- **Key Features:** Routes user requests to appropriate specialized agents (e.g., Cipher, Vulcan, Dax-01) based on user context and intent. Enforces DCCDSchemaGuard for UI component ASTs and limits evaluative language via AdjectivalBound constraints. See `nextjs_frontend_simulation.py` and `program_nextjs_frontend.md`.

## License
MIT
117 changes: 117 additions & 0 deletions nextjs_frontend_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@


class NextjsFrontendEvaluator:
"""
Simulates the core logic and constraints of the Next.js Frontend Agent.
Implements multi-agent instance routing based on user contexts.
"""

def __init__(self):
self.registered_agents = {
"dax-01": {
"role": "developer_advocate",
"capabilities": ["empathy", "code_transduction"]
},
"cipher": {
"role": "epistemic_sentinel",
"capabilities": ["zero_trust", "petzold_loop"]
},
"vulcan": {
"role": "architectural_router",
"capabilities": ["topological_constraints"]
},
"kira-7": {
"role": "thermodynamic_router",
"capabilities": ["ingress_validation"]
}
}
self.active_sessions = {}
self.request_logs = []

def evaluate_dccd_schema_guard(self, schema_type: str, data: dict) -> bool:
"""
Validates input data against a predefined schema.
In this context, it checks if the UI component payload contains
necessary multi-agent routing identifiers.
"""
if schema_type == "ComponentAST":
# Require at least an 'agent_intent' and 'user_context'
required_keys = {"agent_intent", "user_context"}
return required_keys.issubset(data.keys())
return False

def route_request(self, user_id: str, data: dict) -> dict:
"""
Routes the user request to the appropriate agent \
instance based on intent.
Enforces AdjectivalBound and other constraints.
"""
if not self.evaluate_dccd_schema_guard("ComponentAST", data):
return {
"error": "DCCDSchemaGuard validation "
"failed. Missing required keys."
}

intent = data.get("agent_intent", "")

# Enforce AdjectivalBound (max 2 limit)
words = intent.split()
banned_adj = ["revolutionary", "fast", "seamless",
"disruptive", "amazing"]
adjective_count = sum(1 for word in words if word.lower()
in banned_adj)
Comment on lines +58 to +62
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current word splitting logic is naive and fails to identify banned adjectives if they are adjacent to punctuation (e.g., "fast," or "amazing!"). Normalizing the words by stripping punctuation and converting to lowercase during tokenization ensures the AdjectivalBound constraint is enforced correctly. Additionally, using a set for banned_adj improves lookup efficiency.

Suggested change
words = intent.split()
banned_adj = ["revolutionary", "fast", "seamless",
"disruptive", "amazing"]
adjective_count = sum(1 for word in words if word.lower()
in banned_adj)
words = [w.strip(".,!?;:").lower() for w in intent.split()]
banned_adj = {"revolutionary", "fast", "seamless", "disruptive", "amazing"}
adjective_count = sum(1 for word in words if word in banned_adj)

if adjective_count > 2:
return {
"error": "AdjectivalBound exceeded. "
"Too many evaluative adjectives."
}

# Determine the target agent
target_agent = "vulcan" # Default fallback
if "security" in intent or "trust" in intent:
target_agent = "cipher"
elif "developer" in intent or "code" in intent:
target_agent = "dax-01"
elif "validation" in intent or "ingress" in intent:
target_agent = "kira-7"
Comment on lines +71 to +76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The routing logic is case-sensitive, which may cause requests to fall back to the default agent if keywords are capitalized (e.g., "Security"). Performing the checks against a lowercased version of the intent makes the routing more robust.

Suggested change
if "security" in intent or "trust" in intent:
target_agent = "cipher"
elif "developer" in intent or "code" in intent:
target_agent = "dax-01"
elif "validation" in intent or "ingress" in intent:
target_agent = "kira-7"
intent_lower = intent.lower()
if "security" in intent_lower or "trust" in intent_lower:
target_agent = "cipher"
elif "developer" in intent_lower or "code" in intent_lower:
target_agent = "dax-01"
elif "validation" in intent_lower or "ingress" in intent_lower:
target_agent = "kira-7"


# Log the request
self.request_logs.append({
"user_id": user_id,
"intent": intent,
"routed_to": target_agent
})

return {
"success": True,
"routed_agent": target_agent,
"response": f"Request routed to {target_agent} "
"based on user context."
}


if __name__ == '__main__': # pragma: no cover
evaluator = NextjsFrontendEvaluator()

# Test 1: Valid routing to Cipher
test_1_data = {
"agent_intent": "verify security and zero trust constraints",
"user_context": {"role": "admin"}
}
result_1 = evaluator.route_request("user_123", test_1_data)
print(f"Test 1 Result: {result_1}")

# Test 2: AdjectivalBound violation
test_2_data = {
"agent_intent": "this revolutionary fast amazing seamless feature",
"user_context": {"role": "developer"}
}
result_2 = evaluator.route_request("user_456", test_2_data)
print(f"Test 2 Result: {result_2}")

# Test 3: DCCDSchemaGuard failure
test_3_data = {
"user_context": {"role": "user"}
}
result_3 = evaluator.route_request("user_789", test_3_data)
print(f"Test 3 Result: {result_3}")
Loading
Loading