# Cognitive Architectures

From classic cognitive science to modern neural-symbolic agents.

---

## Classic Cognitive Architectures

### Soar (State, Operator, And Result)
| Component | Description |
|---|---|
| **Working Memory** | Current state (symbolic) |
| **Long-term Memory** | Procedural (rules), Semantic, Episodic |
| **Decision Cycle** | Input → Propose → Decide → Apply → Output |
| **Learning** | Chunking (compile sequences into rules) |
| **Subgoaling** | Automatic when knowledge incomplete |

**Agent relevance**: Explicit separation of memory systems, automatic subgoaling, chunking as skill acquisition.

### ACT-R (Adaptive Control of Thought—Rational)
| Module | Function |
|---|---|
| **Goal** | Current intention stack |
| **Declarative Memory** | Facts (chunks with activation) |
| **Procedural Memory** | Production rules (if-then) |
| **Perceptual/Motor** | Interface to world |
| **Subsymbolic** | Activation, utility, latency (quantitative) |

**Key equation**: Activation = Base-level + Spread + Partial matching
- Base-level = log(frequency × recency)
- Explains human forgetting/practice curves

### LIDA (Learning Intelligent Distribution Agent)
| Cycle Phase | Description |
|---|---|
| **Understanding** | Perceive → activate memory |
| **Attention** | Competition for consciousness (global workspace) |
| **Action Selection** | Procedural memory matches conscious content |
| **Learning** | Reinforcement, perceptual, episodic |

---

## Modern Neural-Symbolic Architectures

### Neuro-Symbolic Integration Spectrum
```
Pure Neural ←────────────────────────────────────────→ Pure Symbolic
     │                                                      │
     ▼                                                      ▼
LLM only                                            Logic/Planner
     │                                                      │
     ▼                                                      ▼
LLM + Tools                                        LLM-guided search
     │                                                      │
     ▼                                                      ▼
Neural Theorem Prover                           Neurosymbolic DSL
     │                                                      │
     ▼                                                      ▼
AlphaGeometry                                   Program Synthesis
```

### Integration Patterns
| Pattern | Neural Role | Symbolic Role | Example |
|---|---|---|---|
| **Neural Guidance** | Propose actions, score | Validate, execute, search | AlphaGo, AlphaGeometry |
| **Symbolic Grounding** | Perceive, embed | Reason, plan | LLM + PDDL planner |
| **Hybrid Representation** | Vector + graph | Explicit relations | Knowledge Graph + LLM |
| **Compilation** | Learn → distill to rules | Execute fast | Chunking (Soar), Distillation |
| **Verification** | Generate candidates | Prove/check correctness | Lean + LLM, Prolog + LLM |

---

## Key Modern Architectures

### 1. LLM + Classical Planner
```python
class NeuroSymbolicAgent:
    def __init__(self):
        self.llm = LLM()
        self.planner = PDDLPlanner()  # Fast Downward, etc.
    
    def act(self, goal, state):
        # LLM translates natural language → PDDL problem
        pddl_problem = self.llm.translate_to_pddl(goal, state)
        # Symbolic planner finds optimal plan
        plan = self.planner.solve(pddl_problem)
        # LLM translates plan → executable steps
        return self.llm.translate_plan(plan)
```

### 2. LLM + Constraint Solver / SAT
- **Use case**: Scheduling, resource allocation, code synthesis
- **Pattern**: LLM generates constraints → Z3/SAT solves → LLM interprets
- **Tools**: Z3, OR-Tools, MiniZinc, Picat

### 3. Program Synthesis / Inductive Programming
- **DreamCoder** — Wake-sleep: neural proposes, symbolic verifies, library learning
- **CrossBeam** — Neural guides symbolic search
- **Applications**: DSL synthesis, API sequence generation, SQL

### 4. Neural Theorem Proving
- **Lean + LLM** — LLM suggests tactics, Lean verifies
- **Isabelle + LLM** — Similar pattern
- **Autoformalization** — Natural language → formal proof

### 5. Neuro-Symbolic DSLs
| DSL | Domain | Neural Integration |
|---|---|---|
| **PDDL** | Planning | LLM → PDDL |
| **SQL** | Databases | Text-to-SQL |
| **Regex/Grammars** | Parsing | LLM → regex |
| **GraphQL/REST** | APIs | LLM → queries |
| **Terraform/Pulumi** | Infra | LLM → IaC |

---

## Memory in Cognitive Architectures

| Architecture | Working Memory | Long-term Memory | Learning |
|---|---|---|---|
| **Soar** | Symbolic state graph | Procedural (rules), Semantic, Episodic | Chunking |
| **ACT-R** | Buffers (goal, imaginal, etc.) | Declarative (chunks), Procedural | Base-level learning, production compilation |
| **LIDA** | Workspace (conscious) | Perceptual, Episodic, Procedural | Reinforcement, Hebbian |
| **Generative Agents** | Context window | Vector store + reflection | Reflection → importance → retrieval |
| **MemGPT** | Context window (paged) | Disk (SQLite/Vector) | Virtual memory management |

---

## Reasoning Systems Comparison

| System | Paradigm | Strengths | Limitations |
|---|---|---|---|
| **LLM CoT** | Neural | Flexible, natural language | Unreliable, no guarantees |
| **PDDL Planner** | Symbolic | Optimal, complete, verifiable | Requires formalization |
| **SAT/SMT** | Symbolic | Exact, constraint solving | NP-hard, modeling effort |
| **Prolog/Datalog** | Logic | Recursive, deductive | Closed world, no uncertainty |
| **Probabilistic Prog** | Bayesian | Uncertainty, learning | Inference complexity |
| **Neural-Symbolic** | Hybrid | Best of both | Integration complexity |

---

## Implementing Neural-Symbolic Agents

### Architecture Template
```python
class NeuroSymbolicAgent:
    def __init__(self):
        # Neural components
        self.perception = MultimodalEncoder()
        self.reasoning = LLM()
        self.critic = LLM()  # For reflection/verification
        
        # Symbolic components
        self.planner = PDDLPlanner()
        self.solver = Z3Solver()
        self.knowledge_graph = GraphDB()
        self.skill_library = SkillRegistry()
        
        # Integration
        self.grounding = NeuralSymbolicGrounding()
        self.compiler = SkillCompiler()  # Neural → Symbolic
    
    def run(self, goal):
        # 1. Perceive & Ground
        state = self.perception.observe()
        symbolic_state = self.grounding.to_symbolic(state)
        
        # 2. Plan (Symbolic)
        plan = self.planner.solve(goal, symbolic_state)
        
        # 3. Execute with Neural Monitoring
        for step in plan:
            # Neural proposes concrete action
            action = self.reasoning.propose_action(step, state)
            # Symbolic validates
            if not self.solver.validate(action, symbolic_state):
                action = self.repair(action)
            # Execute
            result = self.execute(action)
            
            # Neural reflects
            critique = self.critic.reflect(step, result)
            if critique.learns_skill:
                self.compiler.compile(critique)  # Distill to skill
        
        return result
```

---

## When to Use Neural-Symbolic

| Use Neural-Symbolic When | Pure LLM OK When |
|---|---|
| Correctness critical (finance, medical, safety) | Creative, open-ended |
| Complex constraints (scheduling, logistics) | Simple QA, chat |
| Verifiable reasoning needed | Exploration, brainstorming |
| Long-horizon planning | Short tasks |
| Skill reuse across tasks | One-off tasks |
| Regulatory explainability required | Internal tools |

---

## Related Notes

- [[Foundations/Core-Abstractions.md]] — Core building blocks
- [[Architectures/Single-Agent-Patterns.md]] — ReAct, Plan-and-Execute as neural patterns
- [[Architectures/Control-Flow.md]] — Execution control structures
- [[ModelArchitectures/Reasoning-Models.md]] — o1, CoT, ToT as neural reasoning
- [[Frontiers/Neurosymbolic-Integration.md]] — Deep dive on integration
- [[Frontiers/Formal-Verification.md]] — Proof-carrying agents
- [[Domains/Coding-Agents.md]] — Program synthesis, verification
- [[Domains/Scientific-Agents.md]] — Theorem proving, discovery

---

*Sources: Soar (Laird), ACT-R (Anderson), LIDA (Franklin), "Neuro-Symbolic AI" (Garcez et al.), "AlphaGeometry" (Trinh et al.), "DreamCoder" (Ellis et al.), "Lean + LLM" (First et al.), "Generative Agents" (Park et al.), "MemGPT" (Packer et al.), PDDL, Z3, OR-Tools docs.*