The Keel Language
Keel is a programming language where AI agents are first-class citizens.
Building an AI agent that monitors your email, classifies messages, and drafts replies takes ~180 lines of Python with LangChain. In Keel, it takes 40:
type Urgency = low | medium | high | critical
agent EmailAssistant {
role "Professional email assistant"
model "claude-sonnet"
tools [email]
task triage(email: {body: str}) -> Urgency {
classify email.body as Urgency fallback medium
}
task handle(email: {body: str, from: str, subject: str}) {
urgency = triage(email)
when urgency {
low, medium => {
reply = draft "response to {email}" { tone: "friendly" }
confirm user reply then send reply to email
}
high, critical => {
notify user "{urgency}: {email.subject}"
guidance = ask user "How to respond?"
reply = draft "response to {email}" { guidance: guidance }
confirm user reply then send reply to email
}
}
}
every 5.minutes {
for email in fetch email where unread {
handle(email)
}
}
}
run EmailAssistant
Design Principles
- Agents are primitives —
agentis a keyword, not a class pattern - Intent over implementation —
classify,draft,summarizeare built-in keywords, not library calls - Statically typed — full inference, every expression has a known type, mismatches are compile errors
- Humans in the loop —
ask,confirm,notifyare first-class - Web is native —
fetch,search,sendneed no imports - Time is built in —
every,after,atfor scheduling
What Keel Looks Like
Classify with AI
urgency = classify email.body as Urgency considering [
"mentions a deadline" => high,
"newsletter" => low
] fallback medium using "claude-haiku"
Pattern matching
when urgency {
low => archive email
medium => auto_reply(email)
high => escalate(email)
critical => page_oncall(email)
}
Collections with lambdas
urgent = emails.filter(e => triage(e) == critical)
names = contacts.map(c => c.name).sort_by(n => n)
Retry with backoff
retry 3 times with backoff { send email }
Getting Started
Install Keel and build your first agent in 5 minutes: Installation →