The OpenAI Agent Swarm pattern implementation for OllamaJS. Includes TTS synthesis and speech recognition for simplified testing and interaction.
Important
👉 There is an upgraded starter kit version which defenitely should be used for starting new projects. It includes boilerplate code reduction, the agent could be deployed in few lines of code without DI declaration
-
Several chatgpt sessions (agents) execute tool calls. Each agent can use different model, for example, mistral 7b for small talk, nemotron for business conversation
-
The agent swarm navigate messages to the active chatgpt session (agent) for each
WebSocket
channel by usingclientId
url parameter -
The active chatgpt session (agent) in the swarm could be changed by executing function tool
-
Each client sessions share the same chat message history for all agents. Each client chat history keep the last 25 messages with rotation. Only
assistant
anduser
messages are shared between chatgpt sessions (agents), thesystem
andtool
messages are agent-scoped so each agent knows only those tools related to It. As a result, each chatgpt session (agent) has it's unique system prompt -
[OPTIONAL] The tools with common business logic are grouped into functions using the Registry Pattern . This enables the system to support plugins and extensions, making the developer code extendable and maintainable - an essential quality for prompt engineering. For example, the original OpenAI sample uses a single
main.py
file. Without tools registries, when scaled, will result in thousands of lines of code, making it harder to manage. This also simplify TDD approach
The result
The model system prompt can be dynamically changed based on the user behaviour. The model interact with the external api based on the user requests
cp .env.example .env
ollama pull nemotron-mini:4b
ollama pull granite-embedding:278m
# cd docker/mongodb && docker-compose up
# cd docker/redis && docker-compose up
npm install
npm start
The entry point of the backend application is ConnectionPublicService.ts. The agent swarm with system prompts is placed in the logic folder. The ai functions are places in the tools folder
-
MongoDb Community
$vectorSearch
implementationBy using gpt4all embedding generation and tfjs for cosine similarity
-
REPL for product creation
For automatic embedding indexing, you should use
npm run start:repl
. The product creation command isioc.migrationPublicService.createProduct("title", "description")
. The embeddings will be generated automatically -
Vendor-proved LLM models
This tool using the commercial-ready products: NVidia nemotron-mini for chat and IBM granite-embedding for database vector indexing. Both of them are the most production-ready cause the reputation of big tech companies
-
Microservice ready
The client chat history implementation is designed to store messages in in-memory storage (e.g., Redis, Tarantool). The tool execution registry is prepared for horizontal scaling using gRPC remote hosts .
-
Integrated environment
Includes a lot of dev tools like TTS synthesis and speech recognition (
npm start
), REPL javascript interpretation (npm run start:repl
), REST API, WS API, console chat interface (npm run start:console
), test-driven development (npm run test
)