MCPcopy Index your code
hub / github.com/cedriking/spark

github.com/cedriking/spark @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
141 symbols 260 edges 35 files 1 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

AI Spark: an LLM-powered autonomous agent platform

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

Setup

You will need at least Node 10.

Download or clone this repository, then install dependencies: yarn or npm install.

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

# 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
MODEL=... # any Llama.cpp LLM model
SERVER=... # optionally, a server to connect to (default http://localhost:8080)

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:

yarn dev [# of agents]

or:

npm run dev [# of agents]

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 agents sometimes devolve into endless error loops and can't figure out what the problem is. It's highly advised to never leave an agent unattended.

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.

Code based on ai-legion.

Extension points exported contracts — how you extend this code

MessageBus (Interface)
(no doc) [4 implementers]
src/message-bus.ts
Store (Interface)
(no doc) [3 implementers]
src/store/index.ts
Action (Interface)
(no doc)
src/parse-action.ts
Message (Interface)
(no doc)
src/message.ts
ModuleDefinition (Interface)
(no doc)
src/module/index.ts
MessageEvent (Interface)
(no doc)
src/memory/index.ts
ChatGPTMessage (Interface)
(no doc)
src/services/ChatGPT.ts
MessageSourceBase (Interface)
(no doc)
src/message.ts

Core symbols most depended-on inside this repo

get
called by 10
src/store/index.ts
set
called by 9
src/store/index.ts
countTokens
called by 8
src/util.ts
checkPath
called by 7
src/module/definitions/filesystem.ts
defineModule
called by 6
src/module/define-module.ts
agentName
called by 5
src/util.ts
subscribe
called by 4
src/message-bus.ts
send
called by 4
src/message-bus.ts

Shape

Method 60
Function 35
Class 24
Interface 22

Languages

TypeScript100%

Modules by API surface

src/store/file-store.ts15 symbols
src/memory/memory.ts12 symbols
src/services/ChatGPT.ts10 symbols
src/task-queue.ts7 symbols
src/store/json-store.ts7 symbols
src/message.ts7 symbols
src/store/in-memory-store.ts6 symbols
src/redis-message-bus.ts6 symbols
src/in-memory-message-bus.ts6 symbols
src/util.ts5 symbols
src/store/index.ts5 symbols
src/module/module-instance.ts5 symbols

For agents

$ claude mcp add spark \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact