USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksAI Agent Book
HomeAI Agent BookOpenAI Agents SDK
PreviousHow Do You Choose an Agent Architecture?NextDefine OpenAI Agents, Instructions, Models, and Output
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

12 sections

Progress0%
1 / 12

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Set Up and Run Your First OpenAI Agent

The OpenAI Agents SDK packages an agent’s model, instructions, tools, handoffs, guardrails, and output contract, while a runner executes the model-and-tool loop. Your first program should use one focused agent with no tools, prove authentication and result handling, inspect its trace, and only then add authority.

What will you be able to do?

You will create an isolated project, install openai-agents, run one asynchronous turn, distinguish Agent from Runner, and diagnose the common setup failures.

What do you need before starting?

  • Python 3.10 or newer.
  • An OpenAI API account with an API key and available usage.
  • A terminal and editor.

Check current models, access, and pricing in the official console. Model identifiers in documentation can change; this example uses the SDK default rather than freezing one into the lesson.

How do you install the SDK?

bash
mkdir supportops-openai && cd supportops-openai python3 -m venv .venv source .venv/bin/activate pip install openai-agents export OPENAI_API_KEY="replace-with-your-key"

Do not put the key in source code or shell history on a shared machine. A production service should obtain it from a secrets manager.

How do you build the first agent?

first_agent.py:

python
import asyncio from agents import Agent, Runner triage_agent = Agent( name="Support triage learner", instructions=( "Classify the request as billing, technical, or general. " "Explain the classification in one sentence. Do not claim to take action." ), ) async def main() -> None: result = await Runner.run( triage_agent, "I was charged twice for the same subscription.", max_turns=3, ) print(result.final_output) if __name__ == "__main__": asyncio.run(main())

Run it:

bash
python first_agent.py

Agent is configuration. Runner.run() performs the loop and returns a result. final_output is the final user-facing value; later chapters inspect richer history, usage, interruptions, and state.

How do you prove it works?

Check four pieces of evidence:

  1. The process exits successfully.
  2. The result identifies billing and does not claim a refund occurred.
  3. A run appears in the OpenAI Traces dashboard on the normal server-side SDK path.
  4. Removing OPENAI_API_KEY produces an authentication/configuration failure rather than a fabricated result.

Exact wording may vary; the behavioral assertions should not.

Trace this run: The input enters Runner, the model produces a final answer without a tool call, and the runner returns. There is one application turn and no delegated authority.

How does it fail safely?

Test a request such as “refund me now.” The agent has no refund tool, so it cannot perform the action. It should state its limitation instead of pretending. Capability comes from tools and runtime access, not from confident language.

What changes in production?

Use centralized configuration, pin and test dependency upgrades, set request deadlines, attach correlation/tenant identifiers through local run context, redact traces where required, and translate provider errors into stable domain outcomes. Keep the first production slice read-only.

What mistakes should you avoid?

  • Installing the openai client and assuming it is the openai-agents package.
  • Committing the API key.
  • Starting with tools, handoffs, and memory simultaneously.
  • Asserting exact prose in tests.
  • Ignoring traces until the workflow is already complex.

Check your understanding

  1. What does Agent configure, and what does Runner do?
  2. Why does this first agent have no side-effect authority?
  3. Which four artifacts prove the setup is working?

Expert extension

Wrap the run in an application function that accepts a request ID and returns a typed domain outcome. Add a timeout and a test using a fake adapter—without calling the live API.

Official references

  • OpenAI Agents SDK quickstart
  • OpenAI Agents SDK for Python