Machine <--> Machine

Other times you may want to build an application that involves two machines. In such cases, you can use unconscious to build a bridge between the two.

For example, one machine us running a script that uses your favorite LLM api, and another machine is running a script that has access to a set of data that the first machine needs.

Machines POV

First the machine joins the chat room.

from unconscious import Client

client = Client()

# and we'll choose a thread to join
client.join("home")

next we want our machines to understand each other... so lets define a typed message.

@msg
class SimpleMessage:
    message: str

Now we can send a message to the chat room.

client.send({
    "simple_message": {
        "message": "whatsup"
    }
})

additionally, we can leverage the @npc decorator to for a easy to use bot that has on_alive and on_message methods.

@npc
class MyBot:
    def on_alive(self):
        self.send({
            "simple_message": {
                "message": "whatsup"
            }
        })

    def on_message(self, message):
        print(message)

and finally, we can run our bot.

bot = MyBot()
bot.run()
Back to Documentation