Coder Social home page Coder Social logo

agentframework / agentframework Goto Github PK

View Code? Open in Web Editor NEW
112.0 5.0 3.0 1.58 MB

An elegant & efficient TypeScript metaprogramming API to build software agents

License: Apache License 2.0

TypeScript 100.00%
dependency-injection aop typescript interceptor reflection metadata proxy es6 aspect-oriented-framework agent-oriented-programming serverless

agentframework's Introduction

AgentFramework

An elegant & efficient TypeScript metaprogramming API to build software agents

gzip size


๐Ÿญ Modernize: 100% for TypeScript. Side-effect free tree shaking compatible with ES2015.

โšก Fast: Use CodeGen to minimize overheads. Faster than es6 Proxy.

๐ŸŽฏ Efficient: Well-designed and crafted api only has 1300 SLOC and 5.6kb after minzipped.

โ™ป๏ธ Clean: Transparent dynamic proxy. No prototype pollution. No reflect-metadata or any npm dependencies.

Supported Environment

Platform Version
Node.js 18, 16, 14, 12, 10, 8
TypeScript 4.7, 4.6, 4.5, 4.4, 4.3, 4.2, 4.1, 4.0, 3.9, 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1, 3.0

Changelog

Date Version Status
2022-03-11 2.0.2 Stable
2019-02-27 1.0.0 Maintenance
2018-12-21 0.9.23 EOL
2017-06-30 0.5.12 EOL
2016-11-03 0.2.28 EOL

Install

npm i agentframework

Example code

import { agent, singleton } from 'agentframework';

class ComponentA {
	name = 'Agent Framework';
}

@agent()
class ProjectA {
	@singleton()
	private component!: ComponentA;

	constructor() {
		console.log(`WOW! You working on project ${this.component.name}!`);
	}
}

const project = new ProjectA();

console.log('Is it create from the ProjectA class?', project instanceof ProjectA);

Features

  • Add metadata to your code at design-time (using @decorator) or runtime (using Reflector api)
  • Access the metadata at runtime (using Reflector api)
  • AOP, dependence injection and dependence lookup

Projects

Agent Oriented Programming

Principle

PARADIGM INSPIRATION PRINCIPLE
Function Programming Math It transform data
OOP The world It describe things and the relationships between them
Agent Oriented Programming Human It actions like a human (AI)

Concepts

HUMAN AGENT FRAMEWORK DESCRIPTION
People Agent A class decorate with @agent attribute
Action Behavior Class method decorate with @action, @method or @behavior attribute
Belief Memory Private class field decorated with @state, @remember, @memory attribute
Environment Domain A container for agents, entities, services or artifacts
Autonomy Activation Timer, scheduler which based on environment conditions
Sociality Message Agent can communicate with other agent
Mobility Mobile Agent An agent can move from domain to domain with their belief unchanged

When use Agent Framework

  • You want to build software agents.
  • You want to use dependence injection or dependence lookup.
  • You want to build a framework which similar to Spring Framework but in JavaScript.
  • You want to build an abstract layer for a specific business domain in your organization.
  • You want to remove duplicated code and keep project codebase small and clean.
  • You need a powerful method to pre-process, post-process or modify system behaviors without touching existing code.

Agentframework 2.x milestones

  • Breaking change: Remove I from interface name
  • Breaking change: Remove Intializer. Use Interceptor instead
  • MVP: Dependency injection/dependency lookup and Domain driven design support
  • MVP: Improve unit test coverage rate
  • COMPATIBILITY: Revise error types and message
  • COMPATIBILITY: Revise Domain interface
  • COMPATIBILITY: Revise embedded decorators
  • EPIC: Abstract data layer - mongodb 4.x
  • EPIC: Cross architecture web application development (Server, Serverless)
  • EPIC: Serverless support - AWS Lambda, Google Cloud Function, Azure Function, Alicloud Function Computing
  • EPIC: Bot development (Telegram)
  • Other: Example and references
  • Other: docs.agentframework.com
  • Other: agentframework.com

Agentframework 1.x milestones

  • MVP: Reflection can access type information generated by tsc. tsc --emitDecoratorMetadata
  • MVP: Reflection support both ES6 and ES2017 (Reflect.metadata)
  • MVP: Share metadata across different agentframework library of same application
  • MVP: Both agent or normal class can be used for dependence injection
  • MVP: Add IInitializer to init a field property
  • MVP: Interceptor can work with Initializer during dependence injection
  • EPIC: Create agent without domain
  • EPIC: Provide access to intercepted property value in constructor
  • PERFORMANCE: Metadata only attribute, attribute without interceptor
  • PERFORMANCE: Pre-compile class member interceptors to improve method call performance
  • PERFORMANCE: Caching class constructor interceptors to reduce future class instance creation time.
  • PERFORMANCE: Remove interceptor for @agent attribute to improve performance
  • PERFORMANCE: Do not add proxy if the agent don't have interceptor
  • PERFORMANCE: Remove ES6 Proxy if don't have field interceptor
  • COMPATIBILITY: Move @inject and @ready decorator out from core
  • COMPATIBILITY: GetPrototypeOf should return origin prototype
  • COMPATIBILITY: Agent should works in extended classes
  • COMPATIBILITY: instanceOf should works when compile to proxy
  • COMPATIBILITY: Revise IInvocation Interface
  • COMPATIBILITY: Revise IInitializer Interface
  • COMPATIBILITY: Revise IInterceptor Interface
  • COMPATIBILITY: Revise IAttribute Interface
  • COMPATIBILITY: Revise Reflection Interface
  • COMPATIBILITY: Revise Reflector Interface
  • COMPATIBILITY: Revise Agent Options
  • COMPATIBILITY: Revise Domain Interface (Domain is been completely moved to 2.0)

Special Thanks To:

JetBrains, creators of the IntelliJ IDEA, supports AgentFramework with one of their Open Source Licenses. IntelliJ IDEA is the recommended IDE for working with AgentFramework.

License

Copyright 2022 Ling Zhang!

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

agentframework's People

Contributors

agentframework avatar e2tox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

agentframework's Issues

Examples

Hey there, I'm not too familiar with AOP but it sounds interesting. It would be great if you included some resources on here for how to learn more about it, or perhaps a TodoMVC implementation to look at.

Thanks

Global Annotation

Annotate once and applied to all agent class. The idea is

class Agent {
}

Reflector(Agent).addAttribute(new Attribute())

branch v2.1

Add browser support

Some webpage may have strict CSP policy which not allow eval.

EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive:

Need remove all eval code

Error: Invalid "exports" main target "lib/index.js" defined in the package config

Latest verison 2.0.2 in npm repository adds exports key to package.json file:

  "exports": {
    ".": {
      "import": "lib/index.mjs",
      "require": "lib/index.js",
      "types": "lib/index.d.ts"
    }

which throws error on usage:

Error: Invalid "exports" main target "lib/index.js" defined in the package config /home/retreat/projects/agent-hello-world/node_modules/agentframework/package.json; targets must start with "./"

Downgrading to node v12.14.1 (npm v6.13.4) solves the issue.

version 2.0.1 works fine on both v16.13.0 and 12.14.1.

using:

  • Ubuntu 18.04.6 LTS
  • tsmon v0.9.1
  • typescript v4.4.4
  • node v16.13.0

Add documentation for @inject decorator

@Inject will do dependency injection when user create a new agent class.

e.g

class Calculator {
   add(left:number, right: number): number {
     return left + right;
   }
}

@agent('awesome')
class MyAgent {

   @inject(Calculator)
   calculator: Calculator

}


const agent = new MyAgent();

console.log(agent.calculator.add(1,3));
// 4

Add tsm.run support

esm.run will obfuscate all class name into: a,b,c,d,e....

need review code and fix any possible issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.