Quickstart¶
Welcome to our Quickstart Guide! This guide is designed to help you get up and running with the AI Refinery SDK as quickly and smoothly as possible. For a more detailed overview of our project creation guidelines, visit our Project Guidelines page. In this quickstart guide, we will create a simple example project that utilizes both a custom utility agent and a built-in utility agent.
Environment Variables¶
To facilitate seamless login to the AI Refinery service, begin by setting the ACCOUNT
and API_KEY
environment variables as shown below.
Creating a Custom Agent¶
A custom agent is a Python function designed to process a string query and return a single output. An example of a custom utility agent can be seen below:
import os
import asyncio
import random
import string
from openai import AsyncOpenAI
from air import login, DistillerClient
from air import utils
auth = login(
account=str(os.getenv("ACCOUNT")),
api_key=str(os.getenv("API_KEY")),
)
async def simple_agent(query: str, **kwargs):
global auth
prompt = f"""Your task is to generate some synthetic data so that it will be useful to answer the user question. Do not mention this is synthetic data in your answer.\n\n{query}"""
# This is for local serving
client = AsyncOpenAI(**auth.openai())
# This is for production endpoint
# client = AsyncOpenAI(**auth.openai())
response = await client.chat.completions.create(
messages=[{"role": "user", "content": prompt}],
model="meta-llama/Llama-3.1-70B-Instruct",
)
return response.choices[0].message.content
In this example, the simple_agent
generates synthetic data in response to a user's query using the OpenAI API. Depending on your requirements, you can customize the agent to be simpler (e.g., returning "hello" for every input query) or more complex (e.g., interacting with other agents or retrieving relevant information using RAG). You can achieve this by modifying the provided function accordingly.
Creating a Distiller Client¶
Next, use our DistillerClient
API to create a distiller client. This client will interface with the AI Refinery service to run your project. Below is a function that sets up the distiller client. Here's what it does:
- Instantiates a
DistillerClient
. - Creates a project named
example
using the configuration specified in theexample.yaml
file. Details ofexample.yaml
are provided in the next section. - Adds the previously defined
simple_agent
to thecustom_agent_gallery
under the nameData Scientist Agent
. - Runs the project in
interactive
mode.
def interactive():
distiller_client = DistillerClient()
# upload your config file to register a new distiller project
distiller_client.create_project(config_path="example.yaml", project="example")
# Define a mapping between your custom agent to Callable.
# When the custom agent is summoned by the super agent / orchestrator,
# distiller-sdk will run the custom agent and send its response back to the
# multi-agent system.
custom_agent_gallery = {
"Data Scientist Agent": simple_agent,
}
distiller_client.interactive(
project="example",
uuid="test_user",
custom_agent_gallery=custom_agent_gallery,
)
if __name__ == "__main__":
# Run Interactive Mode
print("\nInteractive Mode")
interactive()
Project Configuration¶
Next, you will need to configure your project by using YAML.
orchestrator:
agent_list:
- agent_name: "Data Scientist Agent"
- agent_name: "Search Agent"
utility_agents:
- agent_class: CustomAgent
agent_name: "Data Scientist Agent"
agent_description: "The data scientist can help you perform data analytics."
config: {}
- agent_class: SearchAgent
agent_name: "Search Agent"
Data Scientist Agent
from the custom_agent_gallery
and a built-in utility agent named Search Agent.
The settings for each of these utility agents are specified under utility_agents.
You have the flexibility to expand your project based on your requirements. You can add additional custom agents that you define in the future or integrate built-in agents from our agent marketplace. Project Setup & Execution¶
Now that you have all the necessary code needed for the project, let us set it up and execute it.
Structure¶
- Create a directory named
example
. - Inside the
example
directory, create a Python file namedexample.py
and place all the Python code mentioned above into this file. - Also, within the
example
directory, create a YAML file namedexample.yaml
and paste the provided YAML configuration into this file.
This gives us the following project structure:
Execution¶
To execute the example project, run the following commands on your terminal:
Running these commands will create the project on the AI Refinery server. You can now interact with the agents directly from your terminal.