AIPL

Actor based Intelligent Parallel Language

AI エージェントをアクターとして書き、
その約束ごとを型で実行前に確かめる。
並行・分散のための、型付き AI エージェント言語です。

Write AI agents as actors,
and check the promises between them with types before they run.
A typed AI agent language for concurrent and distributed systems.

この絵は、ブラウザの中で AIPL のアクター 4 つが描いていますThis picture is being drawn by four AIPL actors running in your browser

特徴Features

ABCL/1 の流れをくむアクター言語に、AI 時代に必要な型と効果を加えました。An actor language in the line of ABCL/1, with the types and effects that the age of AI calls for.

A

アクターで書くWritten as actors

一つひとつのエージェントは独立したアクター。状態を共有せず、メッセージだけでやりとりします。

Each agent is an independent actor. Actors share no state and talk to each other only by messages.

⇄

3 つの呼び方Three ways to call

send(送りっぱなし)、now(返事を待つ)、future(あとで受け取る)を使い分けます。

send (fire and forget), now (wait for the reply) and future (collect the reply later).

T

返事の約束を型で検査Replies checked by types

「必ず一度だけ reply する」「約束した型で返す」を実行前に確かめます。返し忘れで相手が永久に待つことを防ぎます。

“Reply exactly once” and “reply with the promised type” are checked before the program runs, so a forgotten reply cannot leave a caller waiting forever.

!

効果注釈Effect annotations

!{ai, net} のように、AI 呼び出しや通信などの副作用をシグネチャに書き、宣言と本体の食い違いを検出します。

Side effects such as AI calls and networking go in the signature, as in !{ai, net}, and any mismatch between the declaration and the body is caught.

⏱

期限つきの待ちWaits with deadlines

now … timeout 500 else 0 で待ち時間に上限を付けられます。期限付きだけで書けばデッドロックしません。

now … timeout 500 else 0 puts an upper bound on a wait. A program that uses only bounded waits cannot deadlock.

AI

AI を部品として呼ぶAI as a component

ai_call で言語モデルを呼び出し、計画・実行・検証を役割の違うアクターに分けて協調させます。

ai_call invokes a language model; planning, acting and checking are split across actors with different roles that work together.

書き方What it looks like

クラスを定義し、new でアクターを作り、メッセージを送ります。Define a class, create actors with new, and send them messages.

class Stock {
  var n = 10;
  method take(k) : int {      // int を返すと約束// promises an int
    n = n - k;
    if (n < 0) { n = 0; }
    reply(n);
  }
}

class Front {
  method place(k) : string {
    var left = now stock.take(k);  // 返事を待つ// waits for the reply
    if (left > 0) { reply("ok, left=" ++ left); }
    else { reply("sold out"); }
  }
}

var stock = new Stock();
var front = new Front();
print(now front.place(3));    // ok, left=7
print(now front.place(99));   // sold out

在庫を持つ Stock と、注文を受ける Front の 2 つのアクターです。

  • Front は now で Stock に問い合わせ、返事を待ってから客に返します。
  • take は : int と宣言しているので、すべての経路で int を reply していなければ、実行前に指摘されます。
  • now stock.take(k) の結果が int だと分かるので、left > 0 の比較も型で確かめられます。

Two actors: Stock, which holds the stock, and Front, which takes orders.

  • Front asks Stock with now and waits for the answer before replying to the customer.
  • take is declared : int, so if some path does not reply with an int, this is reported before the program runs.
  • The result of now stock.take(k) is known to be an int, so the comparison left > 0 is type-checked too.

このプログラムを実行するRun this program

試してみるTry it

サーバは使いません。下の欄のプログラムは、このページに入っている AIPL 処理系がブラウザの中で実行します。書き換えて実行してみてください。No server is involved: the program below is run inside your browser by the AIPL interpreter built into this page. Edit it and run it.

⌘ / Ctrl + Enter でも実行⌘ / Ctrl + Enter also runs
出力Output
黒=プログラムの出力 橙=型検査の指摘 赤=エラー
「詳しく表示」に印を付けると、アクターの動き(生成・送信・返事)と、期限の無い待ちへの指摘も表示します。
Black = program output Orange = type-checker notes Red = errors
Tick “Show details” to also see what the actors do (creation, sends, replies) and notes about waits without a deadline.

動く場所Where it runs

同じ AIPL のプログラムが、性格の違う処理系の上で動きます。The same AIPL program runs on implementations of quite different kinds.

OCaml 版OCaml 言語仕様の基準となる処理系。型検査と実行。The reference implementation of the language: type checking and execution.
Python 版Python コマンドラインで動く処理系。実験用のダッシュボードつき。A command-line interpreter, with a dashboard for experiments.
ブラウザ版Browser JavaScript による処理系。このページで動いているもの。An interpreter in JavaScript — the one running on this page.
Raspberry Pi 上の XinuXinu on Raspberry Pi Linux を使わない小型 OS(Xinu)の上で、ロボットアームなどの実機を動かします。Runs on the small operating system Xinu instead of Linux, driving real hardware such as a robot arm.