The best way to Use OpenAI’s Responses API & Agent SDK?

OpenAI has been a number one options supplier within the GenAI house. From the legendary ChatGPT to Sora, it’s a go-to platform for all of the working professionals on the market. With Qwen and Claude gaining reputation amongst builders, OpenAI is again once more with its newest updates, empowering builders to create extra dependable and succesful AI brokers. The main highlights from the listing embrace the Responses API and Brokers SDK. On this weblog, we’ll discover the Responses API and Brokers SDK, perceive learn how to entry them, and discover ways to use them to construct real-world functions!

What’s the Responses API?

The Responses API is OpenAI’s latest API designed for simplifying the method of constructing AI-based functions. It combines the simplicity of the Chat Completions API with the highly effective tool-use capabilities of the Assistants API. This implies builders can now create brokers that leverage a number of instruments and deal with advanced, multi-step duties extra effectively. This API lowered the reliance on advanced immediate engineering and exterior integrations.  

Key Options of the Responses API

  • Constructed-in instruments like internet search, file search, and laptop use, permitting brokers to work together with real-world information.
  • Unified design that simplifies polymorphism and improves usability.
  • Higher observability, serving to builders observe agent habits and optimize workflows.
  • No further prices, as it’s charged based mostly on token utilization at OpenAI’s customary pricing.

With these instruments, Responses API is a sport changer in the direction of constructing AI brokers. Infact, going ahead, Responses API will help all of OpenAI’s new and upcoming fashions. Let’s see how we will use it to construct functions.

The best way to use Responses API?

To strive Responses API:

  1. Set up openai (if not already put in) and use OpenAI.
  2. Guarantee you could have the newest OpenAI library(pip set up openai – -upgrade).
  3. Import OpenAI and Set Up the Shopper.

As soon as arrange, you’ll be able to request the Responses API. Whereas primary API calls are frequent, its built-in capabilities make it highly effective. Let’s discover three key options:

  • File Search: Retrieve insights from paperwork.
  • Net Search: Get real-time, cited info.
  • Laptop Use: Automate system interactions.

Now, let’s see them in motion!

It allows fashions to retrieve info in a data base of beforehand uploaded recordsdata by semantic and key phrase search. At the moment it doesn’t help csv recordsdata, you’ll be able to test the listing of supported file varieties right here.

Observe: Earlier than utilizing the file search, be certain that to retailer your recordsdata in a vector database

Job: Names of individuals with area as Information Science. (I used the next File.)

Code:

response = consumer.responses.create(

    mannequin="gpt-4o-mini",

    enter="Names of individuals with area as Information Science",

    instruments=[{

        "type": "file_search",

        "vector_store_ids": [vector_store_id],

        "filters": {

            "sort": "eq",

            "key": "Area",

            "worth": "Information Science"

        }

    }]

)

print(response.output_text)

Output:

The individual with the area of Information Science is Alice Johnson [0].
[0] names_and_domains.pdf

This characteristic permits fashions to go looking the net for the newest info earlier than producing a response, guaranteeing that the information stays updated. The mannequin can select to go looking the net or not based mostly on the content material of the enter immediate.

Job : What are one of the best cafes in Vijay nagar?

Code:

response = consumer.responses.create(

    mannequin="gpt-4o",

    instruments=[{

        "type": "web_search_preview",

        "user_location": {

            "type": "approximate",

            "country": "IN",

            "city": "Indore",

            "region": "Madhya Pradesh",

        }

    }],

    enter="What are one of the best cafe in Vijay nagar?",

)

print(response.output_text)

Output:

The best way to Use OpenAI’s Responses API & Agent SDK?

3. Laptop Use

It’s a sensible utility of Laptop-using Agent(CUA) Mannequin, which mixes the imaginative and prescient capabilities of GPT-4o with superior reasoning to simulate controlling laptop interfaces and carry out duties.

Job: Verify the newest weblog on Analytics Vidhya web site.

Code:

response = consumer.responses.create(

    mannequin="computer-use-preview",

    instruments=[{

        "type": "computer_use_preview",

        "display_width": 1024,

        "display_height": 768,

        "environment": "browser" # other possible values: "mac", "windows", "ubuntu"

    }],

    enter=[

        {

            "role": "user",

            "content": "Check the latest blog on Analytics Vidhya website."

        }

    ],

    truncation="auto"

)

print(response.output)

Output:

ResponseComputerToolCall(id='cu_67d147af346c8192b78719dd0e22856964fbb87c6a42e96', 
motion=ActionScreenshot(sort="screenshot"),
call_id='call_a0w16G1BNEk09aYIV25vdkxY', pending_safety_checks=[],
standing="accomplished", sort="computer_call")

How is the Responses API Completely different from the Completions API?

Now that we have now seen how the Responses API works, let’s see how totally different it’s from the pre-existing Completions API.

Responses API vs Completions API: Execution

API  Responses API  Completions API
Code
from openai import OpenAI
consumer = OpenAI()
response = consumer.responses.create(
    mannequin="gpt-4o",
    inputs=[
        {
            "role": "user",
            "content": "Write a one-sentence bedtime story about a unicorn."
        }
    ]
)
print(response.output_text)
from openai import OpenAI
consumer = OpenAI()
completion = consumer.chat.completions.create(
    mannequin="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": "Write a one-sentence bedtime story about a unicorn."
        }
    ]
)
print(completion.selections[0].message.content material)
Output


Responses API vs Completions API: Options

Here’s a simplified breakdown of the assorted options of Chat Complerions APi and Responses API:

Capabilities Responses API Chat Completions API
Textual content technology
Audio Coming quickly
Imaginative and prescient
Net search
File search
Laptop use
Code interpreter Coming quickly
Response Dealing with Returns a single structured output Returns selections array
Dialog State previous_response_id for continuity Should be manually managed
Storage Habits Saved by default (retailer: false to disable) Saved by default

Roadmap: What Will Proceed, What Will Deprecate?

With Responses API going stay, the burning query now could be, would it not have an effect on the present Chat Completions and Assistant API? Sure it might. Let’s have a look at how:

  • Chat Completions API: OpenAI will proceed updating it with new fashions, however solely when the capabilities don’t require built-in instruments.
  • Net Search & File Search Instruments: These will develop into extra refined and highly effective within the Responses API.
  • Assistants API: The Responses API incorporates its finest options whereas enhancing efficiency. OpenAI has introduced that full characteristic parity is coming quickly, and the Assistants API might be deprecated by mid-2026.

Introducing the Brokers SDK

Constructing AI brokers is not only about having a strong API—it requires environment friendly orchestration. That is the place OpenAI’s Brokers SDK comes into play. The Brokers SDK is an open-source toolkit that simplifies agent workflows. This agent constructing framework integrates seamlessly with the Responses API and Chat Completions API. Moreover, it’s also suitable with fashions from varied suppliers, supplied they provide an API endpoint styled like Chat Completions.

Among the key options of Brokers SDK are:

  • It permits builders to configure AI brokers with built-in instruments.
  • It allows multi-agent orchestration, permitting seamless coordination of various brokers as wanted.
  • It permits us to trace the dialog & the movement of knowledge between our brokers.
  • It permits a neater solution to apply guardrails for security and compliance.
  • It ensures that builders can monitor and optimize agent efficiency with built-in observability instruments.

Agent SDK isn’t a “new addition” to OpenAI’s jewels. It’s an improved model of “Swarm”, the experimental SDK that OpenAI had launched final 12 months. Whereas “Swarm” was simply launched for academic functions, it grew to become widespread amongst builders and was adopted by a number of enterprises too. To cater to extra enterprises and assist them construct production-grade brokers seamlessly, Brokers SDK has been launched. Now that we all know what Brokers SDK has to supply, let’s see how we will use this framework to construct our agentic system.

Additionally Learn: Prime 10 Generative AI Coding Extensions in VS Code

Construct a Multi-agentic System utilizing Agent SDK

We’ll construct a multi-agent system that helps customers with automotive suggestions and resale worth estimation by leveraging LLM-powered brokers and internet search instruments to offer correct and up-to-date insights.

Step 1: Constructing a Easy AI Agent

We start by making a Automobile Advisor Agent that helps customers select an acceptable automotive sort based mostly on their wants.

Code:

car_advisor = Agent(

    identify="Automobile advisor",

    directions= "You might be an knowledgeable in advising appropriate automotive sort like sedan, hatchback and many others to folks based mostly on their necessities.",

    mannequin="gpt-4o",

    )

immediate = "I'm in search of a automotive that I take pleasure in driving and comforatbly take 4 folks. I aircraft to journey to hills. What sort of automotive ought to I purchase?"

async def essential():

    outcome = await Runner.run(car_advisor, immediate)

    print(outcome.final_output)

# Run the operate in Jupyter

await essential()

Output:

Building a Simple AI Agent

Step 2: Construct the Multi-Agent System

With the essential agent in place, we now create a multi-agent system incorporating totally different AI brokers specialised of their respective domains. Right here’s the way it works:

Brokers within the Multi-Agent System

  1. Automobile Promote Estimate Agent: It offers a resale worth estimate based mostly on automotive particulars.
  2. Automobile Mannequin Advisor Agent: It suggests appropriate automotive fashions based mostly on finances and placement.
  3. Triage Agent: It directs the question to the suitable agent.

We’ll present two totally different prompts to the brokers and observe their outputs.

Code:

car_sell_estimate = Agent(

    identify="Automobile promote estimate",

    directions= "You might be an knowledgeable in suggesting an acceptable worth of reselling a automotive based mostly on its make, mannequin, 12 months of buy, and situation.",

    handoff_description= "Automobile reselling worth estimate knowledgeable",

    mannequin="gpt-4o",

    instruments=[WebSearchTool()]

    )

car_model_advisor = Agent(

    identify="Automobile mannequin advisor",

    directions= "You might be an knowledgeable in advising appropriate automotive mannequin to folks based mostly on their finances and placement.",

    handoff_description= "Automobile mannequin suggestion knowledgeable",

    mannequin="gpt-4o",

    instruments=[WebSearchTool()]

    )

triage_agent = Agent(

    identify = "Triage Agent",

    directions="You establish the suitable agent for the duty.",

    mannequin = "gpt-4o",

    handoffs=[car_sell_estimate, car_model_advisor]

)

Immediate 1: 

immediate = "I need to promote my Ecosport automotive in New Delhi. It's 3 years outdated and in good situation. 50000Km. What worth ought to I count on?"

async def essential():

    outcome = await Runner.run(triage_agent, immediate)

    print(outcome.final_output)

# Run the operate in Jupyter

await essential()

Output 1:

SDK Output 1

Immediate 2:

immediate = "I need to purchase a excessive acceleration automotive, snug for 4 folks for 20 lakhs in New Delhi. Which automotive ought to I purchase?"

async def essential():

    outcome = await Runner.run(triage_agent, immediate)

    print(outcome.final_output)

# Run the operate in Jupyter

await essential()

Output 2:

We acquired the automotive choices as per our necessities! The implementation was easy and fast. You should use this agentic framework to construct brokers for journey help, monetary planning, medical help, personalised procuring, automated analysis, and way more.

Agent’s SDK: A New Agentic Framework in City?

OpenAI’s Brokers SDK represents its strategic push towards offering a devoted framework for AI agent growth. The framework contains crew-like options by its triage agent, mimicking Crew AI’s options. Equally, its handoff mechanisms intently resemble these of AutoGen, permitting environment friendly delegation of duties amongst a number of brokers.

Moreover, LangChain’s energy in modular agent orchestration is mirrored in the best way the Brokers SDK offers structured workflows, guaranteeing easy execution and adaptableness. Whereas Brokers SDK provides nothing greater than what the present frameworks already do, it quickly will give them a troublesome competitors. 

Additionally Learn: Claude 3.7 Sonnet: The Finest Coding Mannequin But?

Why Do Builders Want Responses API & Brokers SDK?

Responses API and Brokers SDK present builders with the instruments & platform to construct AI-driven functions. By decreasing the reliance on handbook immediate engineering and in depth customized logic, these instruments permit builders to give attention to creating clever workflows with minimal friction.

  • Simple Integration: Builders not must juggle a number of APIs for various instruments; the Responses API consolidates internet search, file search, and laptop use right into a single interface.
  • Higher Observability: With built-in monitoring and debugging instruments, builders can optimize agent efficiency extra simply.
  • Scalability: The Brokers SDK offers a structured method to dealing with multi-agent workflows, enabling extra strong automation.
  • Improved Improvement Cycles: By eliminating the necessity for in depth immediate iteration and exterior software integration, builders can prototype and deploy agent-based functions at a a lot sooner tempo.

Conclusion

The introduction of OpenAI’s Responses API and Brokers SDK is a game-changer for AI-driven automation. By leveraging these instruments, we efficiently constructed a multi-agent system in a short time with only a few traces of code. This implementation will be additional expanded to incorporate further instruments, integrations, and agent capabilities, paving the best way for extra clever and autonomous AI functions in varied industries.

These instruments are certainly going to assist builders and enterprises scale back growth complexity, and create smarter, extra scalable automation options. Whether or not it’s for buyer help, analysis, enterprise automation, or industry-specific AI functions, the Responses API and Brokers SDK supply a strong framework to construct next-generation AI-powered methods with ease.

Regularly Requested Questions

Q1. What’s OpenAI’s Responses API?

A. The Responses API is OpenAI’s newest AI framework that simplifies agent growth by integrating built-in instruments like internet search, file search, and laptop use.

Q2. How is the Responses API totally different from the Completions API?

A. Not like the Completions API, the Responses API helps multi-tool integration, structured outputs, and built-in dialog state administration.

Q3. What’s OpenAI’s Brokers SDK?

A. The Brokers SDK is an open-source framework that permits builders to construct and orchestrate multi-agent methods with AI-powered automation.

This autumn. How does the Brokers SDK enhance AI growth?

A. It permits seamless agent coordination, enhanced observability, built-in guardrails, and improved efficiency monitoring.

Q5. Can the Responses API and Brokers SDK be used collectively?

A. Sure! The Brokers SDK integrates with the Responses API to create highly effective AI-driven functions.

Q6. Is OpenAI’s Brokers SDK suitable with different AI fashions?

A. Sure, it may well work with third-party fashions that help Chat Completions API-style integrations.

Q7. What industries can profit from multi-agent AI methods?

A. Industries like automotive, finance, healthcare, buyer help, and analysis can use AI-driven brokers to optimize operations and decision-making.

Anu Madan has 5+ years of expertise in content material creation and administration. Having labored as a content material creator, reviewer, and supervisor, she has created a number of programs and blogs. At the moment, she engaged on creating and strategizing the content material curation and design round Generative AI and different upcoming expertise.

Login to proceed studying and revel in expert-curated content material.