Tool usage lets an AI assistant obtain information or take actions through external functions, APIs, and services. It raises the stakes: a mistaken weather answer is inconvenient, while a mistaken booking or database deletion can cause lasting harm. Multi-step workflows also compound errors, so a successful tool call is not the same as a reliable end-to-end agent. section 1.4.2 section 2.9
For information retrieval, separate language understanding from factual lookup. The model identifies that it needs data and requests a function call; application code executes the function and returns its result; the model then writes a response using that result. A weather assistant can therefore answer from current API data rather than inventing conditions from its training data. This reduces hallucination risk but still depends on choosing an authoritative source and handling failures. section 2.8 section 2.8.3
A practical integration has three parts:
- Define a function and describe its parameters with a JSON schema so the model can request a structured call. section 2.8.3
- Inspect returned tool calls, execute the requested function in application code, and append each result to the conversation with its tool-call ID. section 2.8.3
- Request a final response after supplying the result; for agents that act across services, add consistent error handling, traceability, and failure containment. section 2.8.3 section 1.4.2
Current weather
A user asks whether it is raining in Seattle. The assistant requests current conditions through a weather function, receives the result, and answers that it is 10°C and raining. The model handles the question and phrasing; the external service supplies the weather facts. section 2.8.3
const tools = [
new DynamicTool({
name: "travel_knowledge",
description: "Useful for answering questions about travel destinations,
landmarks, and tourist attractions",
func: async (input: string) => {
const result = await retrievalChain.run(input); #1
return result;
},
}),
new DynamicTool({
name: "weather_service",
description: "Get the current weather conditions for a specific location
or city",
func: async (location: string) => {
return await getWeather(location); #2
},
}),
];
Two named tools show how an agent can route destination questions to a retrieval chain and current-weather questions to a weather service. Their descriptions make the intended use of each tool explicit. section 6.3.4












