Getting started

Assistant workflows

Workflows allow you to connect multiple assistants in a sequential chain passing the output from one step to another in a deterministic way.

Step-by-step guide

  1. Start by creating 2 agents (you need to have at least 2 agents to be able to create a workflow).
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
import os
from superagent.client import Superagent

client = Superagent(
    base_url="https://api.beta.superagent.sh",
    token=os.environ["SUPERAGENT_API_KEY"]
)

agent = client.agent.create(request={
    "name": "Blog Assistant",
    "description": "An Assistant that can create blog post contents",
    "avatar": "https://example.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": "Create blog post contents."
})

agent2 = client.agent.create(request={
    "name": "Image Assistant",
    "description": "An Assistant that can generate image",
    "avatar": "https://example.com/logo2.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 SDXL API to generate an image."
})

  1. Next, let's create a workflow.
1
2
3
4
workflow = client.workflow.create(request={
    "name": "Blog Post Generator Workflow",
    "description": "Useful for generating blog post",
})
  1. Add the workflow steps
1
2
3
4
5
6
7
8
    step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
        "agentId": agent1.data.id,
        "order": 0
    })
    step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
        "agentId": agent2.data.id,
        "order": 1
    })
  1. Let's invoke the workflow
1
2
response = client.workflow.invoke(workflow_id=workflow.data.id, input="create a blog post about AI", enable_streaming=False)
print(response)

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
43
44
import os
from superagent.client import Superagent

client = Superagent(
    base_url="https://api.beta.superagent.sh",
    token=os.environ["SUPERAGENT_API_KEY"]
)

agent = client.agent.create(request={
    "name": "Blog Assistant",
    "description": "An Assistant that can create blog post contents",
    "avatar": "https://example.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": "Create blog post contents."
})

agent2 = client.agent.create(request={
    "name": "Image Assistant",
    "description": "An Assistant that can generate image",
    "avatar": "https://example.com/logo2.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 SDXL API to generate an image."
})

 workflow = client.workflow.create(request={
    "name": "Blog Post Generator Workflow",
    "description": "Useful for generating blog post",
})

step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent1.data.id,
    "order": 0
})
step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
    "agentId": agent2.data.id,
    "order": 1
})
response = client.workflow.invoke(workflow_id=workflow.data.id, input="create a blog post about AI", enable_streaming=False)
print(response)