Skip to main content

A package to interact with generative AI and build specialized generative AI workflows. This project is dual-licensed under AGPL-3.0 and a separate commercial license.

Project description

OpenBrain

Main Build Status

🚧 Under active development. Not ready for use. 🚧

OpenBrain is a chat platform backed by Large Language Model (LLM) agents. It provides APIs and tools to configure, store, and retrieve chat agents, making your chat sessions more versatile and context-aware.

OpenBrain agents are stateful, so they can remember things about you and your conversation. They can also use tools, so you can use the same agent to chat and to perform actions.

Interactions with the agent can be injected into any application easily by constructing a query, choosing an agent configuration, and pre-processing your data through that agent before sending it of for further processing.

Features

  • Interactive Agent Tuner: A GUI to modify and test agent configurations.
  • Command-Line Interface: Use ob for quick completions and ob-chat for an interactive session.
  • Flexible Configuration: Customizable agents through DynamoDB backed ORM.
  • Event-Driven Architecture: Extensible through cloud-based event handling.

Quick Start

Installation

pip install openbrain

Setup .env file

cp .env.example .env  # Edit this file with your own values

Deploy Supporting Infrastructure

python ci_cd.py -I

Using OpenBrain

OpenBrain Gradio Tuner

To facilitate tuning agent parameters and experimenting with prompts, OpenBrain provides a GUI interface using Gradio. To launch the GUI.

img.png

$ ob-tuner
Running on local URL:  http://0.0.0.0:7861

To create a public link, set `share=True` in `launch()`.
Tip: You can show or hide the button for flagging with the `allow_flagging=` kwarg; for example: gr.Interface(..., allow_flagging=False)

Command Line Completions

$ ob "What is the air speed velocity of an unladen swallow?" -v

> Entering new AgentExecutor chain...
Ah, the famous question about the air speed velocity of an unladen swallow. Are you referring to an African or European swallow?

> Finished chain.
Ah, the famous question about the air speed velocity of an unladen swallow. Are you referring to an African or European swallow?

Command Line Interactive Session

$ ob-chat
---------- Begin Chat Session ----------
> OpenBrain: What… is your name?
User: It is Arthur  King of the Britons.
> OpenBrain: What… is your quest?
User: To seek the Holy Grail.
> OpenBrain: What… is the air-speed velocity of an unladen swallow?
User: What do you mean? An African or a European swallow?
> OpenBrain: I don’t know that. Aaaaaaaaagh!

Architecture Overview

Data Model

classDiagram
    class ChatMessage {
        User provided*
        + str: sessionId
        + str: clientId
        + str: message
        + AgentConfig: agentConfigOverrides
        + str: agentConfig
        + bool: reset
    }

    class AgentConfig {
        + str: profileName
        + str: clientId
        + str: iceBreaker
        + Decimal: temperature
        + ...
        + save()
        + refresh()
        + load()
        + delete()
        + get_all()
    }

    class ChatSession {
        + str: sessionId
        + str: clientId
        + byte: agentMemory
        + AgentConfig: agentConfig
        + Lead: lead
        + save()
        + load()
    }

    class Lead {
        + str: sessionId
        + str: clientId
        + str: fullName
        + str: firstName
        + str: middleName
        + str: lastName
        + List[str]: medications
        + str: email
        + ...
        + save()
        + refresh()
        + delete()
        + load()
        + get_all()
    }

    ChatSession "1" *-- "1" Lead: contains
    ChatSession "1" *-- "1" AgentConfig: contains
%%    ChatMessage "1" *-- "1" AgentConfig: contains
%%    ChatSession "1" *-- "*" ChatMessage: contains
    ChatSession "1" *-- "1" langchain_ChatMemory: from langchain, serialized

Data Flow diagram

OpenBrain uses an event driven architecture. The agent sends events to event bus and then the developer can simply write rules and targets for the incoming events once the targets are ready. The following diagram shows the data flow in two parts.

  1. The user interaction with the agent and the agent interaction with an event bus.
  2. The event bus and the targets that are triggered by the events.
sequenceDiagram
    title Agent Data Flow
    participant User
    create participant GPT Agent
    participant AgentConfigTable
    participant OpenAI
    participant Tool
    participant EventBus

    User ->> GPT Agent: (AgentConfig, AgentMemory), ChatMessage
        GPT Agent -->> AgentConfigTable: profileName
        AgentConfigTable -->> GPT Agent: AgentConfig
        GPT Agent -->> OpenAI: ChatMessage
        OpenAI -->> GPT Agent: ChatMessage
%%        GPT Agent ->> GPT Agent: Create/Update Object
        GPT Agent -->> Tool: Tool(Object, clientId)
        Tool -->> EventBus: (Object, clientId, session_id, object_id)
        Tool -->> GPT Agent: ChatMessage
    destroy GPT Agent
    GPT Agent ->> User: ChatMessage, (AgentConfig, AgentMemory), Object

  box blue Databases
      participant AgentConfigTable
  end
  box purple Tool
      participant Tool
  end

  box gray EventBus
      participant EventBus
  end

  box red Provider
      participant OpenAI
  end
sequenceDiagram
    title Agent Data Flow
    participant SQS
    participant EventBus
    participant Lambda
    participant ObjectTable
    participant AgentConfigTable
    participant ChatHistoryTable
    participant ExternalSite

    EventBus ->> Lambda: (Object, clientId, sessionId, objectId)
    Lambda -->> ObjectTable: (clientId, objectId)
    ObjectTable -->> Lambda: Object

    Lambda -->> AgentConfigTable: (profileName, clientId)
    ChatHistoryTable -->> Lambda: AgentConfig

    Lambda --> ChatHistoryTable: (clientId, sessionId)
    ChatHistoryTable -->> Lambda: (AgentMemory, AgentConfig)

    Lambda ->> ExternalSite: ...
    ExternalSite --x Lambda: ERROR
    Lambda ->> SQS: <DETAILS NEEDED TO RETRY>
    ExternalSite ->> Lambda: ...

    Lambda -> EventBus: <POTENTIAL NEW EVENT>

    box maroon DeadLetterQueue
        participant SQS
    end

    box blue Databases
        participant ObjectTable
        participant AgentConfigTable
        participant ChatHistoryTable
    end

    box gray EventBus
        participant EventBus
    end

    box brown EventTargets
        participant Lambda
    end

    box green Internet
        participant ExternalSite
    end

Contributing

See CONTRIBUTING.md for guidelines.

License

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openbrain-0.10.8.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

openbrain-0.10.8-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file openbrain-0.10.8.tar.gz.

File metadata

  • Download URL: openbrain-0.10.8.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.13 Linux/6.2.0-1011-azure

File hashes

Hashes for openbrain-0.10.8.tar.gz
Algorithm Hash digest
SHA256 6ce7b4ba04192616a25454eb14478c828aa2281e740ba318725c18a98b4b3f99
MD5 7fe79bd65527d37779b6929193372b43
BLAKE2b-256 fde6fc7812f3a31e80dd95561b60b733b735269b60978a76b5ac4df244fd9bd5

See more details on using hashes here.

File details

Details for the file openbrain-0.10.8-py3-none-any.whl.

File metadata

  • Download URL: openbrain-0.10.8-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.13 Linux/6.2.0-1011-azure

File hashes

Hashes for openbrain-0.10.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bd0a268dbb8e912f55a2fbf4dd34e0b41016c5e8b9824d8fc1e5ad0227b18095
MD5 71bb5d30d40fa5c4c5267fac92504712
BLAKE2b-256 6ec35407b4087ad75bea64e2226721aac0e93901ade861ee2e0b57a5bdb25987

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page