{- Utilities to write agents. -} module QuicQuid.Agent.Util( answerAgent ,module QuicQuid.Term -- ,module QuicQuid.Router ,module QuicQuid.Broker ) where import Control.Monad(forever) import Control.Exception import Data.Maybe import QuicQuid.Log import QuicQuid.Term -- import QuicQuid.Logic import QuicQuid.Router import QuicQuid.Broker -- TODO: add support for the orderly shutdown of agents, to allow for closing connections, etc. -- | Utility function to create an agent that will answer a given query. answerAgent :: String -- ^ the name of the agent, e.g. "curl" -> String -- ^ the ask pattern (as a string), e.g. "resource{url:?url,content:?content}" -> (ReadChan -> IO ()) -- ^ the function that will read the queries and answer them -> IO () answerAgent agentName answerTerm process = do qch <- newAnswerAt ("/dns/org/quicquid/" ++ agentName) answerTerm forever $ handle (\e-> errorM ("Agent " ++ agentName) $ show e) $ process qch