Programming with Agents

Embrio is an “agent based” programming tool.  The design and structure of an agent based program is significantly different than that of a traditional program.  This post will discuss how to think about a programming problem from the perspective of implementing it with agents.

There are two important properties of an agent; each agent should do just one thing, and each agent is always running.  This highly parallel architecture is very useful when it comes to embedded and embodied programming, significantly simplifying the complexity of the “program loop”.

The Three Types of Agents

In general there are three types of agents; perception, action, and control.  In the Embrio application there are just agents, the three types are conceptual differences, not ones specifically modeled in the software.

You can think of the flow of data in an Embrio program traveling into the system from sensors up the perception agents, across the logic agents, then down the action agents out to the system outputs.  Again, these are concepts to keep in mind when designing your program, Embrio doesn’t differentiate between the different types of agents.

Perception, Control, and Action agents


Perception agents detect things about the world or the internal state of the program.  They generally have an output activation which turns on when their state is detected and stays at 0 when it is not.  Perception agents can exist in layers, with higher layer agents representing more abstract states.

For example let’s imagine we are making a program to automate controlling a light.  A low level agent could read an ambient light sensor value which it converts to an activation, 0 being no light, 1 being bright light.  Another low level agent could be a motion detector, it outputs 0 when it doesn’t detect motion, 1 when it does.

A higher level perception agent could be an “it’s dark out” detector, which takes the light sensing agent and passes its activation through a threshold node, then outputs a 1 if the light value is below a certain range.

An even higher level perception agent could be an “it’s dark out and there’s been no motion for a while” detector, which outputs a 1 activation when that particular state is active.  This agent would take the “it’s dark out” detector, the motion detector, and combine them with some kind of timer to determine that “it’s been a while”.  All of this logic would be encapsulated by this agent and simplified into a single activation value which can be used anywhere else in the program.


Action agents make things happen.  Like perception agents, these also exist in layers with higher level agents being more abstract.

An obstacle avoiding car provides some good examples of action agents and their hierarchical structure.  (This tutorial walks through implementing some of these concepts.  It was made in an older version of Embrio but the concepts are the same.) Imagine a simple robot car, with a motor on each side, and a few distance sensors in the front.

The lowest level action agents would control the motors.  In this program there would be 4 low level agents, left wheel forward, left wheel back, right wheel forward, and right wheel back.  All of these agents would have an activation input which in this case would use the full value range from 0.0 to 1.0 to control the speed of the motor from off to full power.

The next level of activation agents would be things like move forward, move backward, turn left, and turn right.  These agents would again have a full range input activation which gets passed through to the lower level agents.  For example move forward would pass its input activation through to the left wheel forward and right wheel forward agents.  Turn left would pass its activation to the right wheel forward agent and the left wheel back agent to turn the car.

Other action agents can take perception agent as inputs.  For example an “turn away from obstacles on the left” agent would take the “left wall detector” agent and pass its activation through to the “turn right” agent, turning the car away from obstacles on the left.  There would be another agent to avoid obstacles on the right, and a higher “avoid obstacles” agent which would turn on these and maybe other agents.

A higher level agent could be “wander”, which turns on the move forward agent, the avoid obstacle agent, and the random turns agent.


Perception and Activation agents are the most common in an Embrio program, a lot can be done by flowing data up and down a structure made of these agents.  Logic or Control agents are another conceptual type of agent where data flows across, taking activation states from perception agents and determining based on some logic which action or other logic agents to turn on.

In the obstacle avoiding car example let’s say the car can have several high level behaviors; wander, escape, rest, look around, etc.  Generally only one of these behaviors could or should be on at a time.  We can use some higher level logic agents to decide which behavior to activate.  The concept of state control deserves more attention that can be paid to it in this blog post, so there will be another post dedicated to it.  You can also see this tutorial for an overview.

The general idea here is to understand the three different conceptual types of agents and how you would use them to create an embedded or embodied program with Embrio.


One of the most distinctive features of Embrio is that it uses “activations” as the main data type.  An activation is simply a floating point number between 0.0 and 1.0.  Sometimes an activation can also extend down to -1.0 as its minimum value.  This post will further discuss the concept of an activation and why it is so powerful in embodied software.

As mentioned previously, Embrio was designed primarily as a tool for created embodied software.  In nature bodies are controlled by brains, so understandably Embrio is based loosely on the brain.  The brain is made out of neurons.  Very basically a neuron is made up of a cell body with inputs and outputs that connect to other neurons.  Neurons communicate with electro-chemical signals called “action potentials”.  In reality these communications are very complicated, but when modeled in a computer the signal is either very much simplified to an on or off value, or slightly less simply as a floating point value between 0 and 1, which is what Embrio uses.  A neuron sums together its input values, and if this value is over the neuron’s threshold, the neurons output turns on passing that signal onto other neurons, otherwise it stays off.  The brain is a ridiculously complicated network of billions of neurons with trillions of connections between them, organized into staggering structures and layers designed by evolution over a billion or so years.  An Embrio program is a simple network of interconnected nodes designed by a human with moderate intelligence in hours or days.  There are more differences than similarities, but Embrio takes a lot of inspiration from the brain.

The power of an activation is that it can represent anything happening in a physical system.  Imagine neurons all over the brain that turn on when the specific state that they detect occurs.  For example in the parts of the brain that do vision one neuron would turn on when it detects an edge or line, another neuron turns on when it detects a nose, and another turns on when it detects Joe’s face.  Elsewhere in the brain a neuron turns on when its body is hungry, or scared, or tired.  A neuron can turn on when it detects that its body is about to walk into a wall, or that the road ahead is icy.  In a real brain, these detections are represented by the firing of hundreds or thousands or millions of neurons, but in an Embrio program they are represented by one activation.  In a robot an activation can turn on when there is a wall to the left, or when the measured velocity is less than the desired velocity, or when the battery is low.  The important point is that any state can be represented by an activation as a common simple data type.  An activation is a universal currency that all parts of a program can exchange.

Another powerful aspect of an activation is how they are multiplied together.  Multiplying any number by 0 results in 0, and multiplying any number by 1 results in the same number.   In Embrio, activations flow in from external sources like sensors, through the program to outputs like motors or lights.  This flow can be squeezed shut by multiplying an activation by another activation with a 0 value, or let through by multiplying it with an activation of 1.  A lot of what an agent in Embrio does is turn on or turn off other agents.  Most agents have an input activation that other agents can connect to and pass a 1 activation to turn on that agent.  More about this will be discussed elsewhere.

Almost all sensor or other input data in an Embrio program should be converted from whatever data type and range they come in as into an activation.  These activations flow through the program, turning agents on or off, until they come to outputs to the program at which point the activations are transformed back to whatever range the target hardware requires.  There are some cases where it doesn’t make sense to represent a value as an activation, like if you are making a clock and want to represent seconds, minutes and hours.  In these cases you can use the other data types, but generally all of your logic and as much data as makes sense should be done with activations.