goalEDP


NamegoalEDP JSON
Version 0.0.7 PyPI version JSON
download
home_pageNone
SummaryLibrary for processing goal-oriented agents. Processing is done on an event-driven mechanism. Events are saved to be used by explanation generating methods.
upload_time2024-03-20 18:58:08
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords scientific paradigms agents explainability
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # goalEDP

Library for processing goal-oriented agents. Processing is done on an
event-driven mechanism. Events are saved to be used by explanation generating
methods.

## Contents

- [Sample application](#sample-application)
- [References](#references)
- [About](#about)

## Sample application

This package is published in the official Python repository. To install, use:

```
python3 -m pip install goalEDP
```

Application example:

```python
from goalEDP.extensions.goal import BeliefsReviewer, GoalStatusPromoter, Goal, Action, Agent, GoalBroker, Conflict
from goalEDP.explainers.simple_explainer import SimpleExplainer
from goalEDP.storages.in_memory import InMemoryHistory
from goalEDP.core import Event
from goalEDP.extensions.web_gui import WebGUI


# Describe how the agent works:
# The Agent has the following flow:
# 1) revise beliefs
# 2) promotes goals statuses
# 3) detects conflicts
# 4) pursues goals

class ReviewAccident(BeliefsReviewer):
    def __init__(self):
        # Call to superclass constructor
        super().__init__(
            desc="Review accident data", attrs=["accident"])  # Attributes can be external events, inputted or not by a simulator. They can also be events that represent communication between agents.

    async def reviewBeliefs(self):
        # The event queue is cleared each time the entity is processed. Maybe you want to save the beliefs in an object variable.
        beliefs = dict()
        if ("accident" in self.eventQueueByTopic):
            # "-1" to get the last one in queue
            # Use only JSON-serializable variables as belief values.
            # In fact, in this framework all event values ​​must be serializable to JSON.
            # If you want to use complex structured data, use compositions with Python's dict structure.
            beliefs["accident.coord"] = self.eventQueueByTopic["accident"][-1].value["coord"]
            beliefs["accident.hasAtLeastTwoVictims"] = len(
                self.eventQueueByTopic["accident"][-1].value["victims"]) >= 2
            beliefs["accident.severityIsHigh"] = False
            for victim in self.eventQueueByTopic["accident"][-1].value["victims"]:
                if victim["bpm"] < 60 or victim["bpm"] > 100:
                    beliefs["accident.severityIsHigh"] = True
                if victim["mmHg"][0] > 14 or victim["mmHg"][1] < 6:
                    beliefs["accident.severityIsHigh"] = True
        return beliefs

# All goal statuses must be True for it to be pursued


class RescuePromoter(GoalStatusPromoter):
    def __init__(self):
        super().__init__(
            desc="Promotes rescue goal statuses", beliefs=["accident.hasAtLeastTwoVictims", "accident.severityIsHigh"], promotionNames=["intention"])

    async def promoteOrDemote(self):
        # The event queue is cleared each time the entity is processed. Maybe you want to save the promotions in an object variable.
        promotions = dict()
        if ("accident.severityIsHigh" in self.eventQueueByTopic) and ("accident.hasAtLeastTwoVictims" in self.eventQueueByTopic):
            if (self.eventQueueByTopic["accident.severityIsHigh"][-1].value) or (self.eventQueueByTopic["accident.hasAtLeastTwoVictims"][-1].value):
                promotions["intention"] = True
            else:
                promotions["intention"] = False
        return promotions


class RescueAction(Action):
    def __init__(self):
        super().__init__(
            desc="Action to rescue victims", beliefs=["accident.coord"])

    async def procedure(self) -> None:
        print("Rescue at: " +
              str(self.eventQueueByTopic["accident.coord"][-1].value))

# Goals with highest priority are pursued first


class Rescue(Goal):
    def __init__(self):
        super().__init__(desc="Objective of rescuing victims of serious accidents",
                                     promoter=RescuePromoter(), plan=[RescueAction()], priority=0)

# If conflict is detected, the goal with the highest priority is chosen, with the others discarded.
#
# class ConflictOne(Conflict):
#    def __init__(self):
#        super().__init__(
#            desc="Recharge battery instead of saving victim", conflictingGoals=[goalInstance1, goalInstance2])


agent1 = Agent(desc="Robot that saves victims", beliefsReviewers=[
               ReviewAccident()], goals=[Rescue()], conflicts=[])

# Instantiates history to save events.
history = InMemoryHistory()

# Instantiates the event broker, which also controls the execution sequence
broker = GoalBroker(agents=[agent1], history=history)

broker.startProcess()

# Enter external events, from a simulator for example.
broker.inputExternalEvents([
    Event("accident", {"victims": [
          {"mmHg": [120, 80], "bpm":50}], "coord": [30, 40]})
])

# instantiates the explanation manager
explainer = SimpleExplainer(broker, broker.history)

# Instantiates the explanation generator web graphical interface.
interface = WebGUI(explainer)

# Starts the web graphical interface server.
# The IP and port will be printed on the terminal.
# You must open the respective ip and port in the browser.
interface.server.run()
```

## References

<a id="1">[1]</a> C. Castelfranchi and F. Paglieri. The role of beliefs in goal
dynamics: prolegomena to a constructive theory of intentions. Synthese, 155,
237–263, 2007. doi: https://doi.org/10.1007/s11229-006-9156-3

<a id="2">[2]</a> H. Jasinski and C. Tacla Denerating contrastive explanations
for BDI-based goal selection. url:
http://repositorio.utfpr.edu.br/jspui/handle/1/29522

<a id="3">[3]</a> J. M. Simão, C. A. Tacla, P. C. Stadzisz and R. F.
Banaszewski, "Notification Oriented Paradigm (NOP) and Imperative Paradigm: A
Comparative Study," Journal of Software Engineering and Applications, Vol. 5 No.
6, 2012, pp. 402-416. doi: https://www.doi.org/10.4236/jsea.2012.56047

## About

Author: Henrique Emanoel Viana, a Brazilian computer scientist, enthusiast of
web technologies, cel: +55 (41) 99999-4664. URL:
https://sites.google.com/view/henriqueviana

Improvements and suggestions are welcome!

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "goalEDP",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "scientific, paradigms, agents, explainability",
    "author": null,
    "author_email": "Henrique Emanoel Viana <hv5088@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/7d/ec/ce603d65bc073a2cbce830064ea0a8a86ead789d5a3c43852e5c873ef638/goalEDP-0.0.7.tar.gz",
    "platform": null,
    "description": "# goalEDP\r\n\r\nLibrary for processing goal-oriented agents. Processing is done on an\r\nevent-driven mechanism. Events are saved to be used by explanation generating\r\nmethods.\r\n\r\n## Contents\r\n\r\n- [Sample application](#sample-application)\r\n- [References](#references)\r\n- [About](#about)\r\n\r\n## Sample application\r\n\r\nThis package is published in the official Python repository. To install, use:\r\n\r\n```\r\npython3 -m pip install goalEDP\r\n```\r\n\r\nApplication example:\r\n\r\n```python\r\nfrom goalEDP.extensions.goal import BeliefsReviewer, GoalStatusPromoter, Goal, Action, Agent, GoalBroker, Conflict\r\nfrom goalEDP.explainers.simple_explainer import SimpleExplainer\r\nfrom goalEDP.storages.in_memory import InMemoryHistory\r\nfrom goalEDP.core import Event\r\nfrom goalEDP.extensions.web_gui import WebGUI\r\n\r\n\r\n# Describe how the agent works:\r\n# The Agent has the following flow:\r\n# 1) revise beliefs\r\n# 2) promotes goals statuses\r\n# 3) detects conflicts\r\n# 4) pursues goals\r\n\r\nclass ReviewAccident(BeliefsReviewer):\r\n    def __init__(self):\r\n        # Call to superclass constructor\r\n        super().__init__(\r\n            desc=\"Review accident data\", attrs=[\"accident\"])  # Attributes can be external events, inputted or not by a simulator. They can also be events that represent communication between agents.\r\n\r\n    async def reviewBeliefs(self):\r\n        # The event queue is cleared each time the entity is processed. Maybe you want to save the beliefs in an object variable.\r\n        beliefs = dict()\r\n        if (\"accident\" in self.eventQueueByTopic):\r\n            # \"-1\" to get the last one in queue\r\n            # Use only JSON-serializable variables as belief values.\r\n            # In fact, in this framework all event values \u200b\u200bmust be serializable to JSON.\r\n            # If you want to use complex structured data, use compositions with Python's dict structure.\r\n            beliefs[\"accident.coord\"] = self.eventQueueByTopic[\"accident\"][-1].value[\"coord\"]\r\n            beliefs[\"accident.hasAtLeastTwoVictims\"] = len(\r\n                self.eventQueueByTopic[\"accident\"][-1].value[\"victims\"]) >= 2\r\n            beliefs[\"accident.severityIsHigh\"] = False\r\n            for victim in self.eventQueueByTopic[\"accident\"][-1].value[\"victims\"]:\r\n                if victim[\"bpm\"] < 60 or victim[\"bpm\"] > 100:\r\n                    beliefs[\"accident.severityIsHigh\"] = True\r\n                if victim[\"mmHg\"][0] > 14 or victim[\"mmHg\"][1] < 6:\r\n                    beliefs[\"accident.severityIsHigh\"] = True\r\n        return beliefs\r\n\r\n# All goal statuses must be True for it to be pursued\r\n\r\n\r\nclass RescuePromoter(GoalStatusPromoter):\r\n    def __init__(self):\r\n        super().__init__(\r\n            desc=\"Promotes rescue goal statuses\", beliefs=[\"accident.hasAtLeastTwoVictims\", \"accident.severityIsHigh\"], promotionNames=[\"intention\"])\r\n\r\n    async def promoteOrDemote(self):\r\n        # The event queue is cleared each time the entity is processed. Maybe you want to save the promotions in an object variable.\r\n        promotions = dict()\r\n        if (\"accident.severityIsHigh\" in self.eventQueueByTopic) and (\"accident.hasAtLeastTwoVictims\" in self.eventQueueByTopic):\r\n            if (self.eventQueueByTopic[\"accident.severityIsHigh\"][-1].value) or (self.eventQueueByTopic[\"accident.hasAtLeastTwoVictims\"][-1].value):\r\n                promotions[\"intention\"] = True\r\n            else:\r\n                promotions[\"intention\"] = False\r\n        return promotions\r\n\r\n\r\nclass RescueAction(Action):\r\n    def __init__(self):\r\n        super().__init__(\r\n            desc=\"Action to rescue victims\", beliefs=[\"accident.coord\"])\r\n\r\n    async def procedure(self) -> None:\r\n        print(\"Rescue at: \" +\r\n              str(self.eventQueueByTopic[\"accident.coord\"][-1].value))\r\n\r\n# Goals with highest priority are pursued first\r\n\r\n\r\nclass Rescue(Goal):\r\n    def __init__(self):\r\n        super().__init__(desc=\"Objective of rescuing victims of serious accidents\",\r\n                                     promoter=RescuePromoter(), plan=[RescueAction()], priority=0)\r\n\r\n# If conflict is detected, the goal with the highest priority is chosen, with the others discarded.\r\n#\r\n# class ConflictOne(Conflict):\r\n#    def __init__(self):\r\n#        super().__init__(\r\n#            desc=\"Recharge battery instead of saving victim\", conflictingGoals=[goalInstance1, goalInstance2])\r\n\r\n\r\nagent1 = Agent(desc=\"Robot that saves victims\", beliefsReviewers=[\r\n               ReviewAccident()], goals=[Rescue()], conflicts=[])\r\n\r\n# Instantiates history to save events.\r\nhistory = InMemoryHistory()\r\n\r\n# Instantiates the event broker, which also controls the execution sequence\r\nbroker = GoalBroker(agents=[agent1], history=history)\r\n\r\nbroker.startProcess()\r\n\r\n# Enter external events, from a simulator for example.\r\nbroker.inputExternalEvents([\r\n    Event(\"accident\", {\"victims\": [\r\n          {\"mmHg\": [120, 80], \"bpm\":50}], \"coord\": [30, 40]})\r\n])\r\n\r\n# instantiates the explanation manager\r\nexplainer = SimpleExplainer(broker, broker.history)\r\n\r\n# Instantiates the explanation generator web graphical interface.\r\ninterface = WebGUI(explainer)\r\n\r\n# Starts the web graphical interface server.\r\n# The IP and port will be printed on the terminal.\r\n# You must open the respective ip and port in the browser.\r\ninterface.server.run()\r\n```\r\n\r\n## References\r\n\r\n<a id=\"1\">[1]</a> C. Castelfranchi and F. Paglieri. The role of beliefs in goal\r\ndynamics: prolegomena to a constructive theory of intentions. Synthese, 155,\r\n237\u2013263, 2007. doi: https://doi.org/10.1007/s11229-006-9156-3\r\n\r\n<a id=\"2\">[2]</a> H. Jasinski and C. Tacla Denerating contrastive explanations\r\nfor BDI-based goal selection. url:\r\nhttp://repositorio.utfpr.edu.br/jspui/handle/1/29522\r\n\r\n<a id=\"3\">[3]</a> J. M. Sim\u00e3o, C. A. Tacla, P. C. Stadzisz and R. F.\r\nBanaszewski, \"Notification Oriented Paradigm (NOP) and Imperative Paradigm: A\r\nComparative Study,\" Journal of Software Engineering and Applications, Vol. 5 No.\r\n6, 2012, pp. 402-416. doi: https://www.doi.org/10.4236/jsea.2012.56047\r\n\r\n## About\r\n\r\nAuthor: Henrique Emanoel Viana, a Brazilian computer scientist, enthusiast of\r\nweb technologies, cel: +55 (41) 99999-4664. URL:\r\nhttps://sites.google.com/view/henriqueviana\r\n\r\nImprovements and suggestions are welcome!\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Library for processing goal-oriented agents. Processing is done on an event-driven mechanism. Events are saved to be used by explanation generating methods.",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/hviana/goalEDP"
    },
    "split_keywords": [
        "scientific",
        " paradigms",
        " agents",
        " explainability"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15190bc62b4f60c5dd4731dd6533ef0a9e7ddfe6bf8491176f3f690acc46894f",
                "md5": "0c25f2f5daddba3a1294b1f1a129d21d",
                "sha256": "7225a5d799dd60012206a3bbc92b5b358afe1382fd79517c067c912237ee2461"
            },
            "downloads": -1,
            "filename": "goalEDP-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c25f2f5daddba3a1294b1f1a129d21d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 20522,
            "upload_time": "2024-03-20T18:58:06",
            "upload_time_iso_8601": "2024-03-20T18:58:06.510532Z",
            "url": "https://files.pythonhosted.org/packages/15/19/0bc62b4f60c5dd4731dd6533ef0a9e7ddfe6bf8491176f3f690acc46894f/goalEDP-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7decce603d65bc073a2cbce830064ea0a8a86ead789d5a3c43852e5c873ef638",
                "md5": "ca56e1421fe9a35d0d912e2ba582930a",
                "sha256": "91b86f0c07b99a1b4096652907fbc9f156852c485f0e6f23e7b28efae9bd2467"
            },
            "downloads": -1,
            "filename": "goalEDP-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "ca56e1421fe9a35d0d912e2ba582930a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 21267,
            "upload_time": "2024-03-20T18:58:08",
            "upload_time_iso_8601": "2024-03-20T18:58:08.564555Z",
            "url": "https://files.pythonhosted.org/packages/7d/ec/ce603d65bc073a2cbce830064ea0a8a86ead789d5a3c43852e5c873ef638/goalEDP-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 18:58:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hviana",
    "github_project": "goalEDP",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "goaledp"
}
        
Elapsed time: 0.61084s