Tools
A model cannot safely read your customer database, order system, or private business state by itself. Tools solve this boundary: the Agent can request an application-owned function while your service keeps data access, authorization, and side effects under its control.
- Python
- TypeScript
from agents import function_tool, Runner
from iztro_agents import ChatSession, iztro_ziwei_agent
@function_tool
def lookup_customer(customer_id: str) -> str:
return "Customer is on the annual plan."
agent = iztro_ziwei_agent(tools=[lookup_customer])
session = ChatSession(external_user_id="user_42")
result = await Runner.run(agent, "Use my customer profile when answering.", session=session)
import {tool, run} from '@openai/agents';
import {ChatSession, iztroZiweiAgent} from 'openai-iztro-agents';
const lookupCustomer = tool({
name: 'lookup_customer',
description: 'Read a customer record from your service',
parameters: {type: 'object', properties: {customerId: {type: 'string'}}, required: ['customerId']},
execute: async ({customerId}: {customerId: string}) => `${customerId} is on the annual plan.`,
});
const agent = iztroZiweiAgent({tools: [lookupCustomer]});
const session = new ChatSession({externalUserId: 'user_42'});
await run(agent, 'Use my customer profile when answering.', {session});
Real example: 07_multi_step_booking.py
This example uses two local tools in sequence: check calendar availability, then book only if the selected date is free. The Chinese and English recorded outputs are shown inline below.
Source: examples/07_multi_step_booking.py.
Prompt used for this run
I was born on 1990-12-21 at 13:00, female. Find one auspicious weekday next week for an important meeting, check my calendar first, and book it if it is free.
Complete recorded output
Loading recorded output…