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 Agent2from kern.models.openai import OpenAIResponses34agent = Agent(5 model=OpenAIResponses(id="gpt-4o"),6 followups=True,7 num_followups=3,8)910response = agent.run("What is quantum computing?")1112print(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.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 Agent
1python 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 | Agent's model | Separate 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 asyncio23from kern.agent import Agent, RunEvent4from kern.models.openai import OpenAIResponses56agent = Agent(7 model=OpenAIResponses(id="gpt-4o"),8 followups=True,9 num_followups=3,10)111213async 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)2122 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}")262728asyncio.run(main())Using a separate model
Use followup_model to offload followup generation to a cheaper model.
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses34agent = Agent(5 model=OpenAIResponses(id="gpt-4o"),6 followups=True,7 num_followups=3,8 followup_model=OpenAIResponses(id="gpt-4o-mini"),9)