npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wladiston/chatflow

v0.0.1-beta.2

Published

A chat flow organizer for AI agents

Downloads

4

Readme

ChatFlow

This project is a fork from the original autogen but done in TypeScript.

I took a sightly different approach to the original project. Agents are now provider agnostic and can be used with any provider that implements the AIProvider interface. Also, it is stateless and can be used in a serverless environment.

By default, it uses OpenAI and GPT-3.5-TURBO as the provider but you can change it by passing provider and model to the ChatFlow constructor or by setting them on the node config.

Roadmap

  • [x] Automated reply with loop prevention. Chats are kept alive until the assistant interrupts the conversation.
  • [x] Group chats. Agents chat with multiple other agents at the same time as if they were in a Whatsapp group. The next agent to reply is chosen based on the conversation and predicted most likely to reply.
  • [ ] Function execution. Agents can execute functions and return the result to the conversation.
  • [ ] Cache. Store conversation history in a cache to improve performance and reduce the number of API calls.
  • [ ] Error handling. Handle API errors gracefully.
  • [ ] Code execution. Agents can execute code and return the result to the conversation.

Providers

  • [ ] Anthropic
  • [ ] Cohere
  • [ ] Fireworks.ai
  • [ ] Hugging Face
  • [x] OpenAI
  • [ ] Replicate

Usage

You can install the package:

npm install @wladiston/chatflow

add you OPEN_AI_API_KEY to your environment variables and then use it like this:

import {ChatFlow} from '@wladiston/chatflow'

const flow = new ChatFlow({
  nodes: {
    '🧑': '🤖',
    '🤖': ['🐭', '🦁', '🐶'],
  },
  config: {
    '🧑': {
      type: 'assistant',
      interrupt: 'NEVER',
      role: 'You are a human assistant. Reply "TERMINATE" in when there is a correct answer.',
    },
    '🤖': {type: 'manager'},
    '🐭': {type: 'agent', role: 'You do the math.'},
    '🦁': {type: 'agent', role: 'You check to see if its correct'},
    '🐶': {
      type: 'agent',
      role: 'You reply "TERMINATE" if theres`s a confirmation',
    },
  },
})

flow.on('message', ({from, to, content}) => console.log(`${from}: ${content}`))
// 🧑: How much is 2 + 2?
// 🐭: The sum of 2 + 2 is 4.
// 🦁: That is correct.
// 🐶: TERMINATE

await flow.start({
  from: '🧑',
  to: '🤖',
  content: 'How much is 2 + 2?',
})

console.log('saving chats... ', flow.chats)
// saving chats...  [
//   {
//     from: "🧑",
//     to: "🤖",
//     content: "How much is 2 + 2?",
//     state: "success"
//   }, {
//     from: "🐭",
//     to: "🤖",
//     state: "success",
//     content: "The sum of 2 + 2 is 4."
//   }, {
//     from: "🦁",
//     to: "🤖",
//     state: "success",
//     content: "That is correct."
//   }, {
//     from: "🐶",
//     to: "🤖",
//     state: "success",
//     content: "TERMINATE"
//   }
// ]

Nodes are the agents that will be used in the conversation and how they connect to each other. The config object is used to configure each node.

  • type: agent, assistant or manager. Agents and managers never interrupt conversations by default while assistant always does. Managers don't reply to messages. They are used to group other agents.
  • interrupt: NEVER, ALWAYS. When NEVER, the agent will never interrupt the conversation. When ALWAYS, the agent will always interrupt the conversation. (Note: any of them can interrupt the conversation if they reply "INTERRUPT")
  • role: The role of the agent. It is used to describe the role the agent will perform in the chat.
  • maxRounds: The maximum number of chats an agent or a group will reply to the conversation. It is used to prevent loops.

Listening to events

You can listen to events using the on method:

flow.on('message', ({from, to, content}) => console.log(`${from}: ${content}`))

The following events are available:

  • message: When a message is added to the chat.
  • terminate: When the conversation is terminated. Generally means there is nothing else to do and a new conversation should be started.
  • interrupt: When the conversation is interrupted by an agent. Generally means the agent has a question or needs help. The conversation can be resumed by calling .continue(feedback).

Contributing

To install dependencies:

bun install

To run:

bun run examples/1-basic.ts

Check out the examples folder for more examples.

This project was created using bun init in bun v1.0.3. Bun is a fast all-in-one JavaScript runtime.