GithubHelp home page GithubHelp logo

ai-legion's Introduction

AI Legion: an LLM-powered autonomous agent platform

A framework for autonomous agents who can work together to accomplish tasks.

Discord

Setup

You will need at least Node 10.

npm install

Rename the .env.template file at the root of the project to .env and add your secrets to it:

OPENAI_API_KEY=... # obtain from https://platform.openai.com/account/api-keys
# the following are needed for the agent to be able to search the web:
GOOGLE_SEARCH_ENGINE_ID=... # create a custom search engine at https://cse.google.com/cse/all
GOOGLE_API_KEY=... # obtain from https://console.cloud.google.com/apis/credentials
AGENT_DELAY=... # optionally, a delay in milliseconds following every agent action

You'll also need to enable the Google Custom Search API for your Google Cloud account, e.g. https://console.cloud.google.com/apis/library/customsearch.googleapis.com

Running

Start the program:

npm run start [# of agents] [gpt-3.5-turbo|gpt-4]

Interact with the agents through the console. Anything you type will be sent as a message to all agents currently.

Action errors

After spinning up a new agent, you will often see them make some mistakes which generate errors:

  • Trying to use an action before they've asked for help on it to know what its parameters are
  • Trying to just use a raw text response instead of a correctly-formatted action (or raw text wrapping a code block which contains a valid action)
  • Trying to use a multi-line parameter value without wrapping it in the multiline delimiter (% ff9d7713-0bb0-40d4-823c-5a66de48761b)

This is a normal period of adjustment as they learn to operate themselves. They generally will learn from these mistakes and recover, although gpt-3.5-turbo agents sometimes devolve into endless error loops and can't figure out what the problem is. It's highly advised never to leave an agent unattended, since such infinite loops can eat through your tokens quickly (especially if they're stuck on a high-token-count action such as writeFile).

Agent state

Each agent stores its state under the .store directory. Agent 1, for example, has

.store/1/memory
.store/1/goals
.store/1/notes

You can simply delete any of these things, or the whole agent folder (or the whole .store) to selectively wipe whatever state you want between runs. Otherwise, agents will pick up where you left off on restart.

A nice aspect of this is that when you want to debug a problem you ran into with a particular agent, you can delete the events in their memory subsequent to the point where the problem occurred, make changes to the code, and restart them to effectively replay that moment until you've fixed the bug. You can also ask an agent to implement a feature, and once they've done so you can restart, tell them that you've loaded the feature, and ask them to try it out.

ai-legion's People

Contributors

eumemic avatar foolishsailor avatar jamiew avatar jgeewax avatar malikmalna avatar thebitmonkey 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  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

ai-legion's Issues

Agent stuck in a loop

The agent is stuck in a loop.

=============

Agent 1 -> System:

writeNote
title: Resources for Ruby on Rails Learning
content:
% ff9d7713-0bb0-40d4-823c-5a66de48761b%
- Ruby on Rails Guides: https://guides.rubyonrails.org/
- Ruby on Rails API: https://api.rubyonrails.org/
- Intermediate Rails: Understanding Models, Views and Controllers: https://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
% ff9d7713-0bb0-40d4-823c-5a66de48761b%

viewNote
title: Resources for Ruby on Rails Learning

=============

System -> Agent 1:

--- ERROR ---

Your action could not be parsed. Did you fail to wrap the entirety of a multi-line parameter value with the multi-line delimiter (`% ff9d7713-0bb0-40d4-823c-5a66de48761b`)?

=============

Adding Temperature Option to ChatCompletion

I noticed that in make-decision.ts there isn't an included temperature. I think it's important to consider given how temperature settings can influence rates of hallucination in the bot. Would it be okay for me to add a setting for that in the make-decisions.ts (I would set it 0.0 by default to reduce the likelihood of hallucinations, but I'm open to suggestions for what the value should be by default and why)?

Error: Model 'gpt-4' is unavailable in openai.ts

I encountered an error while trying to use the GPT-4 model (GPT-3.5-turbo works fine) within the project. The error message is as follows:

Agent 1 encountered the following problem while attempting to take action:
Error: Model 'gpt-4' is unavailable.
    at task (C:\Microsoft\legion\src\openai.ts:35:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async C:\Microsoft\legion\src\make-decision.ts:22:29

Please investigate this issue and provide guidance on how to resolve it. Thank you!

What am i doing wrong?

anyone knows why i get this error:

PS D:\Github\ai-legion-master> npm run start 5 gpt-4

[email protected] start
ts-node src/main.ts 5 gpt-4

D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
src/openai.ts:22:21 - error TS2339: Property 'content' does not exist on type 'AxiosResponse<CreateChatCompletionResponse, any>'.

22 return response.content;
~~~~~~~

at createTSError (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:859:12)
at reportTSError (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:863:19)
at getOutput (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:1077:36)
at Object.compile (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:1433:41)
at Module.m._compile (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
at Object.require.extensions.<computed> [as .ts] (D:\Github\ai-legion-master\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Function.Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19) {

diagnosticCodes: [ 2339 ]
}

Stuck in a multi-line delimiter error loop.

Agent 1 -> System:

writeNote
title: Trending NFT Collections at TradePort.xyz
content: % ff9d7713-0bb0-40d4-823c-5a66de48761b
The website summary does not provide detailed information on the respective volumes of the trending NFT collections. It would be necessary to visit the site and retrieve the information manually.
% ff9d7713-0bb0-40d4-823c-5a66de48761b

sendMessage
recipient: Control
message: % ff9d7713-0bb0-40d4-823c-5a66de48761b
I could not find the detailed information on the respective volumes of the trending NFT collections directly from TradePort.xyz. To obtain the requested data, it would be necessary to visit the site and retrieve the information manually.
% ff9d7713-0bb0-40d4-823c-5a66de48761b

=============

System -> Agent 1:

--- ERROR ---

Your action could not be parsed. Did you fail to wrap the entirety of a multi-line parameter value with the multi-line delimiter (% ff9d7713-0bb0-40d4-823c-5a66de48761b)?

Got the AI to review its codebase. These are the suggestions it gave back.

Instructed the AI to review its own codebase for improvement/optimization. This is the advice that it gave back for doing so:

Based on the codebase overview and the code optimization techniques, here are some suggestions for improvement and/or optimization:

1. In the `Agent` class, the `takeAction` method has a `sleep` function call in the `finally` block. This could be replaced with a more efficient scheduling mechanism, such as using `setTimeout` or `setInterval` to schedule the next action.

2. The `Memory` class could benefit from more advanced compression techniques to reduce the memory footprint and improve performance. This could include using data structures like Bloom filters or more efficient serialization methods.

3. The `Message` class and related functions could be refactored to use a more efficient data structure or encoding method to reduce the overhead of message passing between agents.

4. The `ModuleManager` class could be optimized by using a more efficient data structure for storing and retrieving module definitions, such as a trie or a hash table.

5. The `ActionHandler` class could be optimized by using a more efficient method for dispatching actions, such as a priority queue or a task scheduler.

6. The codebase could benefit from more aggressive inlining of small functions to reduce function call overhead.

7. Dead code elimination and constant propagation could be applied to the codebase to remove unnecessary code and simplify expressions.

8. Global register allocation could be used to optimize variable storage and access in the codebase.

These are just a few suggestions for improvement and optimization. Further analysis and profiling of the codebase would be necessary to identify more specific areas for optimization.

With a bit more instruction, I can probably get it to implement some of these suggestions into the codebase, but this seems to be one of the first autonomous AI, possibly the first written in TypeScript, which might actually have the potential to effectively improve itself.

Cannot find module 'fs/promises'

I am getting the following error on running npm run start

srijan@SRIJAN-DESKTOP:~/gpt-legion$ npm run start

> [email protected] start
> ts-node src/main.ts

Number of agents: 1
Model: gpt-3.5-turbo
Error: Cannot find module 'fs/promises'
Require stack:
- /home/srijan/gpt-legion/src/module/definitions/filesystem.ts
- /home/srijan/gpt-legion/src/main.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/home/srijan/gpt-legion/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/srijan/gpt-legion/src/module/definitions/filesystem.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Module.m._compile (/home/srijan/gpt-legion/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Object.require.extensions.<computed> [as .ts] (/home/srijan/gpt-legion/node_modules/ts-node/src/index.ts:1621:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/srijan/gpt-legion/src/module/definitions/filesystem.ts',
    '/home/srijan/gpt-legion/src/main.ts'
  ]
}

Restrict Agent file editing/viewing to only the ".store" folder

My ai agents have a habit of breaking out of the prompt objective to explore their own files and begin tinkering. While its rather entertaining its also rather counterproductive to accomplishing the goal I provide. Is there any code/settings I can change to fix this? I get lost in the sauce when i try to look under the hood to find what's happening in the code, and I am honestly way over my head. I assume there is a easy way to fix this, however I am quite a noob when it comes to coding, using github, and running these programs on my computer.

Perhaps if there is an easy way for users to fix this problem it could be documented in the read.me. Thank you for sharing this amazing project, and allowing me to come here and request help/changes! Keep up the good work!

Add “learned” as a type of persistent memory

Add the concept where an agent can determine if something they have learned in their memory should be moved from the .store to a persistent store called .learning that can be used to help in future operations.

for example if an agent has to discover how to go to GitHub and download and clone a repo - this process could be turned in a “learning”‘that can be referenced the next time it is encountered to streamline the process.

Endless stream of error logs with 401

This is a very nice project. I liked the idea and tried to test it out but there was an endless stream of res objects with 401 error code when a did a "\help" on the console $.
Probably there are many API calls getting rejected by openAI. For a while it was scary if the API gets called endlessly on the back it could get expensive, so I left it there.

It would be nice, if you could explain in more detail some use cases for this project.

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.