Package: openbrain
OpenBrain🚧Under active development, expect instability until v1 (targeting Jan).🚧LinksNOTE: The following links demonstrate resources that are works in progress, these are the main issues that will get addressed eventually, and that make this project difficult to use locally.OpenBrain Portal:Needs stylingSign up for OpenBra.in as a service. Get an API key and start using the API. Swagger UI available once subscribed to the API.This method does not require you to use the library or to deploy any infrastructure. Just grab an API key, and you can simply start withaxiosor therequestslibrary (or whatever your language provides for making HTTP requests).Agent Tuner:Needs SSO and DNSA Gradio interface to create, test, save, and load sets of agent configurations.Agent properties change over time, so the following list is illustrative only to give an idea of what an agent configuration is:profile_name: A unique name for the agent configuration. The reference to the configuration.system_message: This is the LLM system message. It can heavily influence the agent's apparent expertise, style, tone, goal, personality, etc.iceBreaker: A predictable prompt that the agent will use to start the conversation.temperature: A number between 0 and 1 that controls how "creative" the agent is. 0 is very literal, 1 is very creative....: ...Agent configurations allows your API calls to start sessions with a specific agent configuration (i.e. lead-bot, professor, therapist, etc.).Demo Agent Page:Needs styling to hide cold start and to make it look presentableAn example page that's using the API to present a tool wielding agent to visitors.This page uses an identity registered withOpenBrain Portal.This page is using theOpenBrain APIto interact with LLMs.This page is configured to use the profile called "default", but it can, of course, use any stored agent configuration.OpenBrain is a tool-wielding, cloud native, LLM agent platform. It provides APIs and tools to configure, store, and retrieve LangChain agents, making your chat sessions and workflows stateful and persistent. You will find in-memory and DynamoDB ORM options as well as a SAM template for deploying the necessary resources for stateless agents to your AWS.OpenBrain agents are stateful by nature, 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. This project provides a mechanisms to integrate with an API to store the state of the agent as a session, so that the agent can be used asynchronously from any source in a serverless environment.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.Openbrain as a ServiceTo test Openbrain as a service, do the following:Register athttps://portal.openbra.in.Log in to the portal and subscribe to the Openbrain service.Navigate to your dashboard in the portal and use your API keys to interact with the API.A swagger UI and SDKs are available for subscribers.(Optional) deploy the infrastructure to your AWS account using the SAM template provided in this repository (resources.yaml).NOTE: There is currently no fee for using the service, but it's using my personal AWS and OpenAI accounts, so I'll pull the plug immediately if it becomes expensive.FeaturesInfrastructure as Code: Deploy to AWS using CodePipeline and SAM.Interactive Agent Tuner: A GUI to modify and test agent configurations.Command-Line Interface: Useobfor quick completions andob-chatfor an interactive session.Flexible Configuration: Customizable agents through DynamoDB backed ORM.Event-Driven Architecture: Extensible through cloud-based event handling.Quick Start# TLDR: demo functionalitypipinstallopenbrain[gradio]ob-tunerTo print an example .env file, use ob-env.ob-envInstallationGradio is included as an extra dependency. This keeps the base installation small enough to fit in a lambda layer. If you intend to experiment with theob-tunerinterface locally, add the[gradio]extra to your pip install command.pipinstallopenbrain[gradio]Setup .env filecp.env.example.env# Edit this file with your own valuesDeploy Supporting InfrastructureTheAgentConfigs you create inob-tunercan be saved to your DynamoDB tables in AWS, allowing you to reference them in any AWS workflow using the boto3 library.If you intend to use this project in your API, an AWS SAM template is provided to get you started. You can deploy the template using the following command. You will need to have the AWS CLI installed and configured with your credentials.:warning:This will deploy resources to your AWS account.:warning: You will be charged for these resources. SeeAWS Pricingfor more information.pythonci_cd.py-IUsing OpenBrainOpenBrain Gradio TunerTo facilitate tuning agent parameters and experimenting with prompts, OpenBrain provides a GUI interface using Gradio. You can use the in-memory object model to store your agent configurations locally. This is controllable by settingGRADIO_LOCAL=True,ORM_LOCAL=True,UTIL_LOCAL=Truein your.envfile.$ob-tuner
RunningonlocalURL:http://0.0.0.0:7861

Tocreateapubliclink,set`share=True`in`launch()`.
Tip:Youcanshoworhidethebuttonforflaggingwiththe`allow_flagging=`kwarg;forexample:gr.Interface(...,allow_flagging=False)Command Line Completions(doesn't work quite like this yet, but that's the idea, currently noisy)$ob--profile_name=linux'change the file permissions of all files that start with a "w" in this directory (recursively) to 042'find.-typef-name'w*'-execchmod042{}+Command Line Interactive Session(doesn't work quite like this yet, but that's the idea)$ob-chat
----------BeginChatSession----------
>OpenBrain:What…isyourname?
User:ItisArthur–KingoftheBritons.
>OpenBrain:What…isyourquest?
User:ToseektheHolyGrail.
>OpenBrain:What…istheair-speedvelocityofanunladenswallow?
User:Whatdoyoumean?AnAfricanoraEuropeanswallow?
>OpenBrain:Idon’tknowthat.Aaaaaaaaagh!Architecture OverviewData ModelclassDiagram
    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, serializedData Flow diagramOpenBrain 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.The user interaction with the agent and the agent interaction with an event bus.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 -->> 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
  endsequenceDiagram
    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
    endContributingSeeCONTRIBUTING.mdfor guidelines.LicenseOpen Source: AGPLv3Commercial: SeeCOMMERCIAL_LICENSEand contact us for inquiries.