特徴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.
アクターで書く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).
返事の約束を型で検査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 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.
FrontasksStockwithnowand waits for the answer before replying to the customer.takeis 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 comparisonleft > 0is type-checked too.
試してみる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.
「詳しく表示」に印を付けると、アクターの動き(生成・送信・返事)と、期限の無い待ちへの指摘も表示します。
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.
関連リンクLinks
より詳しい資料と、オンラインの実行環境です。More detailed material, and an online environment for running AIPL.