The provided code demonstrates how to integrate Claude, an AI assistant from Anthropic, with external tools to fetch real-time data and enhance its responses. Specifically, it shows how to query the current stock price of Apple (AAPL) by leveraging a tool called get_stock_price that interacts with an external API.
Here's a breakdown of what the code does:
-
Importing Required Libraries: The script starts by importing necessary libraries such as Anthropic for interacting with Claude and any other required packages like requests if needed for API calls.
-
Defining Tools: A list of tools is defined, where each tool has a name (
get_stock_price), description, input schema (specifying what inputs the function expects), and output schema (though not explicitly used in this example). -
User Query: The script sets up an initial user query asking for the current price of Apple stock.
-
Calling Claude with Tools: It then calls Claude's API (
client.messages.create) with the defined tools, passing along the user question as input to see how Claude responds. -
Processing Tool Use Response:
- The script checks if Claude used any tool in its response by iterating through the blocks of content returned
Read the full article at DEV Community
Want to create content about this topic? Use Nemati AI tools to generate articles, social posts, and more.

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



