Skip to content

ling0x/krill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Krill 🦐

A minimal statically-typed actor-based language for AI agents, compiled to bytecode and executed on a Rust runtime.

Features

  • Typed actors: Each agent has a typed mailbox (Ref[MessageType])
  • Message passing: Asynchronous send with Tokio channels
  • Effect system: Capability-gated side effects (HTTP, logging, etc.)
  • Static typing: Compile-time type checking of messages and effects
  • Supervision: Automatic restart on agent crashes

Quick Start

Prerequisites

  • Rust 1.75+ and Cargo

Install & Run

# Clone the repo
git clone https://github.com/ling0x/krill.git
cd krill

# Build
cargo build --release

# Run example
cargo run --example hello

Language Syntax

// Define message types
type TicketMsg {
  NewTicket { id: Int, priority: String, replyTo: Ref[Response] }
  Status { replyTo: Ref[StatusResponse] }
}

type Response {
  Ack { ticket_id: Int }
}

type StatusResponse {
  Count { num: Int }
}

// Define an agent
agent TicketHandler {
  // Initial state
  state {
    tickets: Int = 0
  }
  
  // Message handlers
  on NewTicket { id, priority, replyTo } -> {
    state.tickets = state.tickets + 1;
    log("Processing ticket", id);
    send replyTo Ack { ticket_id: id };
  }
  
  on Status { replyTo } -> {
    send replyTo Count { num: state.tickets };
  }
}

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         agentc (Compiler)               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ Parser   β”‚β†’ β”‚  Type    β”‚β†’ β”‚ Code  β”‚ β”‚
β”‚  β”‚ (LALRPOP)β”‚  β”‚ Checker  β”‚  β”‚ Gen   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    ↓
              Bytecode IR
                    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        agentr (Runtime)                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ Tokio    β”‚  β”‚ Actor    β”‚  β”‚Effect β”‚ β”‚
β”‚  β”‚ Schedulerβ”‚  β”‚ Mailboxesβ”‚  β”‚System β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

agentlang/
β”œβ”€β”€ Cargo.toml              # Workspace manifest
β”œβ”€β”€ agentr/                 # Runtime crate
β”‚   β”œβ”€β”€ Cargo.toml
β”‚   └── src/
β”‚       β”œβ”€β”€ lib.rs          # Public API
β”‚       β”œβ”€β”€ actor.rs        # Actor system
β”‚       β”œβ”€β”€ mailbox.rs      # Typed mailboxes
β”‚       └── effects.rs      # Effect system
β”œβ”€β”€ agentc/                 # Compiler crate
β”‚   β”œβ”€β”€ Cargo.toml
β”‚   β”œβ”€β”€ build.rs            # LALRPOP build script
β”‚   └── src/
β”‚       β”œβ”€β”€ main.rs         # CLI entry point
β”‚       β”œβ”€β”€ grammar.lalrpop # Parser grammar
β”‚       β”œβ”€β”€ ast.rs          # AST definitions
β”‚       β”œβ”€β”€ typechecker.rs  # Type checking
β”‚       β”œβ”€β”€ bytecode.rs     # Bytecode IR
β”‚       └── interpreter.rs  # Bytecode executor
└── examples/
    β”œβ”€β”€ hello.rs            # Simple example
    └── ticket_system.agent # Agent source code

Examples

See examples/ directory for complete examples.

Roadmap

  • Basic actor system
  • Static type checking
  • Effect system
  • BDI-style goals and plans
  • Distributed runtime (NATS)
  • Rust code generation backend
  • Hot code reload

License

MIT

About

Krill 🦐 - A minimal statically-typed actor-based language for AI agents, compiled to bytecode and executed on a Rust runtime.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages