Dear Jane,
It is quite easy to turn Ciao active modules into agents for the kind of application you mention. Active modules are run independently and communicate through messages. Of course, execution is non deterministic, too. Ciao also runs in several platforms (including Win32 and Unix), so you will find your application easily portable.
The Prolog code you send as receipt guard is basically all you need. Here is a slightly modified version that we have been running here without problem:
case(shutdown, _) :- !, halt. case(add(NumList), Sender) :- sum_list(NumList, Sum), send(Sender, sum(Sum)), !. case(_, _).
We have taken out message give_me_your_id and variable I, since we have assumed that the agent Id and I are the same thing, and we have used the module name as such an Id, which is convenient when using active modules. Thus, you identify an agent by the name of the corresponding active module. This is done transparently by the module "send" below, which implements the send/2 predicate.
We have also assumed that any agent might want to call any other, and that the number of agents is known in advance. Given this, it is convenient to use an auxiliary module that will take care of agent communication. It will look like:
:- module(send,[send/2],[actmods,hiord]). :- use_module(library('actmods/webbased_locate')). :- use_active_module(agent1, [agent1/2]). :- use_active_module(agent2, [agent2/2]). ... :- use_active_module(agentN, [agentN/2]).
:- meta_predicate send(?,addmodule).
send(Sender, Message, I) :- Sender(I, Message).
Basically, you need this module to declare the agents in your application: agent1, agent2, ...
We have used as communication protocol the "webbased" one, but you could use any of the others. With "webbased" you will need to have a process acting as name server.
Given the above, your agents will look like:
:- module(agent1,[agent1/2]). :- use_module(send).
agent1(Sender, Msg) :- case(Msg, Sender).
... code for case/2 ...
and all you have to do is to compile them as active modules:
ciaoc -a actmods/webbased_publish agent1
We have been able to run such an application at our site. Your problems might be caused by the name server (if you're using the Ciao distribution right away, the name server is supposed to be run at our site, and we are not currently running any). You will need to set up an appropriate name server at your site. We can help you with this if you have problems (you are probably right that the documentation is not very clear in this point).
It is not clear to us from what you say:
and when the agent end of executing the instruction underway, agent attends the arrival of the message (is as an asynchronous event that triggers the attention of the agent).
whether you want agents to attend several messages at the time or not. It is possible to do it using threads. With the above code, however, agents process only one message at a time (and they are enqueued waiting for the agent to be idle).
Paco Bueno & the Ciao team