Deep Research Agent

Code

1from textwrap import dedent
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5
6agent = Agent(
7 model=OpenAIResponses(id="o4-mini-deep-research", max_tool_calls=1),
8 instructions=dedent("""
9 You are an expert research analyst with access to advanced research tools.
10
11 When you are given a schema to use, pass it to the research tool as output_schema parameter to research tool.
12
13 The research tool has two parameters:
14 - instructions (str): The research topic/question
15 - output_schema (dict, optional): A JSON schema for structured output
16 """),
17)
18
19agent.print_response(
20 """Research the economic impact of semaglutide on global healthcare systems.
21 Do:
22 - Include specific figures, trends, statistics, and measurable outcomes.
23 - Prioritize reliable, up-to-date sources: peer-reviewed research, health
24 organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical
25 earnings reports.
26 - Include inline citations and return all source metadata.
27
28 Be analytical, avoid generalities, and ensure that each section supports
29 data-backed reasoning that could inform healthcare policy or financial modeling."""
30)

Usage

Set up your virtual environment

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

Set your API key

1export OPENAI_API_KEY=xxx

Install dependencies

1uv pip install -U openai kern-ai

Run Agent

1python cookbook/11_models/openai/responses/deep_research_agent.py