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).
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
9agent1 = client.agent.create(
10 name="Blog Assistant",
11 description="An Assistant that can create blog post contents",
12 avatar="https://example.com/logo.png", # Replace with a real image
13 is_active=True,
14 llm_model="GPT_3_5_TURBO_16K_0613",
15 initial_message="Hi there, how can I help you?",
16 prompt="Create blog post contents."
17)
18
19agent2 = client.agent.create(
20 name="Title Assistant",
21 description="An Assistant that can create a compelling blog post title",
22 avatar="https://example.com/logo2.png", # Replace with a real image
23 is_active=True,
24 llm_model="GPT_3_5_TURBO_16K_0613",
25 initial_message="Hi there, how can I help you?",
26 prompt="Given a blog post, create a compelling title."
27)
  1. Next, let’s create a workflow.
1workflow = client.workflow.create(request={
2 "name": "Blog Post Generator Workflow",
3 "description": "Useful for generating blog post",
4})
  1. Add the workflow steps
1 step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
2 "agentId": agent1.data.id,
3 "order": 0
4 })
5 step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
6 "agentId": agent2.data.id,
7 "order": 1
8 })
  1. Let’s invoke the workflow
1response = client.workflow.invoke(workflow_id=workflow.data.id, input="create a blog post about AI", enable_streaming=False)
2print(response)

Full code

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
9agent1 = client.agent.create(
10 name="Blog Assistant",
11 description="An Assistant that can create blog post contents",
12 avatar="https://example.com/logo.png", # Replace with a real image
13 is_active=True,
14 llm_model="GPT_3_5_TURBO_16K_0613",
15 initial_message="Hi there, how can I help you?",
16 prompt="Create blog post contents."
17)
18
19agent2 = client.agent.create(
20 name="Title Assistant",
21 description="An Assistant that can create a compelling blog post title",
22 avatar="https://example.com/logo2.png", # Replace with a real image
23 is_active=True,
24 llm_model="GPT_3_5_TURBO_16K_0613",
25 initial_message="Hi there, how can I help you?",
26 prompt="Given a blog post, create a compelling title."
27)
28
29workflow = client.workflow.create(request={
30 "name": "Blog Post Generator Workflow",
31 "description": "Useful for generating blog post",
32})
33
34step1 = client.workflow.add_step(workflow_id=workflow.data.id, request={
35 "agentId": agent1.data.id,
36 "order": 0
37})
38step2 = client.workflow.add_step(workflow_id=workflow.data.id, request={
39 "agentId": agent2.data.id,
40 "order": 1
41})
42response = client.workflow.invoke(workflow_id=workflow.data.id,
43 input="create a blog post about AI", enable_streaming=False)
44print(response)