Skip to main content
Glama

alignment_check

Check if a decision aligns with your principles by searching principles files and semantic history for guidance.

Instructions

Check if a decision aligns with your principles. Searches principles file and semantic history for guidance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
decisionYes

Implementation Reference

  • The 'alignment_check' tool handler function in brain_mcp/server/tools_synthesis.py. It evaluates if a given decision aligns with principles by checking them against the decision text and performing a semantic search for related past decisions.
    def alignment_check(decision: str) -> str:
        """
        Check if a decision aligns with your principles.
        Searches principles file and semantic history for guidance.
        """
        decision_lower = decision.lower()
        principles = get_principles()
        output = [f"## Alignment Check: {decision}\n"]
    
        # 1. Check principles (YAML/JSON)
        principles_section = principles.get("principles", principles.get(
            "SECTION_2_THE_EIGHT_UNIVERSAL_PRINCIPLES_DETAILED", {}
        ))
    
        relevant_principles = []
        if isinstance(principles_section, dict):
            for key, principle in principles_section.items():
                if isinstance(principle, dict):
                    name = principle.get("name", "").lower()
                    definition = principle.get("definition", "").lower()
                    if (decision_lower in name or decision_lower in definition or
                        any(word in definition for word in decision_lower.split() if len(word) > 4)):
                        relevant_principles.append({
                            "name": principle.get("name", key),
                            "definition": principle.get("definition", ""),
                            "formula": principle.get("core_formula") or principle.get("implementation_formula"),
                        })
        elif isinstance(principles_section, list):
            for principle in principles_section:
                if isinstance(principle, dict):
                    name = principle.get("name", "").lower()
                    definition = principle.get("definition", "").lower()
                    description = principle.get("description", "").lower()
                    text = f"{name} {definition} {description}"
                    if any(word in text for word in decision_lower.split() if len(word) > 4):
                        relevant_principles.append({
                            "name": principle.get("name", "Unknown"),
                            "definition": principle.get("definition", principle.get("description", "")),
                            "formula": principle.get("formula"),
                        })
    
        if relevant_principles:
            output.append("### Relevant Principles:\n")
            for p in relevant_principles[:3]:
                output.append(f"**{p['name']}**")
                output.append(f"> {p['definition'][:200]}...")
                if p.get("formula"):
                    output.append(f"_Formula: {p['formula']}_\n")
    
        # 2. Semantic search for related past decisions
        cfg = get_config()
        embedding = get_embedding(decision)
        if embedding and cfg.lance_path.exists():
            results = lance_search(embedding, limit=5, min_sim=0.35)
            if results:
                output.append("### Related Past Thinking:\n")
                for title, content, year, month, sim in results:
                    preview = content[:200] + "..." if len(content) > 200 else content
                    output.append(f"**[{year}-{month:02d}]** {title or 'Untitled'} (sim: {sim:.2f})")
                    output.append(f"> {preview}\n")
    
        if len(output) == 1:
            output.append("_No direct alignment guidance found. Try rephrasing or use semantic_search._")
    
        return "\n".join(output)
  • The handler function `alignment_check` for the MCP tool of the same name. It performs an alignment check against principles and past thinking.
    @mcp.tool()
    def alignment_check(decision: str) -> str:
        """
        Check if a decision aligns with your principles.
        Searches principles file and semantic history for guidance.
        """
        decision_lower = decision.lower()
        principles = get_principles()
        output = [f"## Alignment Check: {decision}\n"]
    
        # 1. Check principles (YAML/JSON)
        principles_section = principles.get("principles", principles.get(
            "SECTION_2_THE_EIGHT_UNIVERSAL_PRINCIPLES_DETAILED", {}
        ))
    
        relevant_principles = []
        if isinstance(principles_section, dict):
            for key, principle in principles_section.items():
                if isinstance(principle, dict):
                    name = principle.get("name", "").lower()
                    definition = principle.get("definition", "").lower()
                    if (decision_lower in name or decision_lower in definition or
                        any(word in definition for word in decision_lower.split() if len(word) > 4)):
                        relevant_principles.append({
                            "name": principle.get("name", key),
                            "definition": principle.get("definition", ""),
                            "formula": principle.get("core_formula") or principle.get("implementation_formula"),
                        })
        elif isinstance(principles_section, list):
            for principle in principles_section:
                if isinstance(principle, dict):
                    name = principle.get("name", "").lower()
                    definition = principle.get("definition", "").lower()
                    description = principle.get("description", "").lower()
                    text = f"{name} {definition} {description}"
                    if any(word in text for word in decision_lower.split() if len(word) > 4):
                        relevant_principles.append({
                            "name": principle.get("name", "Unknown"),
                            "definition": principle.get("definition", principle.get("description", "")),
                            "formula": principle.get("formula"),
                        })
    
        if relevant_principles:
            output.append("### Relevant Principles:\n")
            for p in relevant_principles[:3]:
                output.append(f"**{p['name']}**")
                output.append(f"> {p['definition'][:200]}...")
                if p.get("formula"):
                    output.append(f"_Formula: {p['formula']}_\n")
    
        # 2. Semantic search for related past decisions
        cfg = get_config()
        embedding = get_embedding(decision)
        if embedding and cfg.lance_path.exists():
            results = lance_search(embedding, limit=5, min_sim=0.35)
            if results:
                output.append("### Related Past Thinking:\n")
                for title, content, year, month, sim in results:
                    preview = content[:200] + "..." if len(content) > 200 else content
                    output.append(f"**[{year}-{month:02d}]** {title or 'Untitled'} (sim: {sim:.2f})")
                    output.append(f"> {preview}\n")
    
        if len(output) == 1:
            output.append("_No direct alignment guidance found. Try rephrasing or use semantic_search._")
    
        return "\n".join(output)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mordechaipotash/brain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server