An agent is an entity that generates and responds to events. Typically it's a process running either locally or on a remote computer; these agents are called clients.
Agents generate events in order to communicate with the rest of the world, namely the Glish program and any other agents the program may have created. By saying that agents respond to events we mean that they expect to receive certain types of events, and when they do they perform some action based on the value of the event. The action may entail generating one or more new events or may not. In general, the events an agent receives and those it generates need not be related, though often they are.
Glish provides an agent type for values corresponding to agents.
The client function provides a way to create an agent associated with a running process. For example,
demo := client("demo_client")assigns to demo an agent value corresponding to an instance of the program demo_client running on the local host.
demo := client("demo_client", host="mars")does the same thing except demo_client runs on the remote host mars. See § 7.8, page , for a full discussion of the client function.
You can also create agents that correspond to autonomous entities running within the context of a Glish program. The create_agent function takes no arguments and returns an agent value corresponding to a new, unique agent:
my_agent := create_agent()This agent can then be sent events using the mechanisms discussed in § 7.4, page , and respond to those events using whenever statements, as discussed in § 7.5, page .
Each agent value is also a record. Whenever the agent generates an event, Glish sets a field in the record with the same name to the value of the event. So, for example, if an agent a generates a hello event with a value of [F, F], then a.hello is set to [F, F].
For the most part, an agent's record can be used just like any other. In particular, you can create new fields in it or modify existing ones. Neither of these operations generates an event, though.