Build an OpenAI Agent
~2 min read
Concept & How It Works
- Key points are in the visual diagram above.
Learn these elsewhere (not covered in depth here)
- →Sessions & Handoffs
- →Guardrails & Tracing
Why Does It Exist?
Reading the docs is not the same as a runner that stops, traces, and refuses jailbreaks.
Real-World Analogy
A front desk that badges visitors, then walks them to billing or engineering.
Visual Workflows
What is Build an OpenAI Agent?
Example
Scenario
Triage → billing or engineering. Billing has refund_tool. Input guardrail rejects 'ignore previous instructions'.
Solution
In OpenAI Agents SDK, apply Build an OpenAI Agent to this scenario: Triage → billing or engineering. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Do this before moving to the next module — reading alone is not enough.
Open the Code Walkthrough below and run it locally. Change one parameter related to Build an OpenAI Agent (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Build an OpenAI Agent happens in the code.
1from agents import Agent, Runner, InputGuardrail, GuardrailFunctionOutput # import dependencies2
3billing = Agent(name="Billing", instructions="Answer invoices and refunds.", tools=[refund_tool]) # key line for Build an OpenAI Agent4eng = Agent(name="Eng", instructions="Answer product bugs.") # key line for Build an OpenAI Agent5
6async def no_inject(ctx, agent, input): # key line for Build an OpenAI Agent7 bad = "ignore previous" in str(input).lower()8 return GuardrailFunctionOutput(tripwire_triggered=bad, output_info={}) # return the result9
10triage = Agent( # key line for Build an OpenAI Agent11 name="Triage",12 instructions="Route to billing or eng.",13 handoffs=[billing, eng],14 input_guardrails=[InputGuardrail(guardrail_function=no_inject)],15)16result = await Runner.run(triage, "I was charged twice")Commands to Remember
Commands to Remember
Agent + Runner.runHandoffs are other agentsGuardrails on input/outputSpecialists stay narrow
Common Mistakes
- One god-agent with 40 tools
- No guardrail on user text
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •Triage routes
- •Guardrail tripwire
- •Trace the run
- •Don't nest 12 agents
