Agent with Followup Suggestions

Generate actionable followup prompts after every agent response.

Set followups=True to automatically generate followup prompt suggestions after each response. The agent makes a second model call to produce short, action-oriented prompts based on the conversation.

Create a Python file

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3
4agent = Agent(
5 model=OpenAIResponses(id="gpt-4o"),
6 followups=True,
7 num_followups=3,
8)
9
10response = agent.run("What is quantum computing?")
11
12print(response.content)
13print("\nFollowup suggestions:")
14for i, suggestion in enumerate(response.followups, 1):
15 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 Agent

1python followup_suggestions.py

Options

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

Streaming

Followup suggestions are available via events when streaming. The FollowupsCompleted event carries the suggestions after the main response finishes.

1import asyncio
2
3from kern.agent import Agent, RunEvent
4from kern.models.openai import OpenAIResponses
5
6agent = Agent(
7 model=OpenAIResponses(id="gpt-4o"),
8 followups=True,
9 num_followups=3,
10)
11
12
13async def main():
14 async for event in agent.arun(
15 "What is quantum computing?",
16 stream=True,
17 stream_events=True,
18 ):
19 if event.event == RunEvent.run_content and event.content:
20 print(event.content, end="", flush=True)
21
22 if event.event == RunEvent.followups_completed:
23 print("\n\nFollowup suggestions:")
24 for i, suggestion in enumerate(event.followups, 1):
25 print(f" {i}. {suggestion}")
26
27
28asyncio.run(main())

Using a separate model

Use followup_model to offload followup generation to a cheaper model.

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3
4agent = Agent(
5 model=OpenAIResponses(id="gpt-4o"),
6 followups=True,
7 num_followups=3,
8 followup_model=OpenAIResponses(id="gpt-4o-mini"),
9)

Developer Resources