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 Agent2from kern.models.openai import OpenAIResponses3from kern.team.team import Team4from kern.team.mode import TeamMode56researcher = Agent(7 name="Researcher",8 role="Research topics thoroughly",9 model=OpenAIResponses(id="gpt-4o"),10)1112team = 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)2021response = team.run("What are the latest advances in fusion energy?")2223print(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.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openaiExport 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.pyOptions
| Parameter | Type | Default | Description |
|---|---|---|---|
followups | bool | False | Enable followup suggestion generation |
num_followups | int | 3 | Number of suggestions to generate (minimum 1) |
followup_model | Model | Team's model | Separate model for generating followups. Use a smaller model to reduce cost. |
Streaming
Followup suggestions are available via events when streaming.
1import asyncio23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.team.team import Team6from kern.team.mode import TeamMode7from kern.team import TeamRunEvent89researcher = Agent(10 name="Researcher",11 role="Research topics thoroughly",12 model=OpenAIResponses(id="gpt-4o"),13)1415team = 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)232425async 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)3334 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}")383940asyncio.run(main())