Defining the Tool
First, install or import the required packages:@tool decorator from LangChain:
The
@tool decorator registers the function’s name, description, and argument schema automatically.Inspecting Tool Metadata
After definingGetFlightStatus, you can verify its registered metadata:
StructuredTool representation:
Using the Tool in a Chain
Next, we’ll connect the tool to a prompt template, the OpenAI LLM, and a simple output parser:Invoking the Chain
With the chain ready, invoke it to extract specific details:You now have a reusable flight status tool. Integrate real-world APIs inside
GetFlightStatus to fetch live data, and combine multiple tools to build sophisticated LangChain agents.