<!-- Sema documentation — agent-research
     Sema is a new AI-native, neurosymbolic programming language most models
     have not been trained on. Full corpus: https://sema.49.12.246.95.sslip.io/llms-full.txt
     Install language support: https://sema.49.12.246.95.sslip.io/install-skill/ -->

# agent-research

> The agent-research worked example.

> The agent-research worked example.

Run it from `sema/`:

```bash
sema check examples/agent-research
SEMA_STRICT=1 sema run examples/agent-research
sema assure examples/agent-research --grade silver
```

## Source

### `src/main.sema`

```sema
"""Durable research fan-out/fan-in with typed native agents."""

assure silver

def search(query: str) -> str !{}:
    return "source:" + query

agent researcher(question: str) -> str by research_model:
    sem "Collect one attributable finding and separate fact from inference"
    use tools [search]
    budget model_calls=2, tokens=512
    ensure len(result) >= 1

agent writer(evidence: list[str]) -> str by writer_model:
    sem "Synthesize the evidence with provenance and explicit uncertainty"
    budget model_calls=1, tokens=512
    ensure len(result) >= 1

circuit synthesize(questions: list[str]) -> str !{model.invoke}:
    budget agents=8, spawn_depth=0, model_calls=16, tokens=8000
    evidence = parallel [researcher(question) for question in questions]
    return writer(evidence)

def main() -> str !{model.invoke}:
    result = synthesize(["energy storage", "grid reliability", "source quality"])
    print(result)
    return result
```

## Reflected API

# `main`

Durable research fan-out/fan-in with typed native agents.

# `def search`

```sema
def search(query: str) -> str !{}
```

**Parameters**

| name | type |
|---|---|
| `query` | `str` |

**Returns** `str`

**Effects** `!{}`

# `agent researcher`

```sema
agent researcher(question: str) -> str
```

**Parameters**

| name | type |
|---|---|
| `question` | `str` |

**Returns** `str`

# `agent writer`

```sema
agent writer(evidence: list[str]) -> str
```

**Parameters**

| name | type |
|---|---|
| `evidence` | `list[str]` |

**Returns** `str`

# `circuit synthesize`

```sema
circuit synthesize(questions: list[str]) -> str !{model.invoke}
```

**Parameters**

| name | type |
|---|---|
| `questions` | `list[str]` |

**Returns** `str`

**Effects** `!{model.invoke}`

# `def main`

```sema
def main() -> str !{model.invoke}
```

**Returns** `str`

**Effects** `!{model.invoke}`
