Parallel & Sequential Calls
From the course AI Function Calling & Tool Use
Multi-Function Patterns
Modern AI models can call multiple functions in a single turn, enabling efficient orchestration.
Parallel Function Calls
When the model identifies independent operations, it can request them simultaneously:
// Model response might include multiple tool calls:
// 1. get_weather("Tokyo")
// 2. get_weather("London")
// 3. get_exchange_rate("JPY", "GBP")
// Execute all in parallel
const results = await Promise.all(
toolCalls.map(call => executeFunction(call.name, call.arguments))
);
Sequential Chains
Some operations depend on previous results:
User: "Book a flight from NYC to the cheapest warm destination"
→ Call 1: search_warm_destinations() → ["Cancún", "Miami", "Bahamas"]
→ Call 2: search_flights("NYC", "Cancún") → $350
→ Call 3: book_flight("NYC", "Cancún", $350) → Confirmation
Provider Differences
| Feature | OpenAI | Claude | Gemini |
|---|---|---|---|
| Parallel calls | Yes (default) | Yes | Yes |
| Force single tool | tool_choice | tool_choice | functionCallingConfig |
| Disable tools | tool_choice: "none" | tool_choice: "none" | mode: "NONE" |
Optimization Tips
- Group independent calls for parallel execution
- Use
tool_choiceto force specific function selection when needed - Limit the number of tools to reduce decision complexity
- Consider splitting large tool sets across specialized agents
Common Pitfall: Providing Too Many Tools at Once
Models perform significantly worse when given more than 10–15 tools simultaneously. The tool selection accuracy drops as the model must reason over a larger decision space. Group tools by task domain and only provide the relevant subset for each user intent:
const toolSets = {
shopping: [searchProductsTool, addToCartTool, checkoutTool],
support: [lookupOrderTool, createTicketTool, processRefundTool],
account: [updateProfileTool, changePasswordTool, viewHistoryTool],
};
// Classify the user's intent first, then provide the relevant tool set
const intent = await classifyIntent(userMessage);
const tools = toolSets[intent] ?? toolSets.support;
Best Practice: Log All Tool Calls for Auditing
Every tool call should be logged with its input, output, and result. This creates an audit trail for compliance and an invaluable debugging dataset:
async function executeWithAudit(toolName: string, args: unknown) {
const logEntry = { toolName, args, timestamp: new Date(), requestId };
try {
const result = await executeFunction(toolName, args);
await db.toolCallLogs.create({ ...logEntry, status: "success", result });
return result;
} catch (error) {
await db.toolCallLogs.create({ ...logEntry, status: "error", error: String(error) });
throw error;
}
}
Named Product Reference: OpenAI Assistants API with Tools
OpenAI's Assistants API manages the tool call loop automatically — you define tools and provide a run, and the API handles the back-and-forth between model responses and tool execution. It also supports code interpretation (Python sandbox) and file search as built-in tools. For developers who want function calling without implementing the agent loop manually, the Assistants API is a significant time-saver.
Key Takeaways
- •AI models can request parallel function calls for independent operations
- •Sequential chains handle dependent operations across multiple turns
- •Provider APIs differ in parallel call and tool choice syntax
- •Limit tool count and use tool_choice to improve reliability
Progress is kept in this browser only.