Team with Followup Suggestions

Generate actionable followup prompts after every team response.

Set followups=True on a Team to automatically generate followup prompt suggestions after each response. Works the same way as agent followups, with support for all team modes.

Create a Python file

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.team.team import Team
4from kern.team.mode import TeamMode
5
6researcher = Agent(
7 name="Researcher",
8 role="Research topics thoroughly",
9 model=OpenAIResponses(id="gpt-4o"),
10)
11
12team = Team(
13 name="Research Team",
14 model=OpenAIResponses(id="gpt-4o"),
15 mode=TeamMode.coordinate,
16 members=[researcher],
17 followups=True,
18 num_followups=3,
19)
20
21response = team.run("What are the latest advances in fusion energy?")
22
23print(response.content)
24print("\nFollowup suggestions:")
25for i, suggestion in enumerate(response.followups, 1):
26 print(f" {i}. {suggestion}")

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U kern-ai openai

Export your OpenAI API key

1export OPENAI_API_KEY="your_openai_api_key_here"
1$Env:OPENAI_API_KEY="your_openai_api_key_here"

Run Team

1python team_followup_suggestions.py

Options

ParameterTypeDefaultDescription
followupsboolFalseEnable followup suggestion generation
num_followupsint3Number of suggestions to generate (minimum 1)
followup_modelModelTeam's modelSeparate model for generating followups. Use a smaller model to reduce cost.

Streaming

Followup suggestions are available via events when streaming.

1import asyncio
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.team.team import Team
6from kern.team.mode import TeamMode
7from kern.team import TeamRunEvent
8
9researcher = Agent(
10 name="Researcher",
11 role="Research topics thoroughly",
12 model=OpenAIResponses(id="gpt-4o"),
13)
14
15team = Team(
16 name="Research Team",
17 model=OpenAIResponses(id="gpt-4o"),
18 mode=TeamMode.coordinate,
19 members=[researcher],
20 followups=True,
21 num_followups=3,
22)
23
24
25async def main():
26 async for event in team.arun(
27 "What are the latest advances in fusion energy?",
28 stream=True,
29 stream_events=True,
30 ):
31 if event.event == TeamRunEvent.run_content and event.content:
32 print(event.content, end="", flush=True)
33
34 if event.event == TeamRunEvent.followups_completed:
35 print("\n\nFollowup suggestions:")
36 for i, suggestion in enumerate(event.followups, 1):
37 print(f" {i}. {suggestion}")
38
39
40asyncio.run(main())

Developer Resources