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.


1import os
2from superagent.client import Superagent
3
4client = Superagent(
5 base_url="https://api.beta.superagent.sh",
6 token=os.environ["SUPERAGENT_API_KEY"]
7)
8
9llm = client.llm.create(request={
10 "provider": "OPENAI",
11 "apiKey": os.environ["OPENAI_API_KEY"]
12})
13
14agent = client.agent.create(
15 name="Chat Assistant",
16 description="An Assistant that has access to the Browser tool",
17 avatar="https://mylogo.com/logo.png", # Replace with a real image
18 is_active=True,
19 initial_message="Hi there! How can I help you?",
20 llm_model="GPT_3_5_TURBO_16K_0613",
21 prompt="Use the Browser to answer the user's question."
22)
23
24client.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 wary of what you put in as your description as it might effect the Assistants behaviour.
1tool = client.tool.create(
2 name="Browser",
3 description="A portal to the internet, useful for answering questions about websites or urls.",
4 type="BROWSER",
5 # metadata={"key": "value"} Optional metadata for the tool.
6 return_direct=False # return_direct is required while creating a tool.
7)
8
9client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id)
  1. Now we are ready to invoke the Agent…
1 prediction = client.agent.invoke(
2 agent_id=agent.data.id,
3 input="Summarize superagent.sh",
4 enable_streaming=False,
5 session_id="my_session_id",
6 )
7
8 print(prediction.data.get("output"))

That’s it! Tools are a super powerful way giving your Assistants superpowers. We are constantly adding new tools based on the feedback from the community.

Full code

1 import os
2 from superagent.client import Superagent
3
4 client = Superagent(
5 base_url="https://api.beta.superagent.sh",
6 token=os.environ["SUPERAGENT_API_KEY"]
7 )
8
9 llm = client.llm.create(request={
10 "provider": "OPENAI",
11 "apiKey": os.environ["OPENAI_API_KEY"]
12 })
13
14 agent = client.agent.create(
15 name="Chat Assistant",
16 description="An Assistant that has access to the Browser tool",
17 avatar="https://mylogo.com/logo.png", # Replace with a real image
18 is_active=True,
19 initial_message="Hi there! How can I help you?",
20 llm_model="GPT_3_5_TURBO_16K_0613",
21 prompt="Use the Browser to answer the user's question."
22 )
23
24 tool = client.tool.create(
25 name="Browser",
26 description="A portal to the internet, useful for answering questions about websites or urls.",
27 type="BROWSER",
28 # metadata={"key": "value"} Optional metadata for the tool.
29 return_direct=False # return_direct is required while creating a tool.
30 )
31
32 client.agent.add_llm(agent_id=agent.data.id, llm_id=llm.data.id)
33 client.agent.add_tool(agent_id=agent.data.id, tool_id=tool.data.id)
34
35 prediction = client.agent.invoke(
36 agent_id=agent.data.id,
37 input="Summarize superagent.sh",
38 enable_streaming=False,
39 session_id="my_session_id",
40 )
41
42 print(prediction.data.get("output"))

Replit template

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