{"id":13522312,"url":"https://github.com/bhouston/behave-graph","last_synced_at":"2025-04-04T21:08:04.171Z","repository":{"id":37881377,"uuid":"506333694","full_name":"bhouston/behave-graph","owner":"bhouston","description":"Open, extensible, small and simple behaviour-graph execution engine.  Discord here: https://discord.gg/mrags8WyuH","archived":false,"fork":false,"pushed_at":"2023-11-29T14:50:51.000Z","size":6417,"stargazers_count":316,"open_issues_count":23,"forks_count":30,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-01T17:43:19.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bhouston.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-06-22T16:56:00.000Z","updated_at":"2025-02-01T04:27:06.000Z","dependencies_parsed_at":"2024-01-13T22:59:26.032Z","dependency_job_id":"fa2c52af-a20d-441c-885f-50fe4eeeb51a","html_url":"https://github.com/bhouston/behave-graph","commit_stats":{"total_commits":608,"total_committers":8,"mean_commits":76.0,"dds":0.5575657894736843,"last_synced_commit":"0be63fbd4adb2cf7277f337d26b34e279ba8e248"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhouston%2Fbehave-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhouston%2Fbehave-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhouston%2Fbehave-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhouston%2Fbehave-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhouston","download_url":"https://codeload.github.com/bhouston/behave-graph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249525,"owners_count":20908212,"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-08-01T06:00:45.550Z","updated_at":"2025-04-04T21:08:04.146Z","avatar_url":"https://github.com/bhouston.png","language":"TypeScript","funding_links":[],"categories":["Javascript Libraries"],"sub_categories":["Graph Utilities"],"readme":"# Behave-Graph\n\n[![GitHub license](https://img.shields.io/npm/l/behave-graph)](https://github.com/bhouston/behave-graph/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/@behave-graph/core)](https://www.npmjs.com/package/@behave-graph/core)\n\nBehave-Graph is a standalone library that implements the concept of \"behavior graphs\" as a portable TypeScript library with no required external run-time dependencies. Behavior graphs are expressive, deterministic, and extensible state machines that can encode arbitrarily complex behavior.\n\nBehavior graphs are used extensively in game development as a visual scripting language. For example, look at Unreal Engine Blueprints or Unity's Visual Scripting or NVIDIA Omniverse's OmniGraph behavior graphs.\n\nThis library is intended to follow industry best practices in terms of behavior graphs. It is also designed to be compatible with these existing implementations in terms of capabilities. Although, like all node-based systems, behavior graphs are always limited by their node implementations.\n\nAnother neat fact about behavior graphs is that they offer a sand boxed execution model. Because one can only execute what is defined by nodes exposed by the host system, you can restrict what can be executed by these graphs. This type of sand-boxing is not possible when you just load and execute arbitrary scripts.\n\n## Documentation\n\n- [Extending the Value System](/docs/Values.md)\n- [Types Of Nodes](/docs/TypesOfNodes.md)\n- [Abstractions and Drivers](/docs/Abstractions.md)\n\n## Community Resources\n\nYou can join our Discord here:\n\n\u003chttps://discord.gg/mrags8WyuH\u003e\n\n## Feature Overview\n\nThis library, while small, contains a nearly complete implementation of behavior graphs along with extensions for 3D math types and scenes. It also contained a graph editor React library.\n\n### Features\n\n- **Customizable** While this library contains a lot of nodes, you do not have to expose all of them. For example, just because this supports for-loops and state, does not mean you have to register that node type as being available.\n- **Type Safe** This library is implemented in TypeScript and fully makes use of its type safety features.\n- **Small** This is a very small library with no external dependencies.\n- **Simple** This library is implemented in a forward fashion without unnecessary complexity.\n- **High Performance** Currently in performance testing, the library achieves over 2M node executions per second.\n\n### Node Types\n\n- **Events** You can implement arbitrary events that start execution: Start, Tick\n- **Actions** You can implement actions that trigger animations, scene scene variations, or update internal state: Log\n- **Logic** You can do arithmetic, trigonometry as well as vector operations and string manipulation: Add, Subtract, Multiply, Divide, Pow, Exp, Log, Log2, Log10, Min, Max, Round, Ceil, Floor, Sign, Abs, Trunc, Sqrt, Negate, And, Or, Not, ==, \u003e, \u003e=, \u003c, \u003c=, isNan, isInfinity, concat, includes.\n- **Queries** You can query the state from the system.\n- **Flow Control** Control execution flow using familiar structures: Branch, Delay, Debounce, Throttle, FlipFlop, Sequence, Gate, MultiGate, DoOnce, DoN, ForLoop\n- **Variables** You can create, set and get variable values.\n- **Custom Events** You can create, listen to and trigger custom events.\n\n### Designed for Integration into Other Systems\n\nThis library is designed to be extended with context dependent nodes, specifically Actions, Events and Queries that match the capabilities and requirements of your system. For example, if you integrate into a 3D engine, you can query for player state or 3D positions of your scene graph, set scene graph properties and also react to overlaps, and player movements. Or if you want to integrate into an AR system, you can react to face-detected, tracking-loss.\n\n## Developer Setup\n\nInstall all dependencies:\n\n```zsh\nnpm install\n```\n\nTo do a full development build with hot reloading and a built-in dev server (via vite) run:\n\n```zsh\nnpm run dev\n```\n\nIf you are curious about the monorepository setup, you can read more about it here:\n\nhttps://github.com/bhouston/template-modern-typescript-monorepo\n\n## Command Line Examples\n\nThe example behavior graphs are in the `/examples` folder. You can execute these from the command line to test out how this library works.\n\nThe main syntax is this one:\n\n```zsh\nnpx exec-graph ./graphs/[examplename].json\n```\n\nHere are some example graphs in their native JSON form:\n\n### Hello World\n\nPrint out the text \"Hello World!\" as soon as the graph starts up!\n\n[/graphs/core/HelloWorld.json](/graphs/core/HelloWorld.json)\n\nConsole output:\n\n```sh\nnpx exec-graph ./graphs/core/HelloWorld.json\n```\n\nConsole output:\n\n```sh\nHello World!\n```\n\n### Setting, Reading, And Listening to Variables\n\nIn this example, we use set a variable and also listen to when it changes.\n\n[/graphs/variables/Changed.json](/graphs/variables/Changed.json)\n\nConsole output:\n\n```sh\nnpx exec-graph ./graphs/core/variables/Changed.json\n```\n\nConsole output:\n\n```sh\n391\n```\n\n### Branching\n\nThis example shows how to branching execution works. The \"flow/branch\" node has two flow outputs, \"true\" and \"false\". The value of it's \"condition\" input determines the path of execution.\n\n[/graphs/core/flow/Branch.json](/graphs/core/flow/Branch.json)\n\nCommand:\n\n```sh\nnpx exec-graph ./graphs/core/flow/Branch.json\n```\n\nConsole output:\n\n```sh\nCondition is false!\n```\n\n### Polynomial Math Formula\n\nThis shows how to create math formulas in logic nodes. In this case the equation is: ( a^1 \\* 3 + a^2 + (-a^3) ), where a = 3. The answer is -9.\n\n[/graphs/core/logic/Polynomial.json](/graphs/core/logic/Polynomial.json)\n\nCommand:\n\n```sh\nnpx exec-graph ./graphs/core/logic/Polynomial.json\n```\n\nConsole output:\n\n```sh\n-9\n```\n\n### Asynchronous Execution\n\nBehave-Graph support asynchronous nodes. These are nodes which will continue execution non-immediately but on their own self-determined schedule. This allows for things such as \"Delay\" nodes that can sleep for a period of time.\n\n[/graphs/core/async/Delay.json](/graphs/core/async/Delay.json)\n\nCommand:\n\n```sh\nnpx exec-graph ./graphs/core/async/Delay.json\n```\n\nConsole output:\n\n```sh\nWaiting...\nOne Second Later!\n```\n\n### For Loops\n\nBuilding upon waiting for downstream nodes to execute, you can also execute For Loops within Behave-Graph.\n\n[/graphs/core/flow/ForLoop.json](/graphs/core/flow/ForLoop.json)\n\nCommand:\n\n```sh\nnpx exec-graph ./graphs/core/flow/ForLoop.json\n```\n\nConsole output:\n\n```sh\nStarting For Loop...\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nLoop Body!\nCompleted For Loop!\n```\n\n# Custom Events\n\nYou can register custom events, trigger then and listen on them.\n\n[/graphs/core/events/CustomEvents.json](/graphs/core/events/CustomEvents.json)\n\nConsole output:\n\n```sh\nnpx exec-graph ./graphs/core/events/CustomEvents.json\n```\n\nConsole output:\n\n```sh\nmyCustomEvent Fired!\nmyCustomEvent Fired!\nmyCustomEvent Fired!\nmyCustomEvent Fired!\nmyCustomEvent Fired!\n```\n\n# Performance Testing\n\nHere is a test of 10,000,000 iteration for loop:\n\n[/graphs/core/flow/PerformanceTest.json](/graphs/core/flow/PerformanceTest.json)\n\nHere is the command running with verbose logging, e.g. \"-l 0\":\n\n```sh\nnpx exec-graph ./graphs/core/flow/PerformanceTest.json -l 0\n```\n\nConsole output:\n\n```sh\nStarting 10,000,000 iteration for-loop...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\n1,000,000 more iterations...\nCompleted all iterations!\n\n  Profile Results: 30000014 nodes executed in 2.742 seconds, at a rate of 10940924 steps/second\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhouston%2Fbehave-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhouston%2Fbehave-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhouston%2Fbehave-graph/lists"}