locked
Agent Outputs Feeding Async Into Other Agent? RRS feed

  • Question

  • Is this design doable in Axum?

     

    • I need an agent (Agent1) that will generate a list of numbers
    • as Agent1 generates elements in the list, each element is fed to another agent (Agent2) that examines the element


    Agent1 would have one input and an unknown-at-design-time number of outputs. Agent1 would need to send each output to Agent2 for processing. Ideally, Agent2 should start receiving elements as Agent1 is generating them, but without waiting for the entire sequence to be generated first. Agent2 should be receiving them asynchronously, as they are calculated by Agent1.
    Tuesday, June 1, 2010 5:26 PM

Answers

  • Sure, this is doable. I can think of two ways:

    1) Have Agent1 create Agent2. This is tightly coupled, since 1 knows about 2. Agent1 generates its numbers and sends them on a channel port to Agent2.

    2) Some other AgentX creates Agent1 and Agent2. Agent1 sends its list of numbers on some output port "NumbersOut" which is forwarded to an Agent2's input port 'NumbersIn' until Agent1 sends a signal on the 'Done' port:

    using (var nwk = ag1::NumbersOut ==> ag2::NumbersIn)
    {
        receive(ag1::Done);
    }

    In scheme 2), the two agents do not know about each other or that they are connected. As far as Agent1 is concerned, it's sending its data to the client, and as far as Agent2 is concerned, its getting its data from the client (AgentX). A downside of this scheme is that if AgentX is on a different machine than Agent1 and Agent2, there is extra communication going on. You'd want Agent1 and Agent2 to be able to communicate directly while still allowing AgentX to be the one who creates both. We have specified (but not implemented) mobile channel endpoint for this purpose: AgentX creates the channel for Agent2 and sends it to Agent1 who is then communicating with Agent2 directly, but without knowing anything about it. From a pattern perspective, you can still play with the logic and use it in process: just declare a port on the channel between AgentX and Agent1 to take a channel type and send the Agent2 endpoint to Agent1, who then sends its numbers directly to ag2::NumbersIn.

    (Actually, mobile channel endpoints are implemented, but may only be sent across in-process channels, so it still doesn't address the scenario above.)

    A hybrid between the two is a variant of 1) where AgentX sends the address of Agent2 to Agent1 which creates it but doesn't choose where Agent2 is hosted. That you can do today, no need for mobile endpoints, and the communication is still efficient.

    Niklas

     

     

    • Marked as answer by Jeff.Ferguson Wednesday, June 16, 2010 12:35 PM
    Friday, June 4, 2010 11:31 PM
    Moderator