Episode 2: Talk to it from Python¶
Quickstart · Episode 2 of 4
Chatting from the browser is nice, but you're a builder. Let's reach the chatbot from code, by creating a second agent whose "brain" is you.
The idea¶
UNaIVERSE treats humans as agents too. There's a ready-made "brain" called
HumanModule whose job is simply: show me what arrives, and send back what I
type. We'll put it in its own node and tell it to get in touch with
MyChatbot.
Wait, a human is an agent?
Yes, and it's a core idea. A person is just an agent whose processor is their
own mind. The HumanModule is the little adapter that turns your keyboard
into an agent's input/output. Same network, same rules as any AI agent. More
in I enter as a human.
The code¶
Keep chatbot.py running in its terminal. In a second terminal, create
me.py:
from unaiverse.agent import Agent
from unaiverse.modules.utils import HumanModule
from unaiverse.networking.node.node import Node
# The "brain" here is you, via the keyboard.
agent = Agent(proc=HumanModule(), proc_inputs=["text"], proc_outputs=["text"])
# Host yourself as a node.
node = Node(agent, node_name="Me", clock_delta=1./25.)
# Reach the chatbot by name and start an interactive session.
node.run(get_in_touch="MyChatbot", interact_mode=True)
Run it¶
Now type in this second terminal, your message travels over the network to
MyChatbot, its TinyLLama brain answers, and the reply comes back to you. You're
holding a conversation between two independent programs that found each other
on the network.
What just happened¶
sequenceDiagram
participant Me as Me (node "Me")
participant Net as P2P network
participant Bot as MyChatbot (node)
Me->>Net: get_in_touch("MyChatbot")
Net-->>Me: connected
Me->>Bot: my message (text)
Bot->>Bot: TinyLLama thinks
Bot-->>Me: reply (text)
- You ran a second node, a separate program, which could be on a separate computer.
get_in_touch="MyChatbot"told it to connect directly to a specific agent by name (no group involved).interact_mode=Trueturned on the interactive console so you can type.- Because both agents declared
textin and out, their streams matched and got wired together automatically.
What's the difference between this and Episode 1's browser chat?
None, conceptually! The browser was a human agent too. Here you just ran that human agent yourself, from Python, so you can see the moving parts. Same network, same connection, same streams.
This is the canonical 'human' script
A fuller version lives in the examples repo as
lonewolves/run_human.py
, it also handles images and joining worlds.
Episode 2 recap
You learned to run a second node, connect two agents with
get_in_touch, and interact over matched text streams. So far a human is
always in the loop. Next, we remove the human entirely.