Skip to content

tripolskypetr/node-ollama-agent-swarm

Repository files navigation

node-ollama-agent-swarm

The OpenAI Agent Swarm pattern implementation for OllamaJS. Includes TTS synthesis and speech recognition for simplified testing and interaction.

screenshot

WARNING Obsolete

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

Main concept

schema

  1. Several chatgpt sessions (agents) execute tool calls. Each agent can use different model, for example, mistral 7b for small talk, nemotron for business conversation

  2. The agent swarm navigate messages to the active chatgpt session (agent) for each WebSocket channel by using clientId url parameter

  3. The active chatgpt session (agent) in the swarm could be changed by executing function tool

  4. 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 and user messages are shared between chatgpt sessions (agents), the system and tool 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

  5. [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

Getting started

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

What's Inside

  • MongoDb Community $vectorSearch implementation

    By 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 is ioc.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)

Releases

No releases published

Packages

No packages published