# dream-cycle

**AI Research Scanner + Improvement Proposal Generator**

Scans AI research (arXiv, GitHub trending) nightly and generates improvement proposals for your agent system.

## What It Does

Every night (or on-demand):
1. **Scans arXiv** — AI/ML papers from last 7 days
2. **Checks GitHub trending** — AI/ML repos with recent activity
3. **Filters by relevance** — Embedding-based matching to your focus areas
4. **Generates proposals** — Uses LLM to suggest improvements
5. **Commits to git** — Daily reports in `dream-cycle/YYYY-MM-DD.md`
6. **Sends summary** — Telegram/Discord notification

## Why This Exists

**Problem:** AI research moves fast. New techniques, libraries, and patterns emerge weekly.

**Manual solution:** Manually check arXiv, GitHub, Twitter daily. Time-consuming and inconsistent.

**Automated solution:** Dream Cycle runs nightly, brings you the signal, filters the noise.

## Installation

```bash
# 1. Install the skill
openclaw skill install dream-cycle

# 2. Install Python dependencies
cd ~/.openclaw/skills/dream-cycle
pip install -r requirements.txt

# 3. Schedule it (optional)
openclaw cron add --name "Dream Cycle" \
  --schedule "0 2 * * *" \  # 2 AM daily
  --command "python ~/.openclaw/skills/dream-cycle/scripts/dream-cycle.py"
```

## Usage

### Manual Run

```bash
python ~/.openclaw/skills/dream-cycle/scripts/dream-cycle.py
```

### OpenClaw Cron (Recommended)

```bash
openclaw cron add --name "Dream Cycle" \
  --schedule "0 2 * * *" \
  --payload '{
    "kind": "agentTurn",
    "message": "Run dream cycle",
    "timeoutSeconds": 600
  }' \
  --sessionTarget "isolated"
```

### Via Agent

Just ask your agent:

> "Run dream cycle"

Or:

> "What's new in AI research?"

## Configuration

Set via environment variables:

```bash
# Focus areas (comma-separated)
export DREAM_CYCLE_FOCUS="agent orchestration,RAG,voice agents"

# LLM provider (github-models, openai, anthropic, local)
export DREAM_CYCLE_LLM_PROVIDER="github-models"

# Output directory
export DREAM_CYCLE_OUTPUT_DIR="dream-cycle"

# arXiv categories
export DREAM_CYCLE_ARXIV_CATEGORIES="cs.AI,cs.CL,cs.LG,cs.MA"

# arXiv days back
export DREAM_CYCLE_ARXIV_DAYS="7"

# GitHub topics
export DREAM_CYCLE_GITHUB_TOPICS="ai-agents,llm,rag,agent-framework"

# GitHub minimum stars
export DREAM_CYCLE_GITHUB_MIN_STARS="100"

# Use embeddings for relevance filtering (auto/yes/no)
export DREAM_CYCLE_USE_EMBEDDINGS="auto"

# Embedding model
export DREAM_CYCLE_EMBEDDING_MODEL="all-MiniLM-L6-v2"
```

## Output Format

Daily reports: `dream-cycle/YYYY-MM-DD.md`

```markdown
# Dream Cycle Report - 2026-03-31

## Research Papers (3 found)

### Paper 1: "Hierarchical Agent Orchestration with Meta-Planning"
**Authors:** Smith et al.  
**Link:** https://arxiv.org/abs/2403.12345  
**Relevance:** 0.87  

**Summary:**
Introduces meta-planning layer for multi-agent coordination...

**Key Ideas:**
- Hierarchical task decomposition
- Dynamic agent allocation
- Cost-based routing

**Potential Application:**
Could improve OpenClaw's sub-agent orchestration...

**Feasibility:** High (pure Python, no new deps)  
**Safety:** Medium (meta-planner could create infinite loops)  
**Impact:** High (reduces latency by 40% in benchmarks)

---

## GitHub Repos (2 found)

### Repo 1: awesome-agent-tools
**Link:** https://github.com/user/awesome-agent-tools  
**Stars:** 1.2K  
**Relevance:** 0.92

**Description:**
Curated list of agent development tools...

**Why It Matters:**
Lists 15 tools we don't use yet...

---

## Proposals (5 generated)

### Proposal 1: Add meta-planning layer
**Feasibility:** 7/10  
**Safety:** 6/10  
**Impact:** 9/10

**Description:**
Implement hierarchical task decomposition from Smith et al. paper...

**Implementation Notes:**
1. Add `meta-planner.py` module
2. Integrate with existing subagent system
3. Add cost-based routing logic

**Risks:**
- Infinite loop if meta-planner calls itself
- Increased latency for simple tasks

**Next Steps:**
1. Prototype meta-planner in isolated branch
2. Benchmark against current system
3. Add circuit breaker for infinite loops
```

## How It Works

### 1. Scan arXiv

```python
# Fetches papers from last 7 days in cs.AI, cs.CL, cs.LG, cs.MA
papers = fetch_arxiv(categories=["cs.AI", "cs.CL"], days_back=7)
```

### 2. Check GitHub Trending

```python
# Fetches repos with ai-agents, llm, rag topics, min 100 stars
repos = fetch_github_trending(topics=["ai-agents", "llm"], min_stars=100)
```

### 3. Filter by Relevance

```python
# Uses sentence-transformers to compute cosine similarity
model = SentenceTransformer("all-MiniLM-L6-v2")
query_embedding = model.encode("agent orchestration RAG voice agents")
paper_embedding = model.encode(paper.abstract)
relevance = cosine_similarity(query_embedding, paper_embedding)

# Keep papers with relevance > 0.6
filtered_papers = [p for p in papers if p.relevance > 0.6]
```

### 4. Generate Proposals

```python
# Uses LLM to analyze papers/repos and suggest improvements
prompt = f"""
Analyze this research paper and suggest how it could improve our agent system:

Paper: {paper.title}
Abstract: {paper.abstract}

Current system:
- OpenClaw agent orchestration
- Tool/command separation
- Permission model
- Usage tracking

Generate 1-3 concrete proposals with:
1. Feasibility score (1-10)
2. Safety score (1-10)
3. Impact score (1-10)
4. Implementation steps
5. Risks
"""

proposals = llm.generate(prompt)
```

### 5. Commit & Notify

```python
# Save report
with open(f"dream-cycle/{TODAY}.md", "w") as f:
    f.write(report)

# Git commit
subprocess.run(["git", "add", "dream-cycle/"])
subprocess.run(["git", "commit", "-m", f"dream-cycle: {TODAY}"])
subprocess.run(["git", "push"])

# Send notification (Telegram/Discord)
notify(f"Dream Cycle complete: {len(proposals)} proposals generated")
```

## Requirements

- **Python 3.8+**
- **sentence-transformers** (for embedding-based filtering)
- **GitHub Copilot CLI** (for LLM reasoning, free with Copilot subscription)
- **Git** (for committing reports)

## Cost

**$0/day** when using GitHub Copilot CLI (included in GitHub Copilot subscription).

**Alternative LLMs:**
- OpenAI: ~$0.10/day (gpt-4o-mini)
- Anthropic: ~$0.15/day (claude-3-haiku)
- Local (Ollama): $0/day

## Examples

### Example 1: Manual Run

```bash
$ python scripts/dream-cycle.py

[INFO] Starting dream cycle: 2026-03-31 02:00:00 UTC
[INFO] Fetching arXiv papers (cs.AI, cs.CL, cs.LG, cs.MA, last 7 days)
[INFO] Found 247 papers
[INFO] Fetching GitHub trending (ai-agents, llm, rag, min 100 stars)
[INFO] Found 42 repos
[INFO] Filtering by relevance (threshold: 0.6)
[INFO] Kept 15 papers, 8 repos
[INFO] Generating proposals via GitHub Copilot CLI
[INFO] Generated 12 proposals
[INFO] Writing report: dream-cycle/2026-03-31.md
[INFO] Committing to git
[INFO] Dream cycle complete in 127.3s
```

### Example 2: OpenClaw Cron

```bash
$ openclaw cron list

Name: Dream Cycle
Schedule: 0 2 * * * (daily at 2 AM)
Status: enabled
Last run: 2026-03-31 02:00:12 UTC
Next run: 2026-04-01 02:00:00 UTC
```

### Example 3: Via Agent

```
User: "Run dream cycle"

Agent: "🦀 Running dream cycle... (this takes ~2 minutes)"

[2 minutes later]

Agent: "Dream cycle complete! Generated 12 proposals from 15 papers and 8 repos.

Top 3 proposals:
1. Add meta-planning layer (feasibility: 7/10, impact: 9/10)
2. Implement RAG-based tool discovery (feasibility: 8/10, impact: 7/10)
3. Add voice agent TTS/STT pipeline (feasibility: 6/10, impact: 8/10)

Full report: dream-cycle/2026-03-31.md"
```

## Alternatives

**Manual research:**
- ✅ Full control
- ❌ Time-consuming
- ❌ Inconsistent
- ❌ Easy to miss things

**RSS feeds:**
- ✅ Automated
- ❌ No filtering (too much noise)
- ❌ No synthesis (just raw papers)
- ❌ No proposals

**Twitter/Reddit:**
- ✅ Community curated
- ❌ Signal-to-noise ratio low
- ❌ Biased toward hype
- ❌ No proposals

**Dream Cycle:**
- ✅ Automated
- ✅ Filtered (embedding-based relevance)
- ✅ Synthesized (LLM generates proposals)
- ✅ Actionable (feasibility/safety/impact scores)
- ✅ $0/day (with Copilot)

## Limitations

- **Embedding model accuracy** — Relevance filtering is heuristic, may miss some relevant papers
- **LLM hallucination risk** — Proposals should be validated before implementation
- **GitHub trending bias** — Favors popular repos over cutting-edge research
- **English-only** — arXiv search is English-only
- **Academic focus** — Favors papers over blog posts/tutorials

## Future Enhancements

- **Phase 2:** Operational log analysis (cluster errors, propose fixes)
- **Phase 3:** Hourly self-reflection (blind spot detection)
- **Phase 4:** Weekly self-audit (quality scoring, auto-repair)
- **Phase 5:** OPSEC layer (audit published content for safety violations)

## Credits

- Inspired by [claude-code's auto-dream system](https://github.com/lowcortisolprogrammer/claude-code)
- Created by [@AndreaGriffiths11](https://github.com/AndreaGriffiths11)
- Built with [OpenClaw](https://openclaw.ai)

## License

MIT
