Skip to content

Commit 8fee457

Browse files
author
Arena AI Agent
committed
feat(l2): 🧠 redesign experts into dynamic Neuro-Symbolic engines (Hegelian, Rigor Sentinel, Chain of Density)
1 parent 43ab6b1 commit 8fee457

4 files changed

Lines changed: 99 additions & 153 deletions

File tree

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
"""Dialectic expert — philosophy/research tension mapping."""
2-
3-
from __future__ import annotations
4-
5-
from typing import Any, Dict
6-
7-
from epistemic_forge.models import ProjectSpec
8-
1+
"""L2 Epistemic Synthesis Engine: Hegelian Dialectic."""
2+
from epistemic_forge.models import ProjectSpec, HegelianDialecticOutput
3+
from epistemic_forge.llm import generate_structured
4+
from typing import Dict, Any
95

106
def run_dialectic(spec: ProjectSpec, claims_bundle: Dict[str, Any]) -> Dict[str, Any]:
11-
claims = claims_bundle.get("claims", [])
12-
thesis = claims[0]["text"] if claims else spec.question
7+
"""Execute Hegelian Synthesis to destroy weak assumptions."""
8+
thesis = spec.question
9+
10+
messages = [
11+
{"role": "system", "content": "You are a ruthless Hegelian philosopher and logician. Your goal is to take a premise, construct the most devastating 'Steelman' antithesis possible, and forge a synthesis that represents the nuanced truth."},
12+
{"role": "user", "content": f"Core Premise/Thesis: {thesis}\nProject Domain: {spec.domain.value}\nDestroy this premise with logic, then synthesize."}
13+
]
14+
15+
# Neuro-Symbolic Call: Forcing GPT to return the strict Hegelian schema
16+
result: HegelianDialecticOutput = generate_structured(
17+
messages=messages,
18+
response_model=HegelianDialecticOutput,
19+
model="gpt-4o-mini" # Cost-aware baseline
20+
)
21+
1322
return {
1423
"thesis": thesis,
15-
"antithesis": (
16-
f"Counter: the best path on «{spec.title}» may be local craft and tacit skill, "
17-
"not explicit lattices—over-formalization can freeze inquiry."
18-
),
19-
"steelman": (
20-
"Steelman of the counter: experts often succeed with pattern recognition under time "
21-
"pressure; forcing explicit structure can slow delivery and invent false precision."
22-
),
23-
"synthesis": (
24-
"Use a *light* claim lattice as a scaffold, not a cage: make assumptions and "
25-
"objections legible, then ship the smallest artifact that can be falsified in the world."
26-
),
27-
"open_questions": [
28-
"What is the cheapest falsifying observation?",
29-
"Who is harmed if we are wrong?",
30-
"What would count as enough certainty to act?",
31-
],
24+
"antithesis": result.steelmanned_antithesis,
25+
"synthesis": result.synthesis_resolution,
26+
"open_questions": result.remaining_uncertainties,
3227
}
Lines changed: 26 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,29 @@
1-
"""Kaggle / applied ML expert."""
2-
3-
from __future__ import annotations
4-
5-
from typing import Any, Dict, List
6-
7-
from epistemic_forge.models import ProjectSpec
8-
9-
10-
def build_competition_kit(
11-
spec: ProjectSpec, claims_bundle: Dict[str, Any], skills: List[str]
12-
) -> Dict[str, Any]:
13-
notebook_md = f"""# {spec.title} — Kaggle Spine
14-
15-
## Problem
16-
{spec.question}
17-
18-
## Skills retrieved
19-
{', '.join(skills) or 'none'}
20-
21-
## Plan
22-
1. **Define target & metric** — match leaderboard metric exactly.
23-
2. **Leakage audit** — time, group, target leakage checks.
24-
3. **EDA** — missingness, cardinality, target balance, simple slices.
25-
4. **Baseline** — linear/GBDT simple pipeline; record CV mean±std.
26-
5. **Error analysis** — where does baseline fail?
27-
6. **One improvement** — single ablated idea; measure lift.
28-
7. **Ship** — reproducible seeds, requirements, README.
29-
30-
## Skeleton code
31-
```python
32-
import numpy as np
33-
import pandas as pd
34-
from sklearn.model_selection import StratifiedKFold, cross_val_score
35-
from sklearn.pipeline import Pipeline
36-
from sklearn.compose import ColumnTransformer
37-
from sklearn.preprocessing import OneHotEncoder
38-
from sklearn.impute import SimpleImputer
39-
from sklearn.ensemble import HistGradientBoostingClassifier
40-
41-
# df = pd.read_csv('train.csv')
42-
# y = df['target']
43-
# X = df.drop(columns=['target'])
44-
45-
# num_cols = X.select_dtypes(include='number').columns
46-
# cat_cols = X.select_dtypes(exclude='number').columns
47-
# pre = ColumnTransformer([
48-
# ('num', SimpleImputer(strategy='median'), num_cols),
49-
# ('cat', Pipeline([
50-
# ('imp', SimpleImputer(strategy='most_frequent')),
51-
# ('oh', OneHotEncoder(handle_unknown='ignore')),
52-
# ]), cat_cols),
53-
# ])
54-
# clf = Pipeline([('pre', pre), ('model', HistGradientBoostingClassifier(random_state=42))])
55-
# cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
56-
# scores = cross_val_score(clf, X, y, cv=cv, scoring='roc_auc')
57-
# print(scores.mean(), scores.std())
58-
```
59-
60-
## Honest claims checklist
61-
- [ ] Metric matches competition
62-
- [ ] Split policy documented
63-
- [ ] No target leakage features
64-
- [ ] Baseline before complexity
65-
"""
1+
"""L2 Epistemic Synthesis Engine: Leakage & Rigor Sentinel."""
2+
from epistemic_forge.models import ProjectSpec, RigorSentinelOutput
3+
from epistemic_forge.llm import generate_structured
4+
from typing import Dict, Any
5+
6+
def build_competition_kit(spec: ProjectSpec, claims_bundle: Dict[str, Any], skills: list) -> Dict[str, Any]:
7+
"""Audit the premise for epistemic blind spots and target leakage."""
8+
9+
messages = [
10+
{"role": "system", "content": "You are a Grandmaster ML Auditor. Your job is to look at a proposed research or data problem and identify 'target leakage'—where the answer is implicitly baked into the question—and propose strict falsification metrics."},
11+
{"role": "user", "content": f"Problem Statement: {spec.question}\nKeywords: {spec.keywords}\nFind the blind spots and establish a robust baseline."}
12+
]
13+
14+
# Neuro-Symbolic Call
15+
result: RigorSentinelOutput = generate_structured(
16+
messages=messages,
17+
response_model=RigorSentinelOutput,
18+
model="gpt-4o-mini"
19+
)
20+
6621
return {
67-
"checklist": [
68-
"metric alignment",
69-
"leakage audit",
70-
"baseline CV",
71-
"error analysis",
72-
"single ablation",
73-
],
74-
"notebook_markdown": notebook_md,
22+
"checklist": result.epistemic_blind_spots,
23+
"metric_alignment": result.falsification_metric,
24+
"baseline_architecture": result.robust_baseline,
7525
"experiment_log_template": {
76-
"run_id": "baseline_001",
77-
"model": "HGB",
78-
"cv_mean": None,
79-
"cv_std": None,
80-
"notes": "",
81-
},
26+
"status": "Audited by Rigor Sentinel",
27+
"notes": "Ensure no data from the future is used."
28+
}
8229
}
Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,28 @@
1-
"""Writing expert — outlines and drafts."""
2-
3-
from __future__ import annotations
4-
5-
from typing import Any, Dict, List
6-
7-
from epistemic_forge.models import ProjectSpec
8-
9-
10-
def outline_and_draft(
11-
spec: ProjectSpec, claims_bundle: Dict[str, Any], instruction: str
12-
) -> Dict[str, Any]:
13-
claims: List[Dict[str, Any]] = claims_bundle.get("claims", [])
14-
outline = [
15-
"Hook / stakes",
16-
"Core question",
17-
"Claim lattice",
18-
"Objections & steelman",
19-
"Working synthesis",
20-
"Limits",
21-
"Next actions",
1+
"""L2 Epistemic Synthesis Engine: Chain of Density Architect."""
2+
from epistemic_forge.models import ProjectSpec, ChainOfDensityOutput
3+
from epistemic_forge.llm import generate_structured
4+
from typing import Dict, Any
5+
6+
def outline_and_draft(spec: ProjectSpec, claims_bundle: Dict[str, Any], instruction: str) -> Dict[str, Any]:
7+
"""Compress the dialectic into a hyper-dense, falsifiable artifact."""
8+
9+
# Gather previous context to compress
10+
raw_context = f"Question: {spec.question}\nClaims: {claims_bundle.get('claims', [])}"
11+
12+
messages = [
13+
{"role": "system", "content": "You are a Chain-of-Density Architect. Your goal is to take raw thoughts and compress them into a highly dense, signal-rich artifact stripped of all rhetorical fluff and confident mush. Every word must carry epistemic weight."},
14+
{"role": "user", "content": f"Raw Context:\n{raw_context}\nCompress this."}
2215
]
23-
body_bits = []
24-
for c in claims:
25-
body_bits.append(f"### {c['id']}: {c['text']}\n")
26-
if c.get("support"):
27-
body_bits.append("Supports:\n" + "\n".join(f"- {s}" for s in c["support"]))
28-
if c.get("objections"):
29-
body_bits.append(
30-
"\nObjections:\n" + "\n".join(f"- {o}" for o in c["objections"])
31-
)
32-
body_bits.append("")
33-
34-
draft = f"""# {spec.title}
35-
36-
## Core question
37-
{spec.question}
38-
39-
## Instruction in force
40-
{instruction}
41-
42-
## Audience
43-
{spec.audience}
44-
45-
## Outline
46-
""" + "\n".join(f"{i+1}. {x}" for i, x in enumerate(outline)) + "\n\n## Claim lattice\n\n" + "\n".join(body_bits)
47-
48-
return {"outline": outline, "draft_markdown": draft}
16+
17+
# Neuro-Symbolic Call
18+
result: ChainOfDensityOutput = generate_structured(
19+
messages=messages,
20+
response_model=ChainOfDensityOutput,
21+
model="gpt-4o-mini"
22+
)
23+
24+
return {
25+
"density_score": result.information_density_score,
26+
"draft_markdown": f"# Crystallized Artifact\n\n{result.crystallized_claim}\n\n*Density Score: {result.information_density_score}/10*",
27+
"outline": ["Crystallized Core"]
28+
}

‎epistemic_forge/models.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,27 @@ class WritingExpertOutput(BaseModel):
143143
tone_consistency_score: float
144144
structural_flow: str
145145
draft_paragraphs: List[str]
146+
147+
148+
# ==========================================
149+
# L2 SYNTHESIS ENGINE SCHEMAS (NEURO-SYMBOLIC)
150+
# ==========================================
151+
from pydantic import BaseModel, Field
152+
from typing import List
153+
154+
class RigorSentinelOutput(BaseModel):
155+
"""Strict schema for the Leakage & Rigor Sentinel (formerly Kaggle Expert)."""
156+
epistemic_blind_spots: List[str] = Field(description="Hidden assumptions or target leakage risks in the user's premise.")
157+
falsification_metric: str = Field(description="The exact mathematical or logical metric that would prove this premise wrong.")
158+
robust_baseline: str = Field(description="A highly resilient, low-complexity baseline approach.")
159+
160+
class HegelianDialecticOutput(BaseModel):
161+
"""Strict schema for the Hegelian Synthesis Engine."""
162+
steelmanned_antithesis: str = Field(description="The absolute strongest possible argument against the core thesis.")
163+
synthesis_resolution: str = Field(description="The nuanced truth that reconciles the thesis and the antithesis.")
164+
remaining_uncertainties: List[str] = Field(description="Questions that still lack sufficient evidence.")
165+
166+
class ChainOfDensityOutput(BaseModel):
167+
"""Strict schema for the Chain of Density Architect."""
168+
information_density_score: float = Field(ge=0.0, le=10.0, description="Score of how dense the signal-to-noise ratio is.")
169+
crystallized_claim: str = Field(description="The final, hyper-dense output stripped of all filler words.")

0 commit comments

Comments
 (0)