Getting started

Chat with tools

Superagent comes packed with pre-built tools you can use together with your Assistants. Tools are a way for assistants to connect and retrieve data/information from third-party APIs or applications.
Superagent supports different types of tools listed here.

Step-by-step guide

  1. Start by creating an LLM and an Agent. Note that you can use already created LLMs or Agents.

Note that you usually only need to create the llm object once and re-use it for subsequent agents you create.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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": "Browser Assistant",
    "description": "An Assistant that has access to the Browser tool",
    "avatar": "https://mylogo.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": "Use the Browser to answer the users question."
})

client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id)
  1. Create a tool. You can create and attach multiple tools to an Assistant. Note that the description key tells the Assistant when this tool should be used. Be vary of what you put in as your description as it might effect the Assistants behaviour.
1
2
3
4
5
6
7
8
9
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. 
    "returnDirect": false, # returnDirect is required while creating a tool.
})

client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id)
  1. Now we are ready to invoke the Agent...
1
2
3
4
5
6
7
8
 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"))

That's it! Tools are super powerful way ginving your Assistants super powers. We are constantly adding new tools based on the feedback from the community.

Full code

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
 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": "Browser Assistant",
     "description": "An Assistant that has access to the Browser tool",
     "avatar": "https://mylogo.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": "Use the Browser to answer the users 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. 
     "returnDirect": false,
 })

 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"))

Replit template

We've created a Replit template for this which you can run here.