Tools¶
Expose local capabilities and apply contracts (5–8 minutes).
Example¶
from alloy import command, tool
@tool
def word_count(text: str) -> int:
return len(text.split())
@command(tools=[word_count])
def analyze(text: str) -> str:
return f"Use word_count(text), then suggest one clarity improvement.\\nText: {text}"
print(analyze("Alloy makes typed AI functions feel like normal Python."))
Expected: a short analysis referencing the word count.
Links (GitHub)¶
Safety: prefer small, idempotent tools with clear messages in @require/@ensure
.
See also: Guide → Contracts (guide/contracts.md) and Design by Contract.