{"id":21221426,"url":"https://github.com/8t4/mas-unity-sample","last_synced_at":"2025-07-10T18:35:05.497Z","repository":{"id":133847430,"uuid":"384446526","full_name":"8T4/mas-unity-sample","owner":"8T4","description":"MAS Unity Sample repository","archived":false,"fork":false,"pushed_at":"2021-08-05T20:10:25.000Z","size":249,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T01:14:14.910Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/8T4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-09T13:32:37.000Z","updated_at":"2021-08-24T14:12:00.000Z","dependencies_parsed_at":"2023-09-01T00:26:49.859Z","dependency_job_id":null,"html_url":"https://github.com/8T4/mas-unity-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/8T4/mas-unity-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8T4%2Fmas-unity-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8T4%2Fmas-unity-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8T4%2Fmas-unity-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8T4%2Fmas-unity-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/8T4","download_url":"https://codeload.github.com/8T4/mas-unity-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8T4%2Fmas-unity-sample/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264631212,"owners_count":23640941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T22:27:51.651Z","updated_at":"2025-07-10T18:35:05.446Z","avatar_url":"https://github.com/8T4.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"                                                                                               \n\u003cp align='center'\u003e\n    \u003cimg width=192\" src=\"https://raw.githubusercontent.com/8T4/mas-unity/main/docs/imgs/logo.png\" /\u003e\n    \u003cbr/\u003eIt is a dotnet framework that helps in the development of MAS (Multi-agent systems) applied to integrative business information systems (IBIS). MAS Unity will assist in the construction, deployment and monitoring of a cluster of autonomous agents.\n\u003c/p\u003e\n\n# How to implement Agents using MAS Unity\nThis repository has a sample of the application of [MAS Unity](https://github.com/8T4/mas-unity). This code presents an example of an agent that performs the credit analysis after purchase. The following steps show the implementation of the sample project.\n\n## Dependencies\nThe sample project was created as a web API with ASP.NET Core, and uses the [MAS Unity](https://github.com/8T4/mas-unity) dependencies:\n\n```\nInstall-Package MasUnity\nInstall-Package MasUnity.HostedService\nInstall-Package MasUnity.HealthCheck\n```\n\n[Tutorial: Create a web API with ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0\u0026tabs=visual-studio)\n\n## Modeling\nIt's important to keep your Agent code organized and easy to maintain. This section will provide a modeling tactical approach to achieve a satisfactory maintainability level. For this, it's recommended to use a domain-model approach to approximate the Agent of own acting environment. In this sense, we propose this modeling structure:\n\n```\nProject/\n│  \n├─ Use cases/\n│  │  \n│  ├─ Agents/\n│  │  │\n│  │  ├─ Actions/\n│  │  │  ├─ Action.cs\n│  │  │  │\n│  │  ├─ Knowledges/\n│  │  │  ├─ Knowledge.cs\n│  │  │  │\n│  │  ├─ Agent.cs\n│  │  ├─ Schedule.cs\n│  │  │  \n│  ├─ Environment/\n│  │  │  ├─ Environment.cs\n```\n\n- [**Use case**](https://en.wikipedia.org/wiki/Use_case): is a list of actions or event steps typically defining the interactions between a Agent and a system to achieve a goal. \n                                                                                                 \n- [**Agents**](https://www.researchgate.net/publication/222827222): an agent is a computer system that is situated in some environment, and that is capable of autonomous action in this environment in order to meet its design objectives.\n                                                                                                 \n- [**Actions**](https://www.researchgate.net/publication/222827222): each agent is responsible for performing tasks to solve partial problems. MAS supports task synchronization, task allocation, task sharing, and result sharing\n                                                                                                 \n- [**Knowledge**](https://www.researchgate.net/publication/222827222): is an integral part of the intelligent agent and multi-agent systems paradigm. Agents possess knowledge and act based on their own knowledge, beliefs, desires, and intentions.\n\n- [**Environment**](https://www.researchgate.net/publication/222827222): system operates in an environment which is similar to the notion of the environment of an organization and that of a multi-agent system.\n                                                                                                 \n\n## Coding\nOur sample simulates a purchase analysis environment. In this context, the Agent verify if the transaction is a credit card transaction. Given some conditions, this Agent should allow or deny the transaction. For this, the Agent realizes the transaction and choose de appropiated action to be executed. The following subsections ilustrates the implementation of Action, Knowledges and Agents classes in this sample.                                                                                                    \n                                                                                                 \n### Actions\nAn Action is a class that implements the `Realize` and `Execute` methods of `IAction` interface. How is shown in the following code:\n                                                                                                 \n```c#\npublic class AllowCreditCardTransaction : IAction\n{\n    ...\n                                                                                                 \n    public Task\u003cPerception\u003e Realize(AgentContext context, CancellationToken cancellation)\n    {\n        Transaction = Queue.GetNext();\n\n        return Perception.Assertion(\n            (\"It's a credit card transaction\", Transaction.IsCreditCardTransaction()),\n            (\"It's normal transaction time\", AboutTransactionSchedule.ItsNormalTransactionSchedule()),\n            (\"It's a safe credit card transactions\", Knowledge.IsSafeTransaction(Transaction))\n        );\n    }\n\n    public async Task\u003cAgentResult\u003e Execute(AgentContext context, CancellationToken cancellation)\n    {\n        await Queue.SaveAsApprovedTransaction(Transaction);\n        return AgentResult.Ok($\"{Transaction.Id} Allowed\");\n    }\n}  \n```\nSee all [actions code](https://github.com/8T4/mas-unity-sample/tree/main/MyBusiness.Compliance/RiskAnalysis/Agents/CreditRisk/Actions) in sample project.\n\n\n### Knowledges\nThe Knowledge class implement the interface `IKnowledge`. This interface is used only for injection concerns. The following code ilustrate the Knowledge implementation:\n                 \n```c#\n//Transactions after 20 PM               \npublic class AboutCreditCardTransactionAfter20Pm : IKnowledge\n{\n    public bool IsUnsafeTransaction(Transaction transaction) =\u003e\n        transaction.IsCreditCardTransaction() \u0026\u0026 transaction.Value \u003e= 2500 \u0026\u0026 transaction.ReliabilityRating \u003c= 3;\n}\n\n//Transactions between 8AM and 20 PM                  \npublic class AboutCreditCardTransactionBetween8AmAnd20Pm : IKnowledge\n{\n    public bool IsSafeTransaction(Transaction transaction) =\u003e\n        transaction.IsCreditCardTransaction() \u0026\u0026 !IsUnsafeTransaction(transaction);\n\n    public bool IsUnsafeTransaction(Transaction transaction) =\u003e\n        transaction.IsCreditCardTransaction() \u0026\u0026 transaction.Value \u003e= 4500 \u0026\u0026 transaction.ReliabilityRating \u003c 3;\n}\n```\nSee all [Knowledges code](https://github.com/8T4/mas-unity-sample/tree/main/MyBusiness.Compliance/RiskAnalysis/Agents/CreditRisk/Knowledges) in sample project.\n                 \n### Agent\nThe Agent class might inherit a `PoractiveAgent` (wich demands a schedule) or a `ReactiveAgent` (wich execution depends of a directily call). Both parent classes demands the implementation of `RegisterActions` method. The following code ilustrate the Agent implementation:\n\n```c#\npublic class CreditRiskAgent: ProactiveAgent\n{\n    private readonly IAgentServiceScope _scope;\n\n    public CreditRiskAgent(IAgentServiceScope scope, CreditRiskAgentSchedule schedule) : base(schedule)\n    {\n        _scope = scope;\n    }\n\n    protected override IEnumerable\u003cIAction\u003e RegisterActions()\n    {\n        yield return _scope.GetService\u003cAllowCreditCardTransaction\u003e();\n        yield return _scope.GetService\u003cDenyCreditCardTransaction\u003e();\n        yield return _scope.GetService\u003cDenyCreditCardTransactionAfter20Pm\u003e();\n    }\n}\n```\n\n## Configuring\n                 \n### Configuring MAS Unity services in Asp.net application\n\nThe following code ilustrate the configutration of five instances of MAS Unity Agents in Asp.net application\n\n```c#\npublic class Startup\n{\n    public void ConfigureServices(IServiceCollection services)\n    {\n        ...\n                 \n        services.ConfigureMasUnity((option) =\u003e\n        {\n            option.AddAgent\u003cCreditRiskAgent\u003e(5)\n                .WithSchedule\u003cCreditRiskAgentSchedule\u003e()\n                .WithEnvironment\u003cPendingTransactions\u003e()\n                .WithKnowledge\u003cAboutCreditCardTransactionAfter20Pm\u003e()\n                .WithKnowledge\u003cAboutCreditCardTransactionBetween8AmAnd20Pm\u003e()\n                .WithAction\u003cAllowCreditCardTransaction\u003e()\n                .WithAction\u003cDenyCreditCardTransaction\u003e()\n                .WithAction\u003cDenyCreditCardTransactionAfter20Pm\u003e()\n                .WithHealtCheck()\n                .Build();\n        });\n    }\n}                 \n```\nSee all [code](https://github.com/8T4/mas-unity-sample/blob/main/MyBusiness.Compliance/Startup.cs) in sample project\n                 \n### Configuring Health check and Open API\n\nsee this [code](https://github.com/8T4/mas-unity-sample/blob/main/MyBusiness.Compliance/Configuration/DependencyInjection.cs) to understand how to configure Health Check and Open API for your Agents.\n                 \n## Running\n### Health Check\nWhen you configure your agente using the method `.WithHealtCheck()`, it's possible monitoring the health of each agent instance.                 \n![hc](https://raw.githubusercontent.com/8T4/mas-unity-sample/main/docs/imgs/hc.png)\n\n### Open API Contract\nMAS Unity provides a controller to manipulate the Agent instance execution.         \n![hc](https://raw.githubusercontent.com/8T4/mas-unity-sample/main/docs/imgs/oa.png)         \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8t4%2Fmas-unity-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F8t4%2Fmas-unity-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8t4%2Fmas-unity-sample/lists"}