Any other examples of multi-agent Agent programming in FSharp?

I am looking into F # agents that have multiple states, i.e. use a combination of the keywords "let rec / and" (for each F # 3.0 Expert "Message Handling and State Machines") to provide multiple blocks of asynchronous access. The only example I have been able to find is the "throttling agent" discussed here (also Fssnip.net). Are there any other resources for exploring this pattern?

edit: My specific application is an agent that has two states,

| StartFeed rateMultiplier replychannel ->

     - replychannel out data values at a delay (provided with each value) 
       multiplied by rateMultiplier
     - loop by using  
       thisAgent.Post(StartFeed rateMultiplier replychannel)


| Pause -> 

      

I would like to provide some way to pass a feedrate multiplier value that increases / decreases the latency with the passed multiplier in the asynchronous feed state without interrupting the feed. I guess the question boils down to "how do you keep an active block of asynchronous loop state while still being aware of new messages?" Almost the same as skipping inbox.Receive asynchronously waiting if the message doesn't really arrive? Inbox.scan?

edit 2: Considering the message queuing aspect of the MailboxProcessor, I can see that an external message (with a different multiplier value) that is received by the agent and queued will successfully change the rate without interrupting the value's data flow. Any advice on "Pause" would still be appreciated.

+3


source to share


1 answer


I found Tomas Petricek's post https://github.com/tpetricek/FSharp.AsyncExtensions/blob/master/src/Agents/BlockingQueueAgent.fs which gives a standard mailbox agent a way to choose which asynchronously block will be used to process next incoming message (ie let the agent "change its state"):

  • inbox.Receive () is used for the "standard state" - the agent's Inbox message queue is neither full nor empty (state # 1)
  • inbox.Scan () is used for "edge" or extreme cases of empty (state # 2) and full (state # 3) messages "Inbox" queue

  • the actions that the agent (depending on which of the three states) can take in response to received messages are written as ** different asynchronous blocks, which are assigned their own asynchronous block in the agent's "let rec" loop; I thought the "let rec ... and ..." asynchronous blocks were limited to having a function to receive messages (.Receive, .Scan, etc.), which is not correct, it could be any asynchronous block that supports the required control flow as seen in the following body function "let rec ... and ...":

  • when the agent, depending on which of the three states, responds to a new message by routing to the appropriate action, the action itself ends by calling another 'and' asynchronous agent body block 'let rec' loop, a selectState () 'block if / then, which determines what state will handle the new message, and calls this asynchronous block of 3 available.



This example seems essential when demonstrating the idiomatic use of the multi-state agent body construct, in particular, how to combine the three functions for receiving messages, responding, and controlling the loop as mutually recursive elements of one "let rec ... and ... and ..." ...

There are other messaging frameworks of course, but this is a generic logical / routing design for a more complex agent, regardless of structure, so: thanks Thomas.

0


source







All Articles