### Initialize Superagent Asynchronous Python Client Source: https://docs.superagent.sh/overview/getting-started/install-sd-ks Example of initializing the asynchronous Superagent client in Python. This setup also requires the SUPERAGENT_API_KEY environment variable and the base URL for the Superagent API. ```Python import os from superagent.client import AsyncSuperagent client = AsyncSuperagent( token=os.environ["SUPERAGENT_API_KEY"], # replace with your Superagent API key base_url="https://api.beta.superagent.sh" # or you local environment ) ``` -------------------------------- ### Copying Superagent Environment Configuration File Source: https://docs.superagent.sh/overview/installation/docker-compose This command sequence navigates to the Superagent Docker configuration directory and copies the example environment file (`.env.example`) to a new `.env` file. This new file will contain the necessary environment variables for Docker Compose to set up Superagent's core services. ```bash cd libs/.docker cp .env.example .env ``` -------------------------------- ### Copy Supabase Environment Example File Source: https://docs.superagent.sh/overview/dependencies/supabase Copies the `.env.example` file to `.env`, which is necessary for configuring Supabase with local environment variables before starting the services. This creates a writable configuration file based on the provided template. ```bash cp .env.example .env ``` -------------------------------- ### Initialize Superagent Synchronous Python Client Source: https://docs.superagent.sh/overview/getting-started/install-sd-ks Example of initializing the synchronous Superagent client in Python. This requires setting the SUPERAGENT_API_KEY environment variable and specifying the base URL for the Superagent API. ```Python import os from superagent.client import Superagent client = Superagent( token=os.environ["SUPERAGENT_API_KEY"], # replace with your Superagent API base_url="https://api.beta.superagent.sh" # or your local environment ) ``` -------------------------------- ### Complete Superagent Agent Setup and Invocation Workflow Source: https://docs.superagent.sh/overview/getting-started/chat-with-tools This comprehensive example combines all previous steps into a single script: initializing the Superagent client, creating an LLM, creating an agent, creating and attaching a tool, and finally invoking the agent with an input. It provides a complete end-to-end workflow for setting up and using a Superagent.sh agent. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create( name="Chat Assistant", description="An Assistant that has access to the Browser tool", avatar="https://mylogo.com/logo.png", # Replace with a real image is_active=True, initial_message="Hi there! How can I help you?", llm_model="GPT_3_5_TURBO_16K_0613", prompt="Use the Browser to answer the user's question." ) tool = client.tool.create( name="Browser", description="A portal to the internet, useful for answering questions about websites or urls.", type="BROWSER", # metadata={"key": "value"} Optional metadata for the tool. return_direct=False # return_direct is required while creating a tool. ) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id) prediction = client.agent.invoke( agent_id=agent.data.id, input="Summarize superagent.sh", enable_streaming=False, session_id="my_session_id", ) print(prediction.data.get("output")) ``` -------------------------------- ### Run Superagent Core Docker Services Source: https://docs.superagent.sh/overview/installation/docker-compose This script initializes and starts all core Superagent services using Docker Compose. It first stops any existing services, checks for and creates a Docker network if necessary, and then brings up the specified services. Users can modify the `docker-compose` command to exclude services deployed elsewhere, such as a cloud-hosted database. ```Shell # Remove any running services ./stop.sh # Check if the network exists if ! docker network ls | grep -q superagent_network; then # Create the network if it does not exist docker network create superagent_network fi # Run the core services docker-compose -f docker-compose.yml \ ### Delete any services you have deployed elsewhere. -f superagent/db/docker-compose.pgdb.yml \ -f superagent/db/docker-compose.pgadmin.yml \ -f superagent/motorhead/docker-compose.motorhead.yml \ -f ui/docker-compose.ui.yml \ up \ --build \ -d docker logs superagent-ui ``` -------------------------------- ### Navigate to Weaviate Docker Directory Source: https://docs.superagent.sh/overview/vector-stores/weaviate Changes the current working directory to the Weaviate Docker example folder, which is necessary before running setup scripts for local Weaviate deployment. ```bash cd libs/.docker/external/vector-store/weaviate/ ``` -------------------------------- ### Running Superagent Core Services with Docker Compose Source: https://docs.superagent.sh/overview/installation/docker-compose These commands navigate to the `libs/.docker` directory and execute the `run.sh` script. This script orchestrates the deployment of Superagent's core services, including the API, UI, Motorhead, Redis, and PostgreSQL database, using Docker Compose. It provides a convenient way to start or restart all essential components. ```bash cd libs/.docker ./run.sh ``` -------------------------------- ### Complete Superagent AI Agent Setup and Interaction Source: https://docs.superagent.sh/overview/getting-started/chat-with-datasources This comprehensive snippet combines all previous steps into a single script. It initializes the Superagent client, configures an LLM, creates an AI agent, adds a datasource, connects both the LLM and datasource to the agent, and finally invokes the agent with a query, printing the output. This serves as a full working example for setting up and using a Superagent AI assistant. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create(request={ "name": "Earnings Assistant", "description": "An Assistant that's an expert at analyzing earnings reports", "avatar": "https://tesla.com/logo.png", # Replace with a real image "isActive": True, "llmModel": "GPT_3_5_TURBO_16K_0613", "initialMessage": "Hi there, how can I help you?", "prompt": "You are an expert at analyzing earnings reports.\nUse the earnings reports provided to answer any questions." }) datasource = client.datasource.create(request={ "name": "Tesla Q3 2023", "description": "Useful for answering questions about Tesla's Q3 2023 earnings report", "type": "PDF", "url": "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q3-2023-Update-3.pdf" }) # Connect the datasource and llm to the Agent client.agent.add_datasource( agent_id=agent.data.id, datasource_id=datasource.data.id ) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) # Invoke the Assistant prediction = client.agent.invoke( agent_id=agent.data.id, input="What was Tesla's revenue?", enable_streaming=False, session_id="my_session_id" ) print(prediction.data.get("output")) # Tesla's revenue was 24 Billing USD according to the earnings report. ``` -------------------------------- ### Copy Langfuse Environment Example File Source: https://docs.superagent.sh/overview/logging/langfuse Duplicates the `.env.example` file to create a new `.env` file. This new file will be used to store local environment variables for the Langfuse Docker Compose setup. ```bash cp .env.example .env ``` -------------------------------- ### Start Weaviate Docker Services Source: https://docs.superagent.sh/overview/vector-stores/weaviate Executes the provided run script to start the Weaviate services using Docker Compose. This command initiates the local Weaviate instance. ```bash ./run.sh ``` -------------------------------- ### cURL Example for Listing Workflow Steps Source: https://docs.superagent.sh/api-reference/api-reference/workflow/list-steps An example cURL command demonstrating how to make an authenticated GET request to the workflow steps API endpoint, replacing `` with your actual authorization token. ```cURL curl https://api.beta.superagent.sh/api/v1/workflows/workflow_id/steps \ -H "Authorization: Bearer " ``` -------------------------------- ### Start Langfuse Services with Docker Compose Source: https://docs.superagent.sh/overview/logging/langfuse Executes the `run.sh` script, which initiates the Langfuse services and their dependencies using Docker Compose. This command brings up the entire Langfuse stack. ```bash ./run.sh ``` -------------------------------- ### Start Supabase Local Instance Source: https://docs.superagent.sh/overview/installation/running-locally Command to start the local Supabase services, including the database and other necessary components. ```Bash supabase start ``` -------------------------------- ### Copy Weaviate Environment File Source: https://docs.superagent.sh/overview/vector-stores/weaviate Copies the example environment file (.env.example) to a new .env file. This .env file will be used by Docker Compose to configure the Weaviate service. ```bash cp .env.example .env ``` -------------------------------- ### Install Superagent Python SDK Source: https://docs.superagent.sh/overview/getting-started/install-sd-ks Instructions for installing the Superagent Python SDK using either the poetry package manager or pip. ```Python poetry add superagent-py # or pip install superagent-py ``` -------------------------------- ### Navigate to Supabase Docker Directory Source: https://docs.superagent.sh/overview/dependencies/supabase Changes the current directory to the Supabase Docker UI example folder, which is a prerequisite for running Supabase with Docker Compose. This ensures that subsequent commands are executed in the correct context. ```bash cd libs/.docker/ui/supabase/ ``` -------------------------------- ### Install Node.js Dependencies for Stock Assistant Source: https://docs.superagent.sh/templates/assistants/stock-assistant This command installs all necessary Node.js packages listed in the `package.json` file for the Stock Assistant application. It's a standard step after cloning a Node.js project to ensure all required libraries are available. ```Shell npm i ``` -------------------------------- ### Start Supabase Services with run.sh Script Source: https://docs.superagent.sh/overview/dependencies/supabase Executes the `run.sh` script to start Supabase services using Docker Compose. This script ensures the necessary Docker network exists, stops any previously running containers, and then brings up the Supabase stack in detached mode. ```bash ./run.sh ``` ```bash # Check if the network exists if ! docker network ls | grep -q superagent_network; then # Create the network if it does not exist docker network create superagent_network fi ./stop.sh && docker compose up -d docker logs supabase-db ``` -------------------------------- ### Superagent Python SDK: Agent and LLM Management Methods Source: https://docs.superagent.sh/overview/getting-started/basic-example This section documents the core Superagent Python SDK methods used for managing Language Models (LLMs) and AI Agents, as demonstrated in the provided example. It includes details on creating LLM configurations, creating agents, linking LLMs to agents, and invoking agents for predictions. ```APIDOC Superagent Client Initialization: Superagent(base_url: str, token: str) - Initializes the Superagent client. - Parameters: - base_url: The base URL for the Superagent API (e.g., "https://api.beta.superagent.sh"). - token: Your Superagent API key, typically from environment variables. LLM Management: client.llm.create(request: dict) - Creates a new Language Model (LLM) configuration within Superagent. - Parameters: - request: A dictionary containing LLM details: - provider (str): The LLM provider (e.g., "OPENAI"). - apiKey (str): The API key for the specified LLM provider. - Returns: An object containing the created LLM's data, including its unique 'id'. Agent Management: client.agent.create(request: dict) - Creates a new AI Agent within Superagent. - Parameters: - request: A dictionary containing agent details: - name (str): The name of the agent (e.g., "Chat Assistant"). - description (str): A brief description of the agent. - avatar (str, optional): A valid URL to an image for the agent's avatar (JPG or PNG). - isActive (bool): Whether the agent is active. - initialMessage (str): The first message the agent sends to a user. - llmModel (str): The specific LLM model to use (e.g., "GPT_3_5_TURBO_16K_0613"). - prompt (str): The system prompt or persona for the agent. - Returns: An object containing the created agent's data, including its unique 'id'. client.agent.add_llm(agent_id: str, llm_id: str) - Links an existing LLM configuration to an agent. - Parameters: - agent_id (str): The unique ID of the agent. - llm_id (str): The unique ID of the LLM configuration. - Returns: (Implicitly, success/failure of the linking operation). Agent Invocation: client.agent.invoke(agent_id: str, input: str, enable_streaming: bool, session_id: str) - Invokes the specified agent with a given input message. - Parameters: - agent_id (str): The unique ID of the agent to invoke. - input (str): The user's input message. - enable_streaming (bool): Whether to enable streaming for the response. - session_id (str): A unique identifier for the conversation session (best practice for user tracking). - Returns: A prediction object containing the agent's response, accessible via `prediction.data.get("output")`. ``` -------------------------------- ### Configure Superagent Vector Database with Environment Variables Source: https://docs.superagent.sh/overview/getting-started/configuring-vector-database This snippet demonstrates how to set environment variables to integrate a vector database like Supabase with Superagent. This method is the easiest way to get started and is suitable for single-database configurations. ```shell export VECTORSTORE=supabase export SUPABASE_DB_URL=postgresql://user:password@host:port/dbname export SUPABASE_TABLE_NAME=your-table-name ``` -------------------------------- ### Install Project Dependencies with Poetry Source: https://docs.superagent.sh/overview/installation/running-locally Command to install all project dependencies using Poetry within the activated virtual environment. ```Bash poetry install ``` -------------------------------- ### Start Superagent API Server with Uvicorn Source: https://docs.superagent.sh/overview/installation/running-locally Command to start the Superagent API server using Uvicorn with auto-reload enabled, making the API accessible locally. ```Bash uvicorn app.main:app --reload ``` -------------------------------- ### Install Node.js Dependencies for Superagent UI Source: https://docs.superagent.sh/overview/installation/running-locally Installs all required Node.js packages and dependencies for the Superagent UI project, preparing it for development or production use. ```shell npm i ``` -------------------------------- ### Start Local Supabase Services Source: https://docs.superagent.sh/overview/installation/running-locally Initiates the local Supabase services, including the database and authentication, which are essential for the Superagent UI to function correctly. ```shell supabase start ``` -------------------------------- ### Start Superagent UI Development Server Source: https://docs.superagent.sh/overview/installation/running-locally Launches the Superagent UI in development mode, making it accessible locally for testing and further development. ```shell npm run dev ``` -------------------------------- ### Superagent Python SDK: Create and Invoke AI Agent Source: https://docs.superagent.sh/overview/getting-started/basic-example This Python code snippet demonstrates the end-to-end process of setting up an AI assistant using the Superagent SDK. It covers client initialization, creating an LLM configuration, defining an AI agent with specific parameters, linking the LLM to the agent, and finally invoking the agent with a user input. API keys are loaded from environment variables. ```python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create(request={ "name": "Chat Assistant", "description": "My first Assistant", "avatar": "https://myavatar.com/homanp.png", # A valid image URL (jpg or png) "isActive": True, "initialMessage": "Hi there! How can I help you?", "llmModel": "GPT_3_5_TURBO_16K_0613", "prompt": "You are a helpful AI Assistant", }) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) prediction = client.agent.invoke( agent_id=agent.data.id, input="Hi there!", enable_streaming=False, session_id="my_session" # Best practice is to create a unique session per user ) print(prediction.data.get("output")) # Hello there, how can I help you? ``` -------------------------------- ### Configure OpenAI Language Model with Superagent Source: https://docs.superagent.sh/overview/getting-started/basic-example This snippet demonstrates how to initialize the Superagent client and configure an OpenAI Language Model (LLM) using an API key. The configured LLM object can be reused for subsequent agents. ```python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) ``` -------------------------------- ### cURL Example to List LLMs Source: https://docs.superagent.sh/api-reference/api-reference/llm/list Provides a practical cURL command example to demonstrate how to make a GET request to the /api/v1/llms endpoint. This snippet includes the necessary Authorization header with a placeholder for the bearer token. ```cURL curl https://api.beta.superagent.sh/api/v1/llms \ -H "Authorization: Bearer " ``` -------------------------------- ### Initialize Superagent Client, Create LLM, and Agent Source: https://docs.superagent.sh/overview/getting-started/chat-with-tools This snippet demonstrates how to set up the Superagent client by providing the base URL and API token. It then proceeds to create an LLM object, specifying the provider and API key, and subsequently creates a new agent with a name, description, avatar, and initial message. Finally, it associates the created LLM with the agent. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create( name="Chat Assistant", description="An Assistant that has access to the Browser tool", avatar="https://mylogo.com/logo.png", # Replace with a real image is_active=True, initial_message="Hi there! How can I help you?", llm_model="GPT_3_5_TURBO_16K_0613", prompt="Use the Browser to answer the user's question." ) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) ``` -------------------------------- ### JSON Response Example for List Datasources Source: https://docs.superagent.sh/api-reference/api-reference/datasource/list An example of the JSON payload returned by the GET /api/v1/datasources endpoint upon a successful request (HTTP 200). It illustrates the structure of the data array, including nested objects for apiUser, datasources, and vectorDb. ```JSON { "success": true, "total_pages": 1, "data": [ { "id": "id", "name": "name", "type": "TXT", "apiUserId": "apiUserId", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "status": "IN_PROGRESS", "content": "content", "description": "description", "url": "url", "apiUser": { "id": "id", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z" }, "metadata": "metadata", "datasources": [ { "agentId": "agentId", "datasourceId": "datasourceId", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z" } ], "vectorDb": { "id": "id", "provider": "PINECONE", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" }, "vectorDbId": "vectorDbId" } ] } ``` -------------------------------- ### Attach LLM to Assistant and Invoke Source: https://docs.superagent.sh/overview/getting-started/basic-example This snippet demonstrates how to associate a previously configured Language Model with an agent and then invoke the agent with an input message. It also shows how to retrieve and print the agent's response, using a session ID for best practice. ```python client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) prediction = client.agent.invoke( agent_id=agent.data.id, input="Hi there!", enable_streaming=False, session_id="my_session" # Best practice is to create a unique session per user ) print(prediction.data.get("output")) # Hello there, how can I help you? ``` -------------------------------- ### Stop Langfuse Services Source: https://docs.superagent.sh/overview/logging/langfuse Executes the `stop.sh` script to gracefully shut down all running Langfuse services and their associated Docker containers that were started via Docker Compose. ```bash # libs/.docker/external/observabillity/langfuse ./stop.sh ``` -------------------------------- ### Create a Superagent Assistant Source: https://docs.superagent.sh/overview/getting-started/basic-example This snippet illustrates how to create a new AI assistant within the Superagent platform. It defines various properties for the assistant, such as its name, description, type, avatar, initial message, the LLM model to use, and a custom prompt. ```python agent = client.agent.create( name="Chat Assistant", description="My first Assistant", type="SUPERAGENT", avatar="https=//myavatar.com/homanp.png", is_active=True, initial_message="Hi there! How can I help you?", llm_model="GPT_3_5_TURBO_16K_0613", prompt="You are a helpful AI Assistant", ) ``` -------------------------------- ### cURL Example for Listing Datasources Source: https://docs.superagent.sh/api-reference/api-reference/datasource/list This cURL command demonstrates how to make a GET request to the /api/v1/datasources endpoint, including the necessary Authorization header for bearer token authentication. ```cURL curl https://api.beta.superagent.sh/api/v1/datasources \ -H "Authorization: Bearer " ``` -------------------------------- ### Clone Superagent Repository Source: https://docs.superagent.sh/overview/installation/running-locally This command sequence initiates the local setup by cloning the Superagent GitHub repository to your machine. After cloning, it navigates into the newly created 'superagent' directory, preparing the environment for further configuration. ```Shell git clone git@github.com:homanp/superagent.git cd superagent ``` -------------------------------- ### Run Stock Assistant Development Server Source: https://docs.superagent.sh/templates/assistants/stock-assistant This command starts the development server for the Stock Assistant application, typically using Next.js. It allows local testing and development, providing a live-reloading environment for changes. ```Shell npm run dev ``` -------------------------------- ### Stop Superagent Docker Services Source: https://docs.superagent.sh/overview/installation/docker-compose This command stops all Docker services associated with the current project. Running this command will preserve any data linked to services that have a volume mounted, while freeing up system resources. ```Shell ./stop.sh ``` -------------------------------- ### Python: Create Superagent Client and Agent Source: https://docs.superagent.sh/api-reference/api-reference/agent/create Demonstrates how to initialize the Superagent Python client with an API token and then call the `client.agent.create` method to provision a new agent. This example includes various configuration parameters such as agent name, LLM provider, initial message, and the inclusion of a code interpreter tool. ```Python from superagent import ( AgentType, LlmProvider, OpenAiAssistantParameters, OpenAiAssistantParametersToolsItem_CodeInterpreter, ) from superagent.client import Superagent client = Superagent( token="YOUR_TOKEN", ) client.agent.create( is_active=True, name="string", initial_message="string", prompt="string", llm_model="string", llm_provider=LlmProvider.OPENAI, description="string", avatar="string", type=AgentType.SUPERAGENT, parameters=OpenAiAssistantParameters( metadata={"string": {"key": "value"}}, file_ids=["string"], tools=[OpenAiAssistantParametersToolsItem_CodeInterpreter()], ), metadata={"string": {"key": "value"}}, output_schema="string", ) ``` -------------------------------- ### Uninstall Superagent Docker Services Source: https://docs.superagent.sh/overview/installation/docker-compose This command permanently removes all Docker services and their associated volumes for the current project. It's crucial to understand that this action will delete any data stored in the volumes, making it irreversible. ```Shell ./uninstall.sh ``` -------------------------------- ### Superagent API: List Tools Endpoint Source: https://docs.superagent.sh/api-reference/api-reference/tool/list Documents the GET /api/v1/tools endpoint for retrieving a list of all available tools in Superagent. It details the request parameters, authentication requirements, and the structure of the successful response, including an example JSON payload. ```APIDOC GET https://api.beta.superagent.sh/api/v1/tools Description: Retrieves a list of all available tools. Headers: Authorization: string (Required) Bearer authentication of the form Bearer , where token is your auth token. Query Parameters: skip: integer (Optional) Number of items to skip for pagination. take: integer (Optional) Number of items to take for pagination. Response (200 Retrieved): Content-Type: application/json Body: { "success": true, "total_pages": 1, "data": [ { "id": "id", "name": "name", "description": "description", "type": "ALGOLIA", "returnDirect": true, "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId", "metadata": "metadata", "apiUser": { "id": "id", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z" }, "tools": [ { "agentId": "agentId", "toolId": "toolId", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z" } ], "toolConfig": { "key": "value" } } ] } Errors: 422 Unprocessable Entity ``` -------------------------------- ### View Superagent Docker Service Logs Source: https://docs.superagent.sh/overview/installation/docker-compose These commands demonstrate how to view the real-time logs for various Superagent Docker services. The `-f` flag allows following the logs, which means new log entries will be displayed as they are generated until the command is manually stopped (e.g., with Ctrl+C). ```Shell docker logs superagent-api -f docker logs superagent-ui -f docker logs motorhead -f docker logs supabase-kong -f docker logs langfuse-server -f docker logs weaviate -f ``` -------------------------------- ### Initialize Superagent Client with API Key Source: https://docs.superagent.sh/overview/getting-started/configuring-vector-database This snippet demonstrates how to initialize the Superagent client using an API key and a base URL. It shows how to securely load the API key from environment variables and configure the client for either a production or local environment. ```Python from superagent.client import Superagent client = Superagent( token=os.environ["SUPERAGENT_API_KEY"], # replace with your Superagent API Key base_url="https://api.beta.superagent.sh" # or your local environment ) ``` -------------------------------- ### Initialize Superagent SDK with Local API Source: https://docs.superagent.sh/overview/installation/running-locally Python code snippet demonstrating how to initialize the Superagent SDK client to connect to a locally running Superagent API instance, using an API key and specifying the local base URL. ```Python 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 ) ``` -------------------------------- ### Configuring Local Hosts File for Docker Services Source: https://docs.superagent.sh/overview/installation/docker-compose This snippet illustrates how to add entries to your operating system's hosts file. These entries map local IP addresses (127.0.0.1) to the service names used within the Docker network, ensuring that services like `superagent-api` and `redis` are accessible both internally by other Docker containers and externally from your local machine via consistent URLs. ```bash 127.0.0.1 superagent-api 127.0.0.1 superagent-ui 127.0.0.1 pgdb 127.0.0.1 pgadmin 127.0.0.1 supabase-kong 127.0.0.1 langfuse-server 127.0.0.1 redis 127.0.0.1 weaviate 127.0.0.1 qdrant ``` -------------------------------- ### Initialize Superagent Client, Create LLM, Agent, and Tool Source: https://docs.superagent.sh/overview/getting-started/structured-outputs This snippet demonstrates how to set up the Superagent client using an API key, create an LLM (Large Language Model) instance with an OpenAI provider, define an AI agent with specific characteristics like name, description, and initial message, and register a browser tool. It then shows how to associate the created LLM and tool with the agent. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) # We recommend querying for existing LLMs prior to creating. llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create( name="Structured Assistant", description="An Assistant that returns responses in json", avatar="https://mylogo.com/logo.png", # Replace with a real image is_active=True, initial_message="Hi there! How can I help you?", llm_model="GPT_4_1106_PREVIEW", prompt="Use the Browser to answer the user's question." ) tool = client.tool.create( name="Browser", description="useful for analyzing and summarizing websites and urls.", type="BROWSER" ) client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) ``` -------------------------------- ### Initialize Superagent Client and Create LLM and Agent Source: https://docs.superagent.sh/overview/getting-started/custom-tools This snippet demonstrates how to initialize the Superagent client using an API key, create a Language Model (LLM) object with an OpenAI API key, and then create a new agent with specific configurations like name, description, and an initial message. Finally, it shows how to associate the created LLM with the agent. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create( name="Stock Assistant", description="An Assistant that can fetch stock prices", avatar="https://mylogo.com/logo.png", # Replace with a real image is_active=True, llm_model="GPT_3_5_TURBO_16K_0613", initial_message="Hi there, how can I help you?", prompt="Use the Stock API to answer the users question." ) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) ``` -------------------------------- ### Get Workflow using Superagent Python Client Source: https://docs.superagent.sh/api-reference/api-reference/workflow/get This Python code snippet demonstrates how to retrieve a specific workflow using the Superagent client library. It initializes the client with an authentication token and then calls the 'get' method on the 'workflow' service, passing the required workflow ID. ```Python from superagent.client import Superagent client = Superagent( token="YOUR_TOKEN", ) client.workflow.get( workflow_id="string", ) ``` -------------------------------- ### Superagent API: Get Vector Database by ID Source: https://docs.superagent.sh/api-reference/api-reference/vector-database/get This API documentation describes the GET endpoint for retrieving a single vector database record by its unique identifier. It outlines the required path parameters, authentication headers, and the detailed structure of the successful response body, along with potential error conditions. ```APIDOC GET /api/v1/vector-dbs/:vector_db_id Path Parameters: vector_db_id: string (Required) - The unique identifier of the vector database. Headers: Authorization: string (Required) - Bearer authentication token (e.g., "Bearer "). Responses: 200 OK: Description: Successfully retrieved the vector database. Body: { "success": true, "data": { "id": "id", "provider": "PINECONE", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId", "options": { "key": "value" }, "datasources": [ { "id": "id", "name": "name", "type": "TXT", "apiUserId": "apiUserId", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "status": "IN_PROGRESS" } ], "apiUser": { "id": "id", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "token": "token", "email": "email", "agents": [ { "id": "id", "type": "SUPERAGENT", "name": "name", "description": "description", "isActive": true, "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" } ], "llms": [ { "id": "id", "provider": "OPENAI", "apiKey": "apiKey", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" } ], "datasources": [ { "id": "id", "name": "name", "type": "TXT", "apiUserId": "apiUserId", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "status": "IN_PROGRESS" } ], "tools": [ { "id": "id", "name": "name", "description": "description", "type": "ALGOLIA", "returnDirect": true, "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" } ], "workflows": [ { "id": "id", "name": "name", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" } ], "workflowConfigs": [ { "id": "id", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "workflowId": "workflowId" } ], "apiKeys": [ { "id": "id", "name": "name", "displayApiKey": "displayApiKey", "createdAt": "2024-01-15T09:30:00Z", "updatedAt": "2024-01-15T09:30:00Z", "apiUserId": "apiUserId" } ] } } } 422 Unprocessable Entity: Description: The request could not be processed due to semantic errors. ``` -------------------------------- ### Configure LLM and Create Superagent AI Agent Source: https://docs.superagent.sh/overview/getting-started/chat-with-datasources This snippet demonstrates how to initialize the Superagent client, create an LLM configuration, and then define an AI agent with specific parameters like name, description, and initial message. It also shows how to associate the created LLM with the agent. ```Python import os from superagent.client import Superagent client = Superagent( base_url="https://api.beta.superagent.sh", token=os.environ["SUPERAGENT_API_KEY"] ) llm = client.llm.create(request={ "provider": "OPENAI", "apiKey": os.environ["OPENAI_API_KEY"] }) agent = client.agent.create( name="Earnings Assistant", description="An Assistant that's an expert at analyzing earnings reports", avatar="", is_active=True, initial_message="Hi there! How can I help you?", llm_model="GPT_3_5_TURBO_16K_0613", prompt="You are an expert at analyzing earnings reports.", ) client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id) ``` -------------------------------- ### Generate Prisma Client and Run Database Migrations Source: https://docs.superagent.sh/overview/installation/running-locally Commands to generate the Prisma client and apply pending database migrations to the Supabase instance, ensuring the database schema is up-to-date. ```Bash prisma generate prisma migrate dev ``` -------------------------------- ### Install Superagent Python SDK Source: https://docs.superagent.sh/templates/assistants/chat-image-generation This snippet demonstrates how to install the Superagent Python SDK using either Poetry or Pip. It's the first step to integrate Superagent into your Python project. ```Python poetry add superagent-py # or pip install superagent-py ``` -------------------------------- ### Create Superagent Datasource using Python SDK Source: https://docs.superagent.sh/overview/getting-started/configuring-vector-database This Python code illustrates how to initialize the Superagent client and create a new datasource. It shows how to specify the datasource's name, description, type (e.g., PDF), and URL, allowing Superagent to ingest data from the specified source into the configured vector database. ```python from superagent.client import Superagent client = Superagent( token=os.environ["SUPERAGENT_API_KEY"], # replace with your Superagent API Key base_url="https://api.beta.superagent.sh" # or your local environment ) datasource = client.datasource.create(request={ "name": "Tesla Q3 2023", "description": "Useful for answering questions about Teslas Q3 2023 earnings report", "type": "PDF", "url": "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q3-2023-Update-3.pdf" }) ``` -------------------------------- ### Uninstall Langfuse Services Source: https://docs.superagent.sh/overview/logging/langfuse Executes the `uninstall.sh` script to remove all Langfuse services, containers, and associated Docker resources. This command performs a clean uninstallation of the local Langfuse setup. ```bash # libs/.docker/external/observabillity/langfuse ./uninstall.sh ``` -------------------------------- ### Navigate to Langfuse Docker Compose Directory Source: https://docs.superagent.sh/overview/logging/langfuse Changes the current working directory to the specific location where the Langfuse Docker Compose setup files are stored within the project structure. ```bash cd libs/.docker/external/observabillity/langfuse/ ``` -------------------------------- ### Configure Superagent Environment Variables Source: https://docs.superagent.sh/overview/installation/running-locally This snippet provides an example of the mandatory and optional environment variables required to run Superagent, including API keys for OpenAI, Qdrant, AgentOps, Langfuse, LangSmith, E2B, Replicate, and database connection details for Supabase. ```Shell OPENAI_API_KEY= DATABASE_URL=postgres://:@:/postgres?pgbouncer=true DATABASE_MIGRATION_URL=postgresql://:@:/postgres JWT_SECRET=superagent VECTORSTORE=qdrant QDRANT_API_KEY= QDRANT_HOST= QDRANT_INDEX=superagent MEMORY_API_URL=https://memory.superagent.sh AGENTOPS_API_KEY= AGENTOPS_ORG_KEY= LANGFUSE_PUBLIC_KEY= LANGFUSE_SECRET_KEY= LANGFUSE_HOST= LANGCHAIN_TRACING_V2=False LANGCHAIN_ENDPOINT=https://api.smith.langchain.com LANGSMITH_PROJECT_ID= LANGCHAIN_API_KEY= E2B_API_KEY= REPLICATE_API_TOKEN= ```