agent-research
The agent-research worked example.
Run it from sema/:
sema check examples/agent-researchSEMA_STRICT=1 sema run examples/agent-researchsema assure examples/agent-research --grade silverSource
Section titled “Source”src/main.sema
Section titled “src/main.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 resultReflected API
Section titled “Reflected API”Durable research fan-out/fan-in with typed native agents.
def search
Section titled “def search”def search(query: str) -> str !{}Parameters
| name | type |
|---|---|
query | str |
Returns str
Effects !{}
agent researcher
Section titled “agent researcher”agent researcher(question: str) -> strParameters
| name | type |
|---|---|
question | str |
Returns str
agent writer
Section titled “agent writer”agent writer(evidence: list[str]) -> strParameters
| name | type |
|---|---|
evidence | list[str] |
Returns str
circuit synthesize
Section titled “circuit synthesize”circuit synthesize(questions: list[str]) -> str !{model.invoke}Parameters
| name | type |
|---|---|
questions | list[str] |
Returns str
Effects !{model.invoke}
def main
Section titled “def main”def main() -> str !{model.invoke}Returns str
Effects !{model.invoke}