<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maryam Faizanmianoor on Medium]]></title>
        <description><![CDATA[Stories by Maryam Faizanmianoor on Medium]]></description>
        <link>https://medium.com/@maryam.faizanmianoor?source=rss-37bdc5beb426------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Pllw2Zz6uRlkPZQ7</url>
            <title>Stories by Maryam Faizanmianoor on Medium</title>
            <link>https://medium.com/@maryam.faizanmianoor?source=rss-37bdc5beb426------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:56:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maryam.faizanmianoor/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building AI Agents with OpenAI’s Agents SDK: A Beginner’s Guide]]></title>
            <link>https://medium.com/@maryam.faizanmianoor/building-ai-agents-with-openais-agents-sdk-a-beginner-s-guide-8f05a737cba7?source=rss-37bdc5beb426------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f05a737cba7</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[openai-sdk]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[bots]]></category>
            <dc:creator><![CDATA[Maryam Faizanmianoor]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 21:57:36 GMT</pubDate>
            <atom:updated>2025-06-01T21:57:36.000Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EFOiYSpLZHYnc2Y5.png" /></figure><p>Agents SDK from Open AI with support from AgentOps.ai. Building with the Agents SDK. New tools for building agents from OpenAI.</p><p>The recent release of <a href="https://github.com/openai/openai-agents-python">OpenAI’s Agents SDK</a> marks a significant step forward in making agentic AI applications more accessible to developers. In this guide, we’ll explore how to get started with the Agents SDK, understand its core concepts, and build a simple yet powerful agent-based application. <a href="http://www.agentops.ai/">AgentOps.ai</a> is launching with day 0 support for the Agents SDK. If you want to check it out, head to the link in my bio.</p><h3>What is OpenAI Agents SDK?</h3><p>The OpenAI Agents SDK is a lightweight, Python-based framework that enables developers to build AI applications with agentic capabilities. It provides a small set of powerful primitives:</p><p>Thanks for reading Agency AI! Subscribe for free to receive new posts and support my work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FuieqgXeTAX0mDoo.png" /></figure><ul><li><strong>Agents</strong>: LLMs equipped with instructions and tools</li><li><strong>Handoffs</strong>: Mechanisms for agents to delegate tasks to other specialized agents</li><li><strong>Guardrails</strong>: Systems to validate inputs and outputs</li><li><strong>Tracing</strong>: Built-in capabilities to visualize and debug agent workflows</li></ul><p>Let’s dive into how to use this SDK to build your first agent!</p><h3>Installation</h3><p>First, let’s install the OpenAI Agents SDK. We’ll use uv, a fast Python package installer, but you can also use pip if you prefer.</p><pre># Install uv if you don&#39;t have it already<br>curl -sSf https://install.python-poetry.org | python3 -</pre><pre># Create and activate a virtual environment<br>python -m venv venv<br>source venv/bin/activate  # On Windows, use: venv\Scripts\activate# Install the OpenAI Agents SDK<br>uv pip install openai-agents-sdk</pre><p>You’ll also need to set up your OpenAI API key:</p><pre>export OPENAI_API_KEY=your-api-key-here</pre><p>On Windows, you would use:</p><pre>set OPENAI_API_KEY=your-api-key-here</pre><h3>Creating Your First Agent</h3><p>Let’s start with a simple “Hello World” example to understand the basics:</p><pre>from agents import Agent, Runner<br>import asyncio</pre><pre>async def main():<br>    # Create a simple agent with instructions<br>    agent = Agent(<br>        name=&quot;Greeting Assistant&quot;,<br>        instructions=&quot;You are a friendly assistant that greets users in their preferred language.&quot;<br>    )<br>    <br>    # Run the agent with a user input<br>    result = await Runner.run(agent, &quot;Can you greet me in French?&quot;)<br>    <br>    # Print the final output<br>    print(result.final_output)if __name__ == &quot;__main__&quot;:<br>    asyncio.run(main())</pre><p>Save this as hello_agent.py and run it:</p><pre>python hello_agent.py</pre><p>You should see a greeting in French as the output!</p><h3>Understanding the Agent Loop</h3><p>When you call Runner.run(), the SDK initiates what&#39;s called the &quot;agent loop&quot;:</p><ul><li>The agent receives the input</li><li>The LLM processes the input based on the agent’s instructions</li><li>If the LLM produces a final output (text without tool calls), the loop ends</li><li>If the LLM calls a tool or requests a handoff, those are processed, and the loop continues</li><li>This repeats until a final output is produced or the maximum number of turns is reached</li></ul><h3>Adding Tools to Your Agent</h3><p>Agents become much more powerful when they can use tools. Let’s create an agent that can check the weather:</p><pre>from agents import Agent, Runner, function_tool<br>import asyncio</pre><pre># Define a tool as a Python function<br>@function_tool<br>def get_weather(city: str) -&gt; str:<br>    &quot;&quot;&quot;Get the current weather for a city.&quot;&quot;&quot;<br>    # In a real application, this would call a weather API<br>    weather_data = {<br>        &quot;New York&quot;: &quot;72°F, Sunny&quot;,<br>        &quot;London&quot;: &quot;65°F, Cloudy&quot;,<br>        &quot;Tokyo&quot;: &quot;80°F, Clear&quot;,<br>        &quot;Paris&quot;: &quot;70°F, Partly Cloudy&quot;<br>    }<br>    return weather_data.get(city, f&quot;Weather data not available for {city}&quot;)async def main():<br>    # Create an agent with the weather tool<br>    agent = Agent(<br>        name=&quot;Weather Assistant&quot;,<br>        instructions=&quot;You are a helpful assistant that provides weather information when asked.&quot;,<br>        tools=[get_weather]  # Add the tool to the agent<br>    )<br>    <br>    # Run the agent with a user query<br>    result = await Runner.run(agent, &quot;What&#39;s the weather like in Tokyo?&quot;)<br>    <br>    # Print the final output<br>    print(result.final_output)if __name__ == &quot;__main__&quot;:<br>    asyncio.run(main())</pre><p>When you run this, the agent will use the get_weather tool to fetch and return the weather for Tokyo.</p><h3>Creating Specialized Agents with Handoffs</h3><p>One of the most powerful features of the Agents SDK is the ability to create specialized agents and allow them to hand off tasks to each other. Let’s create a system with a triage agent that can delegate to language-specific agents:</p><pre>from agents import Agent, Runner<br>import asyncio</pre><pre># Create specialized language agents<br>spanish_agent = Agent(<br>    name=&quot;spanish_agent&quot;,<br>    instructions=&quot;You are a helpful assistant that only speaks Spanish. Always respond in Spanish, regardless of the language of the question.&quot;<br>)french_agent = Agent(<br>    name=&quot;french_agent&quot;,<br>    instructions=&quot;You are a helpful assistant that only speaks French. Always respond in French, regardless of the language of the question.&quot;<br>)# Create a triage agent that can hand off to specialized agents<br>triage_agent = Agent(<br>    name=&quot;language_triage&quot;,<br>    instructions=&quot;&quot;&quot;You are a language detection assistant. <br>    Your job is to determine what language the user wants a response in.<br>    If they want Spanish, hand off to the spanish_agent.<br>    If they want French, hand off to the french_agent.<br>    If they don&#39;t specify a language or want English, respond directly in English.&quot;&quot;&quot;,<br>    handoffs=[spanish_agent, french_agent]  # Add the specialized agents as handoffs<br>)async def main():<br>    # Test with different language requests<br>    queries = [<br>        &quot;Can you tell me about the Eiffel Tower in French?&quot;,<br>        &quot;¿Puedes hablarme sobre el clima en Madrid?&quot;,<br>        &quot;Tell me about the history of New York.&quot;<br>    ]<br>    <br>    for query in queries:<br>        print(f&quot;\nQuery: {query}&quot;)<br>        result = await Runner.run(triage_agent, query)<br>        print(f&quot;Response: {result.final_output}&quot;)if __name__ == &quot;__main__&quot;:<br>    asyncio.run(main())</pre><p>When you run this, the triage agent will:</p><ul><li>Respond directly in English for the New York query</li><li>Hand off to the Spanish agent for the Madrid query</li><li>Hand off to the French agent for the Eiffel Tower query</li></ul><h3>Implementing Guardrails</h3><p>Guardrails help ensure that your agents operate within defined boundaries. Let’s add an input guardrail to prevent our agent from responding to inappropriate requests:</p><pre>from agents import Agent, Runner, InputGuardrail, GuardrailFunctionOutput<br>import asyncio</pre><pre># Define a guardrail function<br>async def content_filter(input_text: str, context) -&gt; GuardrailFunctionOutput:<br>    &quot;&quot;&quot;Check if the input contains inappropriate content.&quot;&quot;&quot;<br>    inappropriate_keywords = [&quot;hack&quot;, &quot;illegal&quot;, &quot;cheat&quot;]<br>    <br>    # Check if any inappropriate keywords are in the input<br>    contains_inappropriate = any(keyword in input_text.lower() for keyword in inappropriate_keywords)<br>    <br>    return GuardrailFunctionOutput(<br>        output_info={&quot;contains_inappropriate&quot;: contains_inappropriate},<br>        tripwire_triggered=contains_inappropriate<br>    )async def main():<br>    # Create an agent with a guardrail<br>    agent = Agent(<br>        name=&quot;Safe Assistant&quot;,<br>        instructions=&quot;You are a helpful assistant that provides information on legal and ethical topics.&quot;,<br>        input_guardrails=[InputGuardrail(guardrail_function=content_filter)]<br>    )<br>    <br>    # Test with appropriate and inappropriate queries<br>    queries = [<br>        &quot;Tell me about the history of computers&quot;,<br>        &quot;How can I hack into my neighbor&#39;s WiFi?&quot;<br>    ]<br>    <br>    for query in queries:<br>        try:<br>            print(f&quot;\nQuery: {query}&quot;)<br>            result = await Runner.run(agent, query)<br>            print(f&quot;Response: {result.final_output}&quot;)<br>        except Exception as e:<br>            print(f&quot;Guardrail triggered: {e}&quot;)if __name__ == &quot;__main__&quot;:<br>    asyncio.run(main())</pre><p>When you run this, the agent will respond normally to the first query but will trigger the guardrail for the second query containing “hack”.</p><h3>Using Tracing for Debugging</h3><p>The Agents SDK includes built-in tracing capabilities that help you understand what’s happening during agent execution. Let’s add tracing to our weather agent:</p><pre>from agents import Agent, Runner, function_tool<br>from agents.tracing import trace<br>import asyncio</pre><pre>@function_tool<br>def get_weather(city: str) -&gt; str:<br>    &quot;&quot;&quot;Get the current weather for a city.&quot;&quot;&quot;<br>    weather_data = {<br>        &quot;New York&quot;: &quot;72°F, Sunny&quot;,<br>        &quot;London&quot;: &quot;65°F, Cloudy&quot;,<br>        &quot;Tokyo&quot;: &quot;80°F, Clear&quot;,<br>        &quot;Paris&quot;: &quot;70°F, Partly Cloudy&quot;<br>    }<br>    return weather_data.get(city, f&quot;Weather data not available for {city}&quot;)async def main():<br>    # Create a trace for the entire workflow<br>    with trace(workflow_name=&quot;weather_inquiry&quot;):<br>        agent = Agent(<br>            name=&quot;Weather Assistant&quot;,<br>            instructions=&quot;You are a helpful assistant that provides weather information when asked.&quot;,<br>            tools=[get_weather]<br>        )<br>        <br>        result = await Runner.run(<br>            agent, <br>            &quot;What&#39;s the weather like in Tokyo and Paris?&quot;,<br>            run_config=RunConfig(<br>                workflow_name=&quot;weather_inquiry&quot;,<br>                trace_include_sensitive_data=True<br>            )<br>        )<br>        <br>        print(result.final_output)<br>        <br>        # You can access the trace information<br>        current_trace = get_current_trace()<br>        if current_trace:<br>            print(f&quot;Trace ID: {current_trace.trace_id}&quot;)if __name__ == &quot;__main__&quot;:<br>    from agents import RunConfig<br>    from agents.tracing import get_current_trace<br>    asyncio.run(main())</pre><p>This code adds tracing to our weather agent, allowing us to see the entire workflow, including LLM calls, tool executions, and more.</p><h3>Building a Complete Example: Multi-Service Customer Support Agent</h3><p>Now, let’s build a more complete example: a customer support system with specialized agents for different types of inquiries:</p><pre>from agents import Agent, Runner, function_tool<br>import asyncio<br>from datetime import datetime, timedelta<br>import random</pre><pre># Define some tools for our agents@function_tool<br>def check_order_status(order_id: str) -&gt; str:<br>    &quot;&quot;&quot;Check the status of an order by ID.&quot;&quot;&quot;<br>    # Simulate order database<br>    statuses = [&quot;Processing&quot;, &quot;Shipped&quot;, &quot;Delivered&quot;, &quot;Cancelled&quot;]<br>    return f&quot;Order {order_id} is currently {random.choice(statuses)}.&quot;@function_tool<br>def get_shipping_estimate(product_id: str, destination: str) -&gt; str:<br>    &quot;&quot;&quot;Get shipping estimate for a product to a destination.&quot;&quot;&quot;<br>    # Simulate shipping calculation<br>    days = random.randint(2, 10)<br>    estimated_date = (datetime.now() + timedelta(days=days)).strftime(&quot;%B %d, %Y&quot;)<br>    return f&quot;Shipping to {destination} takes approximately {days} days. Estimated delivery: {estimated_date}&quot;@function_tool<br>def process_refund(order_id: str, reason: str) -&gt; str:<br>    &quot;&quot;&quot;Process a refund request.&quot;&quot;&quot;<br>    return f&quot;Refund for order {order_id} has been initiated. Reason: {reason}. It will be processed within 3-5 business days.&quot;# Create specialized agentsorder_agent = Agent(<br>    name=&quot;order_specialist&quot;,<br>    instructions=&quot;&quot;&quot;You are an order specialist. <br>    Help customers check their order status and provide shipping estimates.<br>    Be friendly and professional.&quot;&quot;&quot;,<br>    tools=[check_order_status, get_shipping_estimate]<br>)refund_agent = Agent(<br>    name=&quot;refund_specialist&quot;,<br>    instructions=&quot;&quot;&quot;You are a refund specialist.<br>    Help customers process refunds for their orders.<br>    Be empathetic and helpful.&quot;&quot;&quot;,<br>    tools=[process_refund]<br>)# Create the main triage agentsupport_agent = Agent(<br>    name=&quot;customer_support&quot;,<br>    instructions=&quot;&quot;&quot;You are a customer support agent for an e-commerce store.<br>    If customers have questions about order status or shipping, hand off to the order specialist.<br>    If customers want to request a refund, hand off to the refund specialist.<br>    For general questions, answer directly.<br>    Always be polite and helpful.&quot;&quot;&quot;,<br>    handoffs=[order_agent, refund_agent]<br>)async def main():<br>    # Simulate a customer support conversation<br>    queries = [<br>        &quot;What&#39;s the status of my order #12345?&quot;,<br>        &quot;I want to return my purchase because it&#39;s damaged. Order #54321.&quot;,<br>        &quot;Do you offer gift wrapping services?&quot;,<br>        &quot;How long will shipping take for product XYZ-789 to Seattle?&quot;<br>    ]<br>    <br>    for i, query in enumerate(queries):<br>        print(f&quot;\n--- Customer Query {i+1} ---&quot;)<br>        print(f&quot;Customer: {query}&quot;)<br>        <br>        result = await Runner.run(support_agent, query)<br>        <br>        print(f&quot;Agent: {result.final_output}&quot;)if __name__ == &quot;__main__&quot;:<br>    asyncio.run(main())</pre><p>This example demonstrates a complete customer support system with:</p><ul><li>A main triage agent that handles initial customer inquiries</li><li>Specialized agents for orders and refunds</li><li>Tools for checking order status, estimating shipping, and processing refunds</li><li>Handoffs between agents based on the customer’s needs</li></ul><h3>Conclusion</h3><p>The OpenAI Agents SDK provides a powerful yet accessible way to build agentic AI applications. With just a few core concepts — agents, tools, handoffs, and guardrails — you can create sophisticated systems that leverage the power of large language models while maintaining control over their behavior.</p><p>As you continue to explore the SDK, you might want to experiment with:</p><ul><li>More complex tool implementations that connect to real APIs</li><li>Custom input and output types for structured data</li><li>Advanced guardrails for safety and quality control</li><li>Tracing and monitoring for production applications</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f05a737cba7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>