Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • New tiny nudibranch species discovered in Taiwan
    • Why the Budget’s CGT changes are a disaster for angel investors and startups
    • OpenAI and Anthropic Sign Letter to Prevent AI-Developed Biological Weapons
    • New York sports betting statements bill advances
    • SwitchBot Launches the Most Complete Home Weather Station I’ve Seen
    • What It Takes for Future-Ready Power Distribution
    • Are we safe from this deadly virus?
    • Edinburgh-based Wordsmith raises €60.2 million Series B to scale legal AI platform for in-house teams
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Thursday, June 4
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»Hands‑On with Agents SDK: Your First API‑Calling Agent
    Artificial Intelligence

    Hands‑On with Agents SDK: Your First API‑Calling Agent

    Editor Times FeaturedBy Editor Times FeaturedJuly 22, 2025No Comments17 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    round LLMs is now evolving into the hype of Agentic AI. Whereas I hope this text doesn’t fall into an “over‑hyped” class, I personally imagine this subject is vital to study. Coming from a knowledge and analytics background, I discover that getting aware of it may be very useful in day‑to‑day work and to organize for the way it may probably reshape present processes.

    My very own journey with Agentic AI continues to be fairly new (in spite of everything, it’s a comparatively new subject), and I’m nonetheless studying alongside the best way. On this collection of articles, I’d prefer to share a newbie‑pleasant, step‑by‑step information to growing Agentic AI primarily based on my private expertise—specializing in the OpenAI Brokers SDK framework. Some subjects I plan to cowl on this collection embrace: device‑use brokers, multi‑agent collaboration, structured output, producing knowledge visualizations, chat options, and extra. So keep tuned!

    On this article, we’ll begin by constructing a fundamental agent after which improve it right into a device‑utilizing agent able to retrieving knowledge from an API. Lastly, we’ll wrap every little thing in a easy Streamlit UI so customers can work together with the agent we construct.

    All through this information, we’ll keep on with a single use case: making a climate assistant app. I selected this instance as a result of it’s relatable for everybody and covers a lot of the subjects I plan to share. For the reason that use case is easy and generic, you’ll be able to simply adapt this information in your personal initiatives.

    The hyperlink to the GitHub repository and the deployed Streamlit app is supplied on the finish of this text.

    A Temporary Intro to OpenAI Brokers SDK

    The OpenAI Brokers SDK is a Python-based framework that enables us to create an agentic AI system in a easy and easy-to-use means [1]. As a newbie myself, I discovered this assertion to be fairly true, which makes the educational journey really feel much less intimidating.

    On the core of this framework are “Brokers”—Massive Language Fashions (LLMs) that we will configure with particular directions and instruments they will use.

    As we already know, an LLM is educated on an enormous quantity of knowledge, giving it robust capabilities in understanding human language and producing textual content or photos. When mixed with clear directions and the power to work together with instruments, it turns into greater than only a generator—it could actually act and turns into an agent [2].

    One sensible use of instruments is enabling an agent to retrieve factual knowledge from exterior sources. This implies the LLM now not depends solely on its (typically outdated) coaching knowledge, permitting it to provide extra correct and up‑to‑date outcomes.

    On this article, we’ll concentrate on this benefit by constructing an agent that may retrieve “actual‑time” knowledge from an API. Let’s get began!

    Set Up the Atmosphere

    Create a necessities.txt file containing the next two vital packages. I want utilizing necessities.txt for 2 causes: reusability and making ready the undertaking for Streamlit deployment.

    openai-agents
    streamlit

    Subsequent, arrange a digital atmosphere named venv and set up the packages listed above. Run the next instructions in your terminal:

    python −m venv venv
    supply venv/bin/activate      # On Home windows: venvScriptsactivate
    pip set up -r necessities.txt

    Lastly, since we’ll use the OpenAI API to name the LLM, you could have an API key (get your API key here). Retailer this key in a .env file as follows. Necessary: be sure to add .env to your .gitignore file if you’re utilizing Git for this undertaking.

    OPENAI_API_KEY=your_openai_key_here

    As soon as every little thing is ready up, you’re good to go!

    A Easy Agent

    Let’s start with a easy agent by making a Python file referred to as 01-single-agent.py.

    Import Libraries

    The very first thing we have to do within the script is import the mandatory libraries:

    from brokers import Agent, Runner
    import asyncio
    
    from dotenv import load_dotenv
    load_dotenv()

    From the Brokers SDK bundle, we use Agent to outline the agent and Runner to run it. We additionally import asyncio to allow our program to carry out a number of duties with out ready for one to complete earlier than beginning one other.

    Lastly, load_dotenv from the dotenv bundle hundreds the atmosphere variables we outlined earlier within the .env file. In our case, this contains OPENAI_API_KEY, which will probably be utilized by default once we outline and name an agent.

    Outline a Easy Agent

    Construction of Climate Assistant Agent.
    Generated utilizing GraphViz.

    Subsequent, we’ll outline a easy agent referred to as Climate Assistant.

    agent = Agent(
        identify="Climate Assistant",
        directions="You present correct and concise climate updates primarily based on consumer queries in plain language."
    )

    An agent will be outlined with a number of properties. On this easy instance, we solely configure the identify and the directions for the agent. If wanted, we will additionally specify which LLM mannequin to make use of. For example, if we wish to use a smaller mannequin equivalent to gpt-4o-mini (at the moment, the default mannequin is gpt-4o), we will add the configuration as proven under.

    agent = Agent(
        identify="Climate Assistant",
        directions="You present correct and concise climate updates primarily based on consumer queries in plain language.",
        mannequin="gpt-4o-mini"
    )

    There are a number of different parameters that we are going to cowl later on this article and within the subsequent one. For now, we’ll maintain the mannequin configuration easy as proven above.

    After defining the agent, the subsequent step is to create an asynchronous perform that may run the agent.

    async def run_agent():
        outcome = await Runner.run(agent, "What is the climate like as we speak in Jakarta?")
        print(outcome.final_output)

    The Runner.run(agent, ...) technique calls the agent with the question “What’s the climate like as we speak in Jakarta?”. The await key phrase pauses the perform till the duty is full, permitting different asynchronous duties (if any) to run within the meantime. The results of this job is saved within the outcome variable. To view the output, we print outcome.final_output to the terminal.

    The final half we have to add is this system’s entry level to execute the perform when the script runs. We use asyncio.run to execute the run_agent perform.

    if __name__ == "__main__":
        asyncio.run(run_agent())

    Run the Easy Agent

    Now, let’s run the script within the terminal by executing:

    python 01-single-agent.py

    The outcome will most certainly be that the agent says it can not present the data. That is anticipated as a result of the LLM was educated on previous knowledge and doesn’t have entry to real-time climate circumstances.

    I can’t present real-time data, however you’ll be able to test a dependable climate web site or app for the most recent updates on Jakarta’s climate as we speak.

    Within the worst case, the agent may hallucinate by returning a random temperature and giving recommendations primarily based on that worth. To deal with this case, we’ll later implement the agent to name an API to retrieve the precise climate circumstances.

    Utilizing Hint

    One of many helpful options of the Brokers SDK is Hint, which lets you visualize, debug, and monitor the workflow of the agent you’ve constructed and executed. You possibly can entry the tracing dashboard right here: https://platform.openai.com/traces.

    For our easy agent, the hint will appear to be this:

    Example of a trace dashboard
    Screenshot of Hint Dashboard.

    On this dashboard, yow will discover helpful details about how the workflow is executed, together with the enter and output of every step. Since it is a easy agent, we solely have one agent run. Nonetheless, because the workflow turns into extra complicated, this hint characteristic will probably be extraordinarily useful for monitoring and troubleshooting the method.

    Consumer Interface with Streamlit

    Beforehand, we constructed a easy script to outline and name an agent. Now, let’s make it extra interactive by including a consumer interface with Streamlit [3].

    Let’s create a script named 02-single-agent-app.py as proven under:

    from brokers import Agent, Runner
    import asyncio
    import streamlit as st
    from dotenv import load_dotenv
    
    load_dotenv()
    
    agent = Agent(
        identify="Climate Assistant",
        directions="You present correct and concise climate updates primarily based on consumer queries in plain language."
    )
    
    async def run_agent(user_input: str):
        outcome = await Runner.run(agent, user_input)
        return outcome.final_output
    
    def major():
        st.title("Climate Assistant")
        user_input = st.text_input("Ask in regards to the climate:")
        
        if st.button("Get Climate Replace"):
            with st.spinner("Considering..."):
                if user_input:
                    agent_response = asyncio.run(run_agent(user_input))
                    st.write(agent_response)
                else:
                    st.write("Please enter a query in regards to the climate.")
    
    if __name__ == "__main__":
        major()

    In comparison with the earlier script, we now import the Streamlit library to construct an interactive app. The agent definition stays the identical, however we modify the run_agent perform to just accept consumer enter and move it to the Runner.run perform. As a substitute of printing the outcome on to the console, the perform now returns the outcome.

    Within the major perform, we use Streamlit parts to construct the interface: setting the title, including a textual content field for consumer enter, and making a button that triggers the run_agent perform.

    The agent’s response is saved in agent_response and displayed utilizing the st.write part. To run this Streamlit app in your browser, use the next command:

    streamlit run 02-single-agent-app.py
    Screenshot for single agent app utilizing Streamlit

    To cease the app, press Ctrl + C in your terminal.

    To maintain the article centered on the Brokers SDK framework, I stored the Streamlit app so simple as attainable. Nonetheless, that doesn’t imply you could cease right here. Streamlit presents all kinds of parts that permit you to get inventive and make your app extra intuitive and interesting. For a whole record of parts, test the Streamlit documentation within the reference part.

    From this level onward, we’ll proceed utilizing this fundamental Streamlit construction.

    A Software-Use Agent

    As we noticed within the earlier part, the agent struggles when requested in regards to the present climate situation. It could return no data or, worse, produce a hallucinated reply. To make sure our agent makes use of actual knowledge, we will enable it to name an exterior API so it could actually retrieve precise data.

    This course of is a sensible instance of utilizing Instruments within the Brokers SDK. Normally, instruments allow an agent to take actions—equivalent to fetching knowledge, operating code, calling an API (as we’ll do shortly), and even interacting with a pc [1]. Utilizing instruments and taking actions is likely one of the key capabilities that distinguishes an agent from a typical LLM.

    Let’s dive into the code. First, create one other file named 03-tooluse-agent-app.py.

    Import Libraries

    We are going to want the next libraries:

    from brokers import Agent, Runner, function_tool
    import asyncio
    import streamlit as st
    from dotenv import load_dotenv
    import requests
    
    load_dotenv()

    Discover that from the Brokers SDK, we now import an extra module: function_tool. Since we’ll name an exterior API, we additionally import the requests library.

    Outline the Perform Software

    The API we’ll use is Open‑Meteo [4], which presents free entry for non‑industrial use. It gives many options, together with climate forecasts, historic knowledge, air high quality, and extra. On this article, we’ll begin with the only characteristic: retrieving present climate knowledge.

    As an extra be aware, Open‑Meteo gives its personal library, openmeteo‑requests. Nonetheless, on this information I take advantage of a extra generic method with the requests module, with the intention of constructing the code reusable for different functions and APIs.

    Right here is how we will outline a perform to retrieve the present climate for a selected location utilizing Open-Meteo:

    @function_tool
    def get_current_weather(latitude: float, longitude: float) -> dict:
        """
        Fetches present climate knowledge for a given location utilizing the Open-Meteo API.
    
        Args:
            latitude (float): The latitude of the situation.
            longitude (float): The longitude of the situation.
    
        Returns:
            dict: A dictionary containing the climate knowledge, or an error message if the request fails.
        """
        attempt:
            url = "https://api.open-meteo.com/v1/forecast"
            params = {
                "latitude": latitude,
                "longitude": longitude,
                "present": "temperature_2m,relative_humidity_2m,dew_point_2m,apparent_temperature,precipitation,weathercode,windspeed_10m,winddirection_10m",
                "timezone": "auto"
            }
            response = requests.get(url, params=params)
            response.raise_for_status()  # Elevate an error for HTTP points
            return response.json()
        besides requests.RequestException as e:
            return {"error": f"Didn't fetch climate knowledge: {e}"}

    The perform takes latitude and longitude as inputs to determine the situation and assemble an API request. The parameters embrace metrics equivalent to temperature, humidity, and wind pace. If the API request succeeds, it returns the JSON response as a Python dictionary. If an error happens, it returns an error message as a substitute.

    To make the perform accessible to the agent, we embellish it with @function_tool, permitting the agent to name it when the consumer’s question is expounded to present climate knowledge.

    Moreover, we embrace a docstring within the perform, offering each an outline of its objective and particulars of its arguments. Together with a docstring is extraordinarily useful for the agent to know use the perform.

    Outline a Software-Use Agent

    Construction of Climate Specialist Agent, a toll-use agent.
    Generated utilizing GraphViz.

    After defining the perform, let’s transfer on to defining the agent.

    weather_specialist_agent = Agent(
        identify="Climate Specialist Agent",
        directions="You present correct and concise climate updates primarily based on consumer queries in plain language.",
        instruments=[get_current_weather],
        tool_use_behavior="run_llm_again"
    )
    
    async def run_agent(user_input: str):
        outcome = await Runner.run(weather_specialist_agent, user_input)
        return outcome.final_output

    For probably the most half, the construction is similar as within the earlier part. Nonetheless, since we are actually utilizing instruments, we have to add some further parameters.

    The primary is instruments, which is a listing of instruments the agent can use. On this instance, we solely present the get_current_weather device. The following is tool_use_behavior, which configures how device utilization is dealt with. For this agent, we set it to "run_llm_again", which implies that after receiving the response from the API, the LLM will course of it additional and current it in a transparent, easy-to-read format. Alternatively, you should use "stop_on_first_tool", the place the LLM is not going to course of the device’s output additional. We are going to experiment with this selection later.

    The remainder of the script follows the identical construction we used earlier to construct the primary Streamlit perform.

    def major():
        st.title("Climate Assistant")
        user_input = st.text_input("Ask in regards to the climate:")
        
        if st.button("Get Climate Replace"):
            with st.spinner("Considering..."):
                if user_input:
                    agent_response = asyncio.run(run_agent(user_input))
                    st.write(agent_response)
                else:
                    st.write("Please enter a query in regards to the climate.")
    
    if __name__ == "__main__":
        major()

    Ensure to avoid wasting the script, then run it within the terminal:

    streamlit run 03-tooluse-agent-app.py

    Now you can ask a query in regards to the climate in your metropolis. For instance, after I requested in regards to the present climate in Jakarta—on the time of penning this (round 4 o’clock within the morning)—the response was as proven under:

    Example of agent response for Jakarta weather
    Screenshot for tool-use agent app utilizing Streamlit

    Now, as a substitute of hallucinating, the agent can present a human‑readable present climate situation for Jakarta. You may recall that the get_current_weather perform requires latitude and longitude as arguments. On this case, we depend on the LLM to produce them, as it’s possible educated with fundamental location data. A future enchancment can be so as to add a device that retrieves a extra correct geographical location primarily based on a metropolis identify.

    (Non-compulsory) Use “stop_on_first_tool”

    Out of curiosity, let’s attempt altering the tool_use_behavior parameter to "stop_on_first_tool" and see what it returns.

    Example output when using stop_on_first_tool
    Screenshot for tool-use agent app with stop_on_first_tool choice utilizing Streamlit

    As anticipated, with out the LLM’s assist to parse and rework the JSON response, the output is more durable to learn. Nonetheless, this conduct will be helpful in eventualities the place you want a uncooked, structured outcome with none further processing by the LLM.

    Improved Instruction

    Now, let’s change the tool_use_behavior parameter again to "run_llm_again".

    As we’ve seen, utilizing an LLM may be very useful for parsing the outcome. We are able to take this a step additional by giving the agent extra detailed directions—particularly, asking for a structured output and sensible recommendations. To do that, replace the directions parameter as follows:

    directions = """
    You're a climate assistant agent.
    Given present climate knowledge (together with temperature, humidity, wind pace/path, precipitation, and climate codes), present:
    1. A transparent and concise clarification of the present climate circumstances.
    2. Sensible recommendations or precautions for outside actions, journey, well being, or clothes primarily based on the information.
    3. If any extreme climate is detected (e.g., heavy rain, thunderstorms, excessive warmth), spotlight needed security measures.
    
    Format your response in two sections:
    Climate Abstract:
    - Briefly describe the climate in plain language.
    
    Options:
    - Provide actionable recommendation related to the climate circumstances.
    """

    After saving the modifications, rerun the app. Utilizing the identical query, you must now obtain a clearer, effectively‑structured response together with sensible recommendations.

    Screenshot for tool-use agent app with an improved instruction utilizing Streamlit
    The ultimate script of 03-tooluse-agent-app.py will be seen right here.
    from brokers import Agent, Runner, function_tool
    import asyncio
    import streamlit as st
    from dotenv import load_dotenv
    import requests
    
    load_dotenv()
    
    @function_tool
    def get_current_weather(latitude: float, longitude: float) -> dict:
        """
        Fetches present climate knowledge for a given location utilizing the Open-Meteo API.
    
        Args:
            latitude (float): The latitude of the situation.
            longitude (float): The longitude of the situation.
    
        Returns:
            dict: A dictionary containing the climate knowledge or an error message if the request fails.
        """
        attempt:
            url = "https://api.open-meteo.com/v1/forecast"
            params = {
                "latitude": latitude,
                "longitude": longitude,
                "present": "temperature_2m,relative_humidity_2m,dew_point_2m,apparent_temperature,precipitation,weathercode,windspeed_10m,winddirection_10m",
                "timezone": "auto"
            }
            response = requests.get(url, params=params)
            response.raise_for_status()  # Elevate an error for HTTP points
            return response.json()
        besides requests.RequestException as e:
            return {"error": f"Didn't fetch climate knowledge: {e}"}
    
    weather_specialist_agent = Agent(
        identify="Climate Specialist Agent",
        directions="""
        You're a climate assistant agent.
        Given present climate knowledge (together with temperature, humidity, wind pace/path, precipitation, and climate codes), present:
        1. A transparent and concise clarification of the present climate circumstances.
        2. Sensible recommendations or precautions for outside actions, journey, well being, or clothes primarily based on the information.
        3. If any extreme climate is detected (e.g., heavy rain, thunderstorms, excessive warmth), spotlight needed security measures.
    
        Format your response in two sections:
        Climate Abstract:
        - Briefly describe the climate in plain language.
    
        Options:
        - Provide actionable recommendation related to the climate circumstances.
        """,
        instruments=[get_current_weather],
        tool_use_behavior="run_llm_again" # or "stop_on_first_tool"
    )
    
    async def run_agent(user_input: str):
        outcome = await Runner.run(weather_specialist_agent, user_input)
        return outcome.final_output
    
    def major():
        st.title("Climate Assistant")
        user_input = st.text_input("Ask in regards to the climate:")
        
        if st.button("Get Climate Replace"):
            with st.spinner("Considering..."):
                if user_input:
                    agent_response = asyncio.run(run_agent(user_input))
                    st.write(agent_response)
                else:
                    st.write("Please enter a query in regards to the climate.")
    
    if __name__ == "__main__":
        major()

    Conclusion

    At this level, now we have explored create a easy agent and why we want a device‑utilizing agent—one highly effective sufficient to reply particular questions on actual‑time climate circumstances {that a} easy agent can not deal with. We have now additionally constructed a easy Streamlit UI to work together with this agent.

    This primary article focuses solely on the core idea of how agentic AI can work together with a device, relatively than relying solely on its coaching knowledge to generate output.

    Within the subsequent article, we’ll shift our focus to a different vital idea of agentic AI: agent collaboration. We are going to cowl why a multi‑agent system will be more practical than a single “tremendous” agent, and discover other ways brokers can work together with one another.

    I hope this text has supplied useful insights to begin your journey into these subjects.

    References

    [1] OpenAI. (2025). OpenAI Brokers SDK documentation. Retrieved July 19, 2025, from https://openai.github.io/openai-agents-python/

    [2] Bornet, P., Wirtz, J., Davenport, T. H., De Cremer, D., Evergreen, B., Fersht, P., Gohel, R., Khiyara, S., Sund, P., & Mullakara, N. (2025). Agentic Synthetic Intelligence: Harnessing AI Brokers to Reinvent Enterprise, Work, and Life. World Scientific Publishing Co.

    [3] Streamlit Inc. (2025). Streamlit documentation. Retrieved July 19, 2025, from https://docs.streamlit.io/

    [4] Open-Meteo. Open-Meteo API documentation. Retrieved July 19, 2025, from https://open-meteo.com/en/docs


    You’ll find the whole supply code used on this article within the following repository: agentic-ai-weather | GitHub Repository. Be at liberty to discover, clone, or fork the undertaking to observe alongside or construct your personal model.

    In case you’d prefer to see the app in motion, I’ve additionally deployed it right here: Weather Assistant Streamlit

    Lastly, let’s join on LinkedIn!



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    I Built a C++ Backend So My GPU Would Stop Eating Air

    June 3, 2026

    I Spent May Evaluating Different Engines for OCR

    June 3, 2026

    Why AI Is NOT Stealing Your Job

    June 3, 2026

    What AI Agents Should Never Do on Their Own

    June 3, 2026

    Exploring Income Patterns with Python Pandas, Matplotlib, and Seaborn

    June 2, 2026

    From Local App to Public Website in Minutes

    June 2, 2026

    Comments are closed.

    Editors Picks

    New tiny nudibranch species discovered in Taiwan

    June 4, 2026

    Why the Budget’s CGT changes are a disaster for angel investors and startups

    June 4, 2026

    OpenAI and Anthropic Sign Letter to Prevent AI-Developed Biological Weapons

    June 4, 2026

    New York sports betting statements bill advances

    June 4, 2026
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    ‘Industry’ Takes on the Age Verification Wars

    January 6, 2026

    Today’s NYT Mini Crossword Answers for April 15

    April 15, 2026

    How to Build an AI-Powered Weather ETL Pipeline with Databricks and GPT-4o: From API To Dashboard

    December 26, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

    Type above and press Enter to search. Press Esc to cancel.