1.3 Build Your First Agent

7 min read

What You’ll Build

In this lab, you’ll run the Product Strategy Research Agent introduced in Lessons 1.1 and 1.2.

The agent analyzes a hypothesis about how AI coding agents may change the Product Manager role. It examines the hypothesis’s assumptions, considers supporting and opposing arguments, and identifies the evidence needed for further investigation.

Research task

question

The hypothesis and research objectives.

Research Agent

Contains its instructions and uses an AI model.

Analysis output

result.final_output

The agent's written analysis.

Lab 1 has no external research tools or persistent knowledge base.

A research task is given to the Research Agent. The agent contains its instructions and uses an AI model to produce an analysis output. In Lab 1, the agent has no external research tools or persistent knowledge base.

The Research Agent contains its instructions and uses an AI model to produce its analysis.

This first version has no external research tools or persistent knowledge base. It cannot search the web or look up current sources. Its analysis relies on the information represented in the model’s training and the context provided in the task.

Before You Begin

To complete this lab, you’ll need:

  • Python 3.12 or later
  • A code editor, such as Visual Studio Code
  • A terminal
  • An OpenAI API key with API billing configured

If you haven’t set these up yet, follow Before You Begin.

Lab 1 is independent. It does not require completing any earlier labs.

Download Lab 1

Download Lab 1 (.zip)

Download the lab package, extract the ZIP, and open the folder in your code editor. We’ll walk through the code before running it.

The package contains:

  • lab1_agent.py: the Research Agent.
  • requirements.txt: the Python package the lab needs.
  • README.md: setup and run instructions.
  • examples/hypothesis_analysis_excerpt.md: an excerpt of an earlier output, for comparison. It is not the complete output, and your results will differ.

Explore the Code

Before running the agent, let’s look at the key parts of lab1_agent.py. The excerpts below are taken directly from the file; ... marks lines omitted here.

1. Import the SDK

In lab1_agent.py, line 1:

from agents import Agent, Runner

This imports two classes from the OpenAI Agents SDK: Agent, which defines the agent, and Runner, which runs it.

2. Define the agent

In lab1_agent.py, lines 6–43 (excerpt):

agent = Agent(
    name="Product Strategy Research Agent",
    instructions="""
    You are a research analyst specializing in
    product management, AI, software development,
    and organizational strategy.

    Your responsibility is to critically investigate
    emerging industry trends and hypotheses.
    ...
    """,
)

The name identifies the agent. The instructions describe how it should work, whatever hypothesis it is given. They include:

  • Its role: a research analyst specializing in product management, AI, software development, and organizational strategy.
  • An analytical approach: seven steps, from restating the hypothesis to suggesting research questions.
  • Research principles: for example, “Distinguish hypotheses from verified facts” and “Do not invent research, statistics, or citations.”
  • A writing style: clear, professional, and organized with meaningful headings.

3. Define the research task

In lab1_agent.py, lines 45–121 (excerpt):

question = """
Analyze the following emerging hypothesis:

Recent advances in AI coding agents, particularly
Anthropic's Claude Code and OpenAI Codex, may be
creating a divergence in the Product Manager role.
...
Important:
You do not currently have access to live research
tools or external information sources.
...
"""

The question variable holds the specific task for this run: the Builder PM hypothesis, nine research objectives, and research limitations for this task.

The instructions describe the agent’s general purpose and behavior. The question describes what it should analyze this time. You could give the same agent a different hypothesis without changing its instructions.

4. Run the agent

In lab1_agent.py, line 126:

result = Runner.run_sync(agent, question)

Runner.run_sync() runs the configured agent with the research task. The program waits until the run finishes before continuing.

5. Display the output

In lab1_agent.py, line 128:

print(result.final_output)

result.final_output contains the agent’s final analysis, and print() displays it in the terminal.

Run Your First Agent

These commands run in a terminal, not in the Python file.

Step 1: Open a terminal in the lab1 folder

Open a terminal in the extracted lab1 folder. In Visual Studio Code, you can use Terminal → New Terminal after opening the folder.

Step 2: Create and activate a virtual environment

Terminal — macOS or Linux:

python3 -m venv .venv
source .venv/bin/activate

Terminal — Windows PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

Your terminal should display (.venv) when the environment is active.

This environment belongs to Lab 1. Create it once; each time you open a new terminal for this lab, activate it again with the second command above. Later labs create their own environments inside their own folders.

If PowerShell blocks the activation script, see Microsoft’s guidance on PowerShell execution policies. Don’t change security settings without understanding them.

Step 3: Install the required packages

Terminal — macOS, Linux, or Windows PowerShell:

python -m pip install -r requirements.txt

This installs the OpenAI Agents SDK.

Step 4: Confirm that your API key is configured

These commands check whether the key is set without displaying it.

Terminal — macOS or Linux:

[ -n "$OPENAI_API_KEY" ] && echo "API key is set" || echo "API key is not set"

Terminal — Windows PowerShell:

if ($env:OPENAI_API_KEY) { "API key is set" } else { "API key is not set" }

If the key is not set, set it for the current terminal session.

Terminal — macOS or Linux:

export OPENAI_API_KEY="your-api-key"

Terminal — Windows PowerShell:

$env:OPENAI_API_KEY="your-api-key"

Replace your-api-key with your actual key. Never place API keys directly in source code or commit them to Git.

Step 5: Run the agent

Terminal — macOS, Linux, or Windows PowerShell:

python lab1_agent.py

Step 6: Examine the analysis

The program prints its title, followed by the agent’s analysis of the hypothesis.

Read through the analysis. Does it restate the hypothesis, identify assumptions, present supporting and opposing arguments, and suggest research questions?

Generated responses can differ between runs, so your analysis won’t match the example excerpt exactly.

Experiment: Change the Agent’s Behavior

Now let’s change the agent and observe what happens. Before you start, make a copy of the original script so you can restore it.

Terminal — macOS or Linux:

cp lab1_agent.py lab1_agent_original.py

Terminal — Windows PowerShell:

Copy-Item lab1_agent.py lab1_agent_original.py

Experiment A: Change the research task

In lab1_agent.py, replace the entire question assignment, from question = """ through its closing """ (lines 45–121), with a shorter hypothesis.

In lab1_agent.py, replace lines 45–121 with:

question = """
Analyze the following hypothesis:

AI coding agents may substantially reduce the time
required to develop software.
"""

Leave the instructions unchanged. Save the file, then run the agent again.

Terminal:

python lab1_agent.py

Compare the new analysis with your first run. How did the scope, structure, and level of detail change?

Experiment B: Change the agent instructions

First, restore the original research task by copying your backup over the edited file.

Terminal — macOS or Linux:

cp lab1_agent_original.py lab1_agent.py

Terminal — Windows PowerShell:

Copy-Item lab1_agent_original.py lab1_agent.py

Next, add a new research principle inside the instructions string. Find the Research principles: list (lines 28–35) and add the new line after - Focus on recent developments when relevant.

In lab1_agent.py, lines 8–43 after your edit (excerpt):

    instructions="""
    ...
    Research principles:
    - Be objective and analytical.
    ...
    - Focus on recent developments when relevant.
    - For each major claim, explain what evidence would verify it.
    ...
    """,

Keep the same indentation as the surrounding lines, and make sure the new line stays before the closing """ of the instructions. Save the file, then run the agent again.

Terminal:

python lab1_agent.py

Compare this analysis with your first run. Does it now explain what evidence would verify its major claims?

What Did You Observe?

Take a moment to reflect on your experiments:

  • What changed when the research task changed? Consider the scope and focus of the analysis.
  • What changed when the agent instructions changed? Consider how the agent treated its claims.
  • Did the agent independently research external information?

Your agent performed hypothesis analysis, not verified external research. It has no web search, no MCP connection, and no persistent knowledge base. Its analysis reflects the model’s existing capabilities, guided by your instructions and task.

Test Your UnderstandingOptional · 3 questions

Question 1 of 3

In lab1_agent.py, where is the specific hypothesis the agent analyzes?