We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience and analyze website traffic…

DeepInfra raises $107M Series B to scale the inference cloud — read the announcement

Introducing Tool Calling with LangChain, Search the Web with Tavily and Tool Calling Agents
Published on 2024.07.05 by Oguz Vuruskaner
Introducing Tool Calling with LangChain, Search the Web with Tavily and Tool Calling Agents

In this blog post, we will query for the details of a recently released expansion pack for Elden Ring, a critically acclaimed game released in 2022, using the Tavily tool with the ChatDeepInfra model.

Using this boilerplate, one can automate the process of searching for information with well-written responses. This is a great way to create a chatbot that can interact with users and provide them with the information they need.

Requirements

  • Python 3.8 or higher
  • DeepInfra API Key
  • Tavily API Key

Installation

First, let's create a virtual environment and activate it:

python3 -m venv venv
source venv/bin/activate
copy

Next, install the required packages:

pip install python-dotenv langchain langchain-community
copy

Setting Up the Environment

Before we start, we need to load our DeepInfra API key and Tavily API key. You can get your DeepInfra API key from here. After obtaining the API key, create a .env file in the root directory of your project and add the following line:

DEEPINFRA_API_TOKEN=YOUR_DEEPINFRA_API_KEY
TAVILY_API_KEY=YOUR_TAVILY_API_KEY
copy

Creating a Tool Calling Agent

After installing the required packages and setting up the environment, we can create a LangChain agent that uses the ChatDeepInfra model and the Tavily tool to search for information on the web. The ChatDeepInfra model is a powerful conversational model that can generate human-like responses to user queries. The Tavily tool allows us to search the web for information and retrieve the search results.

Here's the complete Python script to create and run a LangChain agent using the ChatDeepInfra model:

from dotenv import load_dotenv, find_dotenv
from langchain_community.chat_models import ChatDeepInfra

_ = load_dotenv(find_dotenv())

from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.prompts import ChatPromptTemplate

model_name = "meta-llama/Meta-Llama-3-70B-Instruct"

if __name__ == "__main__":

    tools = [TavilySearchResults(max_results=1)]
    llm = ChatDeepInfra(
        model = model_name
    )
    prompt = ChatPromptTemplate.from_messages(
        [
            (
                "system",
                "You are a helpful assistant. Make sure to use the tavily_search_results_json tool for information.",
            ),
            ("placeholder", "{chat_history}"),
            ("human", "{input}"),
            ("placeholder", "{agent_scratchpad}"),
        ]
    )

    agent = create_tool_calling_agent(llm, tools, prompt)

    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, stream_runnable=False)
    question = "Why is the hype for Shadow of the Erdtree so high?"
    result = agent_executor.invoke({"input": question})

    print(result["output"])

    # According to the search results, the new DLC for Elden Ring is called "Shadow of the Erdtree".
copy

One crucial point is to use stream_runnable=False in the AgentExecutor.

Conclusion

Stage is yours now! You can futher extend the agent to include more tools and models to improve your workflows which will be topic for another blog post.

Stay tuned for more updates and happy coding!

Related articles
Qwen API Pricing Guide 2026: Max Performance on a BudgetQwen API Pricing Guide 2026: Max Performance on a Budget<p>If you have been following the AI leaderboards lately, you have likely noticed a new name constantly trading blows with GPT-4o and Claude 3.5 Sonnet: Qwen. Developed by Alibaba Cloud, the Qwen model family (specifically Qwen 2.5 and Qwen 3) has exploded in popularity for one simple reason: unbeatable price-to-performance. In 2025, Qwen is widely [&hellip;]</p>
Open-Source vs Closed-Source AI Models: Is the Gap Worth It?Open-Source vs Closed-Source AI Models: Is the Gap Worth It?<p>The Artificial Analysis Intelligence Index sits at a ceiling of 57. Three frontier models — Claude Opus 4.7, Gemini 3.1 Pro Preview, and GPT-5.5 — all land in that band. Meanwhile, four open-weight models released between February and April 2026 now score 50 or above on the same index. A year ago, the best open-weight [&hellip;]</p>
GLM-5.2 Model Overview and Integration GuideGLM-5.2 Model Overview and Integration Guide<p>GLM-5.2 is Z.AI&#8217;s flagship open-source large language model, engineered for long-horizon coding, agentic, and reasoning tasks. Designed for complex reasoning, advanced software engineering, and large-scale data processing, GLM-5.2 introduces a massive 1,048,576-token context window alongside significant architectural innovations. Hosted on the DeepInfra platform, GLM-5.2 provides developers with a high-performance, OpenAI-compatible interface. Whether you are building [&hellip;]</p>