Hello World
Let’s write the simplest possible Sage program.
Create a File
Create a file called hello.sg:
agent Main {
on start {
print("Hello from Sage!");
yield(0);
}
}
run Main;
Run It
sage run hello.sg
Output:
Hello from Sage!
0
What’s Happening?
Let’s break down this program:
-
agent Main { ... }— Declares an agent namedMain. Agents are the basic unit of computation in Sage. -
on start { ... }— Thestarthandler runs when the agent is spawned. Every agent needs at least one handler. -
print("Hello from Sage!")— Prints a message to the console. -
yield(0)— Emits a value, signaling that the agent has finished. The emitted value becomes the agent’s result. -
run Main— Tells the compiler which agent to start. Every Sage program needs exactly onerunstatement.
Build a Binary
Instead of running directly, you can compile to a standalone binary:
sage build hello.sg -o out/
./out/hello/hello
The binary is self-contained — no Sage installation needed to run it.
Next Steps
Now let’s write something more interesting: Your First Agent.