Spaces:
Running
Running
File size: 7,416 Bytes
e0ade9c ea1db8d b4b9b2e ea1db8d b4b9b2e ea1db8d b4b9b2e ea1db8d b4b9b2e ea1db8d 0e05213 ea1db8d 0e05213 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ---
title: Second Brain Environment
emoji: π§
colorFrom: indigo
colorTo: purple
sdk: docker
app_port: 8000
---
# π§ Second Brain β OpenEnv Environment
> A Personal Knowledge Management environment where AI agents learn to capture, organize, and retrieve information β simulating the real-world challenge of managing a second brain.
[](https://github.com/meta-pytorch/OpenEnv)
[](https://huggingface.co/spaces/RAc1928/second-brain-env)
[](https://python.org)
---
## π Motivation
Millions of people struggle with **information overload** daily. We save articles, capture meeting notes, jot down ideas β but rarely retrieve them when we actually need them.
This environment trains AI agents to act as a **Personal Knowledge Manager**: capturing raw notes, organizing them correctly, and retrieving the right information at the right time. This is a genuine real-world skill that benefits students, professionals, researchers, and anyone who manages information.
---
## π― Tasks
### Task 1 β `note_categorization` π’ Easy
| Property | Value |
|---|---|
| **Goal** | Assign each of 10 raw notes to the correct category |
| **Categories** | `work`, `personal`, `reference`, `action_item` |
| **Max Steps** | 12 |
| **Reward** | +0.10 per correct, -0.02 per wrong, 0.00 per skip |
| **Score Formula** | `correct_count / 10` |
### Task 2 β `memory_retrieval` π‘ Medium
| Property | Value |
|---|---|
| **Goal** | Find the most relevant note in a 30-note KB for each of 5 questions |
| **Max Steps** | 15 |
| **Reward** | +0.20 exact match, +0.05β0.16 near miss, -0.05 miss, -0.10 repeated failure |
| **Score Formula** | `avg(retrieval_scores) / 5` |
### Task 3 β `knowledge_synthesis` π΄ Hard
| Property | Value |
|---|---|
| **Goal** | Synthesize multi-theme insights from a 50-note knowledge base |
| **Max Steps** | 20 |
| **Reward** | Up to +0.35 per question (theme coverage + note coverage + length) |
| **Score Formula** | `avg(synthesis_scores) / 3` |
---
## π Action Space
```python
class SecondBrainAction(BaseModel):
action_type: str # "categorize" | "retrieve" | "synthesize" | "tag" | "skip"
content: str # category name / search query / synthesized answer
note_id: Optional[str] # target note ID (optional)
tags: Optional[List[str]] # tags to apply (optional)
```
**Action types:**
- `categorize` β assign a category label to the current note (Task 1)
- `retrieve` β search the knowledge base with a query string (Task 2 & 3)
- `synthesize` β produce a final synthesized answer (Task 3)
- `skip` β skip the current item (no reward)
---
## ποΈ Observation Space
```python
class SecondBrainObservation(BaseModel):
current_note: Optional[Dict] # note being processed (Task 1)
query: str # question to answer (Task 2 & 3)
retrieved_notes: Optional[List] # top notes from KB search
knowledge_base_size: int # total notes in KB
step_count: int # current step
task_name: str # active task
reward: float # reward from last action
done: bool # episode finished?
score: float # running score in [0.0, 1.0]
feedback: str # human-readable feedback
valid_categories: List[str] # valid labels for Task 1
remaining_items: int # items left to process
```
---
## ποΈ Setup & Usage
### Install
```bash
pip install openenv-core python-dotenv
pip install git+https://huggingface.co/spaces/RAc1928/second-brain-env
```
### Run locally with Docker
```bash
git clone https://huggingface.co/spaces/RAc1928/second-brain-env
cd second-brain-env
docker build -t second-brain-env .
docker run -p 8000:8000 -p 8001:8001 -p 8002:8002 -p 8003:8003 second-brain-env
```
### Connect as a client
```python
import asyncio
from second_brain_env import SecondBrainEnv, SecondBrainAction
async def main():
async with SecondBrainEnv(base_url="http://localhost:8000") as env:
# Reset
result = await env.reset()
print(result.observation.feedback)
# Task 1: categorize a note
result = await env.step(SecondBrainAction(
action_type="categorize",
content="work"
))
print(f"Reward: {result.observation.reward}")
print(f"Score: {result.observation.score}")
asyncio.run(main())
```
### Run baseline inference
```bash
export HF_TOKEN=hf_your_token_here
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export SECOND_BRAIN_URL=http://localhost:8000
python inference.py
```
### Validate submission
```bash
openenv validate
```
---
## π Baseline Scores
Scores produced by the `Qwen/Qwen2.5-72B-Instruct` model via HuggingFace router:
| Task | Difficulty | Baseline Score |
|---|---|---|
| `note_categorization` | π’ Easy | 0.70 |
| `memory_retrieval` | π‘ Medium | 0.52 |
| `knowledge_synthesis` | π΄ Hard | 0.38 |
| **Average** | | **0.53** |
---
## π Reward Design
Rewards are **dense** β every step produces a signal:
```
Task 1 (categorization):
Correct category β +0.10 (agent gets immediate confirmation)
Wrong category β -0.02 (small penalty, not catastrophic)
Skip β 0.00 (neutral β no progress)
Task 2 (retrieval):
Exact match β +0.20 (top-1 is the correct note)
Near miss rank 2 β +0.16 (partial credit)
Near miss rank 3 β +0.12
Not in top 5 β -0.05 (try a different query)
3 consecutive bad β -0.10 (penalty for looping)
Task 3 (synthesis):
Per relevant note found β +0.05
Synthesis theme coverage β up to +0.12
Synthesis note coverage β up to +0.11
Answer length bonus β up to +0.07
Multi-theme connection β +0.05 bonus
Hallucinated facts β -0.10 penalty
```
---
## π³ Docker
```bash
# Build
docker build -t second-brain-env .
# Run (starts all 3 task servers automatically)
docker run -p 8000:8000 -p 8001:8001 -p 8002:8002 -p 8003:8003 second-brain-env
# Test
curl -X POST http://localhost:8000/reset
curl -X POST http://localhost:8000/step \
-H "Content-Type: application/json" \
-d '{"action_type": "categorize", "content": "work"}'
```
---
## π Project Structure
```
second_brain_env/
βββ inference.py β baseline inference script (root level)
βββ openenv.yaml β environment manifest
βββ pyproject.toml β dependencies
βββ README.md
βββ __init__.py β exports Action, Observation, Env
βββ models.py β Pydantic typed models
βββ client.py β WebSocket client
βββ server/
βββ app.py β FastAPI server
βββ second_brain_env_environment.py β step/reset/state logic
βββ data.py β seed notes and knowledge base
βββ requirements.txt
βββ Dockerfile
```
---
## π₯ Team
**Team TwinCoders**
- Rachana N
- Rakshith N
Built for the Meta Γ PyTorch Γ HuggingFace OpenEnv Hackathon 2026.
|