Agent Runtime

Custom Library

A library is the script that turns Dragon Script Routing into an in-world agent: it tells the AI what the prim perceives and carries out the actions the AI chooses. Our Dragon Library uses nothing private: these are its messages, so you can build your own. The server already checks what each agent may do, so a library only carries actions out.

integer DRAGON_ACTIONS  = 9110;   // API -> library: actions to perform
integer DRAGON_WORLD    = 9111;   // library -> API: what the prim perceives
integer DRAGON_HELLO    = 9112;   // library -> API: "I can act"
integer DRAGON_PING     = 9113;   // API -> library: "announce yourself"
integer DRAGON_CONFIG   = 9114;   // API -> library: dashboard settings
integer DRAGON_MENU     = 9115;   // library -> API: open the owner menu
integer DRAGON_NOTECARD = 9116;   // library -> API: upload a FAQ / Knowledge notecard
SendllMessageLinked( LINK_THIS, DRAGON_HELLO, string about, NULL_KEY );9112

Tells the API a library is installed. From then on every request asks the AI for actions, and they're forwarded to you on DRAGON_ACTIONS.

  • string about – required: a short description shown in the owner's Status, e.g. "my-library 1.0".

Send it in state_entry and whenever you get DRAGON_PING.

Eventlink_message( integer sender, integer DRAGON_PING, "", NULL_KEY ){ ; }9113

The API (re)started and asks libraries to announce themselves. Reply with DRAGON_HELLO, then your latest DRAGON_WORLD.

SendllMessageLinked( LINK_THIS, DRAGON_WORLD, string world, NULL_KEY );9111

What the prim perceives. The API keeps the latest one and sends it with every request, so the AI knows where it is and what it can give.

  • string world – a JSON object; every field is optional:
{"region": "Moonfall", "parcel": "Moonfall Mesh", "slt": "Tue 25 Nov, 7:30 PM SLT",
 "inventory": {"landmark": ["Moonfall Upstairs"], "notecard": ["Price list"], "sound": ["chime"]},
 "nearby": [{"n": "Kira", "u": "kira.resident", "k": "<avatar key>", "d": 3.2}]}

The AI can only give items listed in inventory. Send a new one when it changes.

Eventlink_message( integer sender, integer DRAGON_ACTIONS, string actions, key request_id ){ ; }9110

Actions the AI chose, to carry out in-world.

  • string actions – a JSON list of objects, each with do plus its own fields. Every action is listed in the Dragon Library guide.
  • key request_id – the request that produced them, or NULL_KEY when the server pushed them (settings changes, Agent results).
Eventlink_message( integer sender, integer DRAGON_CONFIG, string config, NULL_KEY ){ ; }9114

The agent's settings from the dashboard: {"name", "chat_mode": "name"|"open", "greet", "moderate", "tips"}. Also arrives as a {"do":"config", ...} action the moment the owner saves.

SendllMessageLinked( LINK_THIS, DRAGON_MENU, "", NULL_KEY );9115

Opens the owner's settings menu (Status, Re-link, New device). Only the owner sees it.

SendllMessageLinked( LINK_THIS, DRAGON_NOTECARD, string chunk, NULL_KEY );9116

Uploads a FAQ or Knowledge notecard, in pieces.

  • string chunk – required JSON: {"kind": "faq"|"knowledge", "chunk": 0, "last": false, "text": "..."}. Number the pieces from 0 (up to 100), up to 4,000 characters each, with "last": true on the final one.

A minimal library

Speaks and gives items:

default
{
    state_entry()
    {
        llMessageLinked(LINK_THIS, 9112, "my-library 1.0", NULL_KEY);   // DRAGON_HELLO
    }

    link_message(integer sender, integer num, string str, key id)
    {
        if (num == 9113) llMessageLinked(LINK_THIS, 9112, "my-library 1.0", NULL_KEY);
        if (num != 9110) return;                                         // DRAGON_ACTIONS
        integer i;
        string a = llJsonGetValue(str, [0]);
        while (a != JSON_INVALID) {
            string what = llJsonGetValue(a, ["do"]);
            if (what == "say") llSay(0, llJsonGetValue(a, ["text"]));
            else if (what == "give_item")
                llGiveInventory((key)llJsonGetValue(a, ["to"]), llJsonGetValue(a, ["item"]));
            a = llJsonGetValue(str, [++i]);
        }
    }
}