Skip to content

Commit

Permalink
init. copy from agencyai
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorgoolsby committed Jan 29, 2024
0 parents commit 7139454
Show file tree
Hide file tree
Showing 603 changed files with 80,398 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .elasticbeanstalk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
branch-defaults:
master:
environment: agencyai-gg-prod-backend
group_suffix: null
deploy:
artifact: artifact.zip
global:
application_name: agencyai-gg
branch: null
default_ec2_keyname: null
default_platform: Node.js 18 running on 64bit Amazon Linux 2023
default_region: us-east-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: null
repository: null
sc: git
workspace_type: Application
21 changes: 21 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[ignore]
<PROJECT_ROOT>/node_modules/resolve/.*
<PROJECT_ROOT>/src/web/node_modules/resolve/test/resolver/.*
<PROJECT_ROOT>/src/cloud/node_modules/resolve/test/resolver/.*

[include]

[libs]

[lints]

[options]
exact_by_default=false
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.mjs
module.file_ext=.cjs
module.file_ext=.json
module.file_ext=.scss

[strict]
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node_modules
.idea
dist
esm
cjs
secrets/.env
.env
.env.staging
.env.production
.dynamodb
build
.serverless
yarn-error.log
.DS_Store
artifact.zip
artifact
.cdk.staging
cdk.out
.next
_next
15 changes: 15 additions & 0 deletions .graphqlconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Untitled GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "http://localhost:4000/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
8 changes: 8 additions & 0 deletions .platform/confighooks/prebuild/00_npm_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
cd /var/app/staging
sudo -u webapp npm uninstall cross-env
sudo -u webapp npm install cross-env
cd backend
sudo -u webapp npm install file:../common
sudo -u webapp npm uninstall bcrypt
sudo -u webapp npm install bcrypt
8 changes: 8 additions & 0 deletions .platform/hooks/prebuild/00_npm_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
cd /var/app/staging
sudo -u webapp npm uninstall cross-env
sudo -u webapp npm install cross-env
cd backend
sudo -u webapp npm install file:../common
sudo -u webapp npm uninstall bcrypt
sudo -u webapp npm install bcrypt
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"semi": false,
"printWidth": 80,
"singleQuote": true
}
52 changes: 52 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"app": "node build/cloud/bin/cdk-test.js",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"package*.json",
"yarn.lock",
"node_modules",
"tests"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true
}
}
76 changes: 76 additions & 0 deletions docs/initial-schema-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Initial Schema Scope

This is a SaaS app which is a simple UI for managing and building multiagent AI systems.

Here is a rough outline of the how the app works technically:

1. (Creating AI Agencies) There is a UI which allows end users to:
1. Create a new multiagent AI environment. This could also be called a multiagent organization or a commune.
2. Within an organization, multiple agents can be defined.
3. Each agent runs on ChatGPT.
3. Each agent has a unique name within the organization for identification purposes and referencing.
4. Each agent has custom instructions which is a string of text to be given to the agent when it first starts up. It is the first string of text the agent will see for this instance of conversation.
5. The custom instructions contains rules about how the agent should respond to certain inputs. These rules might inform the agent to check the FROM directive and react a certain way depending on which other agent sent them the message, and who to send a message to in response using the TO directive.
6. To encode rules about how agents are to interact with each other, the custom instructions contains rules about how the agent's response should be formatted. Each output should start with a TO directive. For example, "TO Programmer:". Our system will read the TO directive, which contains the unique identifier of the other agent the message is to be forwarded to, and our system will forward the message from the first agent to the TO agent. The forwarded message will start with a FROM directive which informs the agent receiving the forwarded message where the message came from. This is how the agents will know who they are talking to.
7. Defining the custom instruction might be like an ad lib to make things easier for the end user to define agent rules. For example, "When <message is from X>, <do something> and <send response to Y>". The custom instruction will be parsed and converted into the proper format for the agent to understand.
2. (Publishing AI Agencies) Once an organization is created, it can be published to the public. This will make the organization available to other users to interact with via API.
1. Each organization was given a unique identifier when it was created. This is used for creating unique API endpoints for each organization. For example: https://multiagent.ai/organizations/12345
2. This is meant to be a drop-in replacement for existing integrations with ChatGPT. If you have a SaaS built on top of the ChatGPT API which uses a single agent approach for your app's operation, then using this multiagent management solution, you can define a multiagent organization with multiple agents, and then publish the organization to the public. This will create a new API endpoint for your organization which will be a drop-in replacement for your existing ChatGPT API endpoint. The only difference is that the new API endpoint will be a multiagent endpoint. Third-party apps which access the API cannot tell the difference between a single agent endpoint and a multiagent endpoint.
3. When a new conversation is started via API to a multiagent organization, new instances of the agents defined in the organization will be created. Each agent will be given the custom instructions defined in the organization. The agents will then interact with each other according to the rules defined in the custom instructions.
4. There will always be an agent in every organization which handles the interfacing between the API and the rest of the organization. This agent is like a manager, forwarding requests from the API to the other agents in the organization. This agent is also responsible for sending responses back to the API. This agent is the only agent which has access to the API. The other agents in the organization do not have access to the API. It handles unpacking a request to multiple agents and also packing multiple responses from multiple agents into a single response to the API.
5. Access to this API is private. An `Authorization` header is required to gain access. This is the same as the ChatGPT API. If the end user has a SaaS that is intended to be a public API, then they are expected to build a wrapper API, which is public, around the private API so that they can monitor usage and charge for usage.
6. The API is a REST API. It is a drop-in replacement for the ChatGPT API. The only difference is that the API is multiagent. The API is not a GraphQL API. The API is not a Websocket API. The API is not a gRPC API. The API is not a JSON-RPC API.

## GraphQL Schema

The GraphQL schema is used as a schema management solution. The MySQL tables are able to be generated from it (using the @sql directive to inform which types and fields should be converted into tables and columns), and all data from the database passes through it, so it can redact sensitive information (using the @private directive to inform which fields should be redacted before being sent to the client).

The GraphQL schema is also used to generate the TypeScript types for the client and server.

The GraphQL schema is also used to generate the API documentation.

The GraphQL schema may also used to generate the API tests using AI to generate end to end tests from the schema later down the road.

For this project specifically, here are the types and fields needed:

- User
- id
- email
- password
- openAIKey
- Agency
- id
- versionId (shared between organizations after restructuring)
- userId
- name
- Agent
- id
- agencyId
- name
- Instructions
- id
- agentId
- Block
- id
- instructionId
- type
- data
- Conversation
- id
- agentId
- Message
- id
- conversationId
- data
- from (null if from API otherwise agentId)
- to (null if to API, otherwise agentId)
- text
- timestamp
- AuthKey
- id
- agencyId
- name (user defined name such as dev or prod)
- key (encrypted at rest)
- deletedAt
- createdAt
- expiresAt
49 changes: 49 additions & 0 deletions docs/message-management-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Message Management

This is a UI for building and managing multiagent AI.

There are multiple agents which will be talking to each other.
Each agent maintains its own context as a list of messages which are included with every chat completions API call to OpenAI.

## Spec

* While the end user is interacting with the agency, a single agent, designated as the manager, will handle all communications with the end user via our third-party API.
* When the end user sends a message through our third-party API, the manager receives the message.
* Later, the manager may send a message back to the end user via our third-party API.
* The manager is responsible for forwarding messages to the other agents in the agency, and coordinating the other agents in order to reach a consensus on what to send back to the end user.
* Besides the above details, the manager is an agent just like any other agent in the agency.
* When a new conversation is started with the agency, a conversation is started with each individual agent in the agency.
* A conversation with an agent is a list of messages which are included in the OpenAI chat completions API call for that agent.
* Each agent's conversation starts with a system message which contains all the principles and instructions the agent should follow, and also a list of all the other agents in the agency.
* Each item in the list of agents is formatted as an ID number and a name. For example, `#143 (programmer)`, or `#224 (designer)`, or `#3543 (tester)`, or `#4522 (manager)`.
* Each agent is also instructed to respond in JSON format. The response is a JSON containing a "to" key whose value of type number and is the ID number. The name is not included. The response JSON also has a "context" key whose value is of type string and is the agent's response. This is how the agent will generate a response and designate who the response is for.
* A JSON response with a "to" field equal to `0` is a response to the end user.
* A JSON response with a "to" field equal to any other number is a response to the agent with that ID number.

## Database Spec

* For a given agency, there may be multiple conversations.
* For a given conversation, there may be multiple messages.
* A given message is not only associated with the conversationId, but also the agentId.

## Database Schema

* Message
* messageId
* conversationId
* agentId
* role (system, assistant, user)
* linkedMessageId (null if not linked to another message)
* data
* from (null if from API otherwise agentId)
* to (null if to API, otherwise agentId)
* text
* dateCreated

## API Spec

* POST /api/agency/:agencyId/chat/completions
* messages: Array<{role: string, content: string}>
* Creates a model response for the given chat conversation.
* If a message with system role is included, then the system message is appended to the system message we generate for the manager. This is similar to how custom instructions in ChatGPT work.
* The system message we generate is private and will not be exposed through the API, but your custom system message will be echoed back.
Loading

0 comments on commit 7139454

Please sign in to comment.