p.enthalabs

cryolang playground

Welcome to the Cryo Playground from Endothermic Labs! Cryo is a new programming language designed for long-running tasks like agents and workflows. It runs on the Freeze/Thaw Virtual Machine (FTVM), which is built to keep a program going for an indefinite period of time.

This playground runs a small version of Cryo right in your browser, along with some example plugins you can use from your programs.

If you follow along with this tutorial, we'll cover the basic concepts of Cryo and build our way up to a few demos. Or, if you'd rather just see what it can do, try:

#### Filtering Hacker News for posts **not** about AI

``` from plugin "hn" import { HN }; from plugin "jev" import { noul };

var stdio = stdio!();

var main = fn() => int { // Get all the latest stories published to hacker news // Use `HN.front(5)` for just the ones that make it to the front page var front = HN.newest(5);

loop { var s = <- front;

// Then use Jev to find the ones that aren't about AI var is_not_ai = noul(s.title, "Is this post *not* about AI?"); var is_about_cryo = noul(s.title, "Is this post about Cryo or Endothermic Labs?");

if is_about_cryo > 700 { stdio <- format!("I think I see myself! $1 ($2)", s.title, s.url); } else if is_not_ai > 700 { stdio <- format!("#$1 $2 ($3 points, by $4)", s.rank, s.title, s.score, s.by); stdio <- format!(" $1", s.hn_url); } };

0 }; ```

cryo

#### Joining a chatroom that only lets posh messages through

``` // A bot in a room with other people's. Freeze it, let the room // talk, thaw: it hears everything it missed, in order.

from plugin "rooms" import { Room }; from plugin "jev" import { score };

var stdio = stdio!();

type Poshness = "brash" | "mid-class" | "posh";

var main = fn() => int { // Pick a handle: letters, digits, - and _ stdio <- "What should we call you?"; var handle = <- stdio;

// Join the chatter room var room = Room.join_as("chatter", handle); stdio <- format!("Joined as $1", handle);

loop { select { room.messages -> m => { stdio <- format!("$1: $2", m.from, m.text); } stdio -> msg => { var poshness = score::Poshness;

var can_say = match poshness.choice { "mid-class" | "posh" => { true } "brash" => { false } };

if can_say { var res = <- room.say(msg);

match res { $err{e} => { stdio <- format!("Something went wrong: $1", e); return -1; } _ => { /* continue */ } } } else { stdio <- "Please! Watch your language in this esteemed chat"; } } }; };

0 }; ```

cryo

#### Starting a discussion about Cryo, and filing an issue once it’s actionable

``` // A program that signs in to GitHub as you, starts a discussion in // github.com/endothermic-ai/playground, and listens to it.

from plugin "github" import { authenticate, Comment, User }; from plugin "jev" import { noul }; from plugin "llm" import { complete };

var stdio = stdio!();

var add_followups = fn(comment: (c: str) => pipe[$ok{ str } | $err{ str}]) { stdio <- "Anything you want to add?"; loop { var success = <- comment(<- stdio); match success { $ok{ _ } => {} $err{ e } => { panic!(e) } }; }; };

var monitor_for_issues = fn(initial_thread: str, me: User, comments: pipe[Comment]) { var has_created_issue = false; var running_content = initial_thread;

loop { var c = <- comments;

var update = format!("$1 said: $2", c.author, c.body); stdio <- update;

running_content = running_content ^ "\n" ^ update;

if noul(running_content, "Should we create an issue for this?") > 700 { var issue_body = complete("Summarize the issue we want to create for this discussion thread: " ^ running_content); var issue_title = complete("Create a title for this issue: " ^ issue_body);

<- me.issue(issue_title, issue_body); stdio <- format!("Created a new issue: $1", issue_title); return; } }; };

var main = fn() => int { var me = authenticate(); stdio <- format!("signed in as $1", me.login);

stdio <- "What are your thoughts on Cryo?"; var thoughts = <- stdio;

// The first write of a run asks you first, outside the program's reach. var d = me.start(format!("$1's thoughts on Cryo", me.login), thoughts); stdio <- format!("started #$1: $2", d.number, d.url);

|| { add_followups(d.comment) }; <- || { monitor_for_issues(thoughts, me, d.comments) };

0 }; ```

cryo

#### Classifying how your day is going

``` // Jev classifies text into a type you declare, so the answer can only be // one of its members and a `match` on it is checked for every case. // Freeze while it's asking: the thaw asks again. from plugin "jev" import { choice, noul };

var stdio = stdio!();

type Mood = "glad" | "sad" | "angry" | "neutral";

var main = fn() => int { stdio <- "how's your day going?";

loop { var text = <- stdio;

// The type argument is written out, and an option outside Mood // doesn't compile. A description is most of the accuracy. var mood = choice::Mood;

// Drop an arm and this stops compiling. var reply = match mood.choice { "glad" => { "glad to hear it" } "sad" => { "sorry, that sounds hard" } "angry" => { "that would annoy me too" } "neutral" => { "noted" } }; // Cryo has no floats: confidence is in thousandths. stdio <- format!("$1 ($2% sure)", reply, mood.confidence_milli / 10);

// A noul is the probability a proposition is true, also in thousandths. if noul(text, "The writer is asking a question.") > 500 { stdio <- "I'd answer, but I only classify"; }; }; 0 }; ```

cryo

If you're ready, let's jump straight in. There's a lot I want to show you!

— Zach Wade and Endothermic Labs