Skip to content

2 · Ask it from Python

In episode 1 you talked to ResNetAgent from the browser. Here you do the same from a terminal. You become an agent of the network yourself. A Python node hosts this agent and you are its processor. Whatever you type or send becomes the output of the agent. The agent in the browser tab of episode 1 worked in the same way.

Keep resnet_agent.py running in the first terminal and open a second one.

The script

me.py
from unaiverse.agent import Agent
from unaiverse.modules.utils import HumanModule
from unaiverse.networking.node.node import Node

agent = Agent(proc=HumanModule(),  # (1)!
              proc_inputs=["text", "img", "file", "all"],
              proc_outputs=["text", "img", "file"])

node = Node(agent, node_name="Me", hidden=True)
node.run(get_in_touch="ResNetAgent", interact_mode=True)  # (2)!
  1. HumanModule is the processor of a person. Its output is what you type or send: text, a picture or a file.
  2. get_in_touch opens a session with the agent called ResNetAgent of your account. interact_mode=True lets you type messages and commands in the terminal.
python me.py

When the session is ready the node prints:

*** Connected to agent ... ***
*** Entering interactive mode [type exit() to quit] ***

👉

Send a picture

Because the classifier takes pictures, send it a file from disk with /send:

👉 /send cat.jpg
*** Sending the picture cat.jpg ***

💬 [you/ResNetAgent.processor.proc_output_0]
   |tabby

The node read the picture, sent it to ResNetAgent as a request to run its processor and printed the text that came back. The line in brackets names the source of the answer: the owner and the node, then the group and the name of the stream (processor.proc_output_0 is the first output of the processor).

The commands of interactive mode

Command What it does
any text Sends the text to the agent or world you are connected to.
/send <path> Sends a file from disk as an image when it is a picture and as a file otherwise.
/agents Lists the agents your node is connected to.
/leave Leaves the current agent (or the world, inside a world).
/debug Turns the debug messages of the behaviors on and off.
exit() Leaves every peer and stops the node. quit() and /exit do the same.

Answers print as they arrive. A text answer appears after the 💬 mark. A picture is saved as a PNG file in the current folder and its name is printed after the 🖼️ mark.

What happened

Your node and ResNetAgent are two equal peers. The two nodes opened a session with a handshake and keep it alive with keep-alives every 15 seconds that check whether the peer still answers. When you sent the picture, your agent created an interaction that asked ResNetAgent to run the action process on that picture. The default behavior of ResNetAgent ran the network and streamed the label back on its output stream.

sequenceDiagram
    participant Me as Me (person)
    participant R as ResNetAgent
    Me->>R: HELLO
    R->>Me: HELLO_ACK
    Note over Me,R: session established
    Me->>R: interaction: process (cat.jpg)
    R->>R: processor runs
    R-->>Me: interaction completed
    R-->>Me: stream: "tabby"

If your Wi-Fi drops for a few seconds, the session enters RECONNECTING and resumes as soon as the network comes back. After 45 seconds without the peer the session ends as LOST. Networking covers these states.

Stop and move on

Stop the node with exit(). Keep resnet_agent.py running for the next episode. In that episode an agent that you write sends the pictures with no person at the keyboard.

A person is an agent

The browser chat of episode 1 and this terminal are the same thing seen from two sides. In both cases a person is the processor of an agent and the other agents do not treat the person differently. People shows how worlds give roles to people as well.