Deployments

Runnning locally

If you don't want to use the Superagent Cloud you can optionally run Superagent localy. In order to make Superagent more modular we have decoupled the Superagent API from the Superagent UI. You can run the API directly by just leveraging the SDKs. Follow the guides below to get started.

Setup Superagent API

Getting started

  1. Clone the Superagent repository and open the superagent folder.

    1
    2
    git clone git@github.com:homanp/superagent.git
    cd superagent
    
  2. Navigate to libs/superagent and copy the .env.example to a new file named .env.

    1
    2
    cd libs/superagent
    cp .env.example .env
    

Set .env variables

In order to get Superagent running we need to set some mandatory environment variables. Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# MANDATORY VARIABLES

OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>

# We use Supabase but you can use any provider.
# You can setup Supabase locally or via Supabase Cloud
DATABASE_URL=postgres://<user>:<password>@<db_host_name>:<db_port>/postgres?pgbouncer=true 
DATABASE_MIGRATION_URL=postgresql://<user>:<password>@<db_host_name>:<db_port>/postgres

# Use a password-like string
JWT_SECRET=superagent

# Depending on which vector db you want to use you need to setup the corresponding auth variables.
# Learn more about which vector databases are avaialable here:  
VECTORSTORE=qdrant
QDRANT_API_KEY=<YOUR_QDRANT_API_KEY>
QDRANT_HOST=<YOUR_QDRANT_HOST>
QDRANT_INDEX=superagent

# You can use the Superagent hosted memory or setup memory yourself. 
# We recommend using Motorhead by Metal: https://github.com/getmetal/motorhead
MEMORY_API_URL=https://memory.superagent.sh

# OPTIONAL VARIABLES

# AgentOps 
# Automatically track costs, session replays, and agent benchmarks. Sign up for a key at [agentops.ai](https://agentops.ai). # Using the default org key in .env.example will include added premium features.
AGENTOPS_API_KEY=<YOUR_AGENTOPS_API_KEY>
AGENTOPS_ORG_KEY=<YOUR_ORG_KEY>

# Langfuse observability
LANGFUSE_PUBLIC_KEY=<LANGFUSE_PUBLIC_KEY>
LANGFUSE_SECRET_KEY=<LANGFUSE_SECRET_KEY>
LANGFUSE_HOST=<LANGFUSE_HOST>

# LangSmith observability
LANGCHAIN_TRACING_V2=False
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_PROJECT_ID=<LANGSMITH_PROJECT_ID>
LANGCHAIN_API_KEY=<LANGCHAIN_API_KEY>

# E2B Code Interpreter
E2B_API_KEY=<E2B_API_KEY>

# Run Replicate models as tools
REPLICATE_API_TOKEN=<REPLICATE_API_TOKEN>

Create a virtual env

In the console, create a virtual environment to install and run the python api.

1
2
# cd libs/superagent
virtualenv venv

Then activate the new virtual environment to work in it.

1
2
# Linux/Mac
source venv/bin/activate
1
2
# Windows (bash)
source venv/Scripts/activate

Install dependencies

Use poetry to install the project dependencies in the virtual environment

1
2
# cd libs/superagent
poetry install 

Start Supabase

1
supabase start

Get Supabase Info

Get the hostname and port of your Supabase instance and replace them in the DATABASE_URL and DATABASE_MIGRATION_URL variable in your .env file.

1
supabase status

Run database migrations

1
2
prisma generate
prisma migrate dev

Start the server

1
2
3
4
uvicorn app.main:app --reload

# Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
# API available at http://127.0.0.1:8000/api/v1

Use local API with the Superagent SDK

1
2
3
4
5
6
7
import os
from superagent.client import Superagent

client = Superagent(
    token=os.environ["SUPERAGENT_API_KEY"], # replace with your Superagent API
    base_url="http://127.0.0.1:8000" # or your local environment
)

And that's it! You now have an instance of the Superagent API running on your local machine. Make sure to checkout the REST API reference for more details on each API endpoint or visit http://127.0.0.1:8000 to view the Swagger docs.

Setup Superagent UI

Setup Supabase

The Superagent UI is setup using Supabase. It leverages the Supabase's Auth and Storage modules. Configure your Supabase setup as per the instructions below:

  1. Clone the Superagent repository
1
git clone git@github.com:homanp/superagent.git
  1. Navigate to /libs/ui

  2. Install Supabase CLI and create project: https://supabase.com/docs/guides/cli/getting-started

  3. Start the local Supabase project

1
supabase start
  1. Run the database migrations
1
2
3
4
5
# Local supabase project
supabase migration up

# Supabase Cloud project 
supabase db push
  1. Create a Supabase storage with the following storage.objects permissions:
Screenshot 2023-09-14 at 23 27 35

Setup authentication

Superagent supports password-less authentication and Github OAuth. You may add which ever Authentication provider supported by Supabase.

  1. Create a new Github OAuth app in your Github account

  2. Copy the CLIENT_ID and CLIENT_SECRET and paste them into the /libs/ui/.env variables in your local Superagent project.

  3. Set the following callback URL

1
<YOUR_SUPABASE_URL>/auth/v1/callback
  1. Navigate to your Supabase project you have created for Superagent UI and paste the CLIENT_ID and CLIENT_SECRET
Screenshot 2023-09-15 at 09 08 52

NOTE: You can enable any provider using the steps above.

Set .env variables

  1. Change the name of .env.example to .env in /libs/ui.

  2. Set the required environment variables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# MANDATORY

# Supabase variables found inside of the Supabase dashboard (local or remote)
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
NEXT_PUBLIC_SUPABASE_STORAGE_NAME="superagent"

# Tracing 
NEXT_PUBLIC_SEGMENT_WRITE_KEY=

# Github OAuth
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Superagent API URL
NEXT_PUBLIC_SUPERAGENT_API_URL="http://127.0.0.1:8000/api/v1"

# OPTIONAL

# Optional for connecting to Google Drive, Dropbox, Box and OneDrive.
NEXT_PUBLIC_APIDECK_API_KEY=
NEXT_PUBLIC_APIDECK_API_ID=

# Optional for adding billing
NEXT_PUBLIC_STRIPE_SECRET_KEY=
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=

# Optional for recording human feedback with Langfuse
NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY=
NEXT_PUBLIC_LANGFUSE_BASE_URL=

Run app

  1. From inside /libs/ui run:
1
npm i 
  1. Start the app
1
npm run dev 

You should now be able to visit http://localhost:3000 and see the Superagent login page