Skip to main content
Function Calling allows AI models to call external functions and APIs, greatly expanding the capability boundaries of intelligent agents, enabling them to perform specific operations and obtain real-time data.

Features

Function calling provides AI models with the ability to interact with external systems, supporting various complex application scenarios and integration requirements.

Core Parameter Description

  • tools: Defines the list of callable functions, including function names, descriptions, and parameter specifications
  • tool_choice: Controls function calling strategy, default is auto (only supports auto)
  • model: Uses models that support function calling, such as glm-4-plus, glm-4.6, etc.

Response Parameter Description

Key fields in function calling responses:
  • tool_calls: Contains information about functions the model decides to call
  • function.name: Name of the called function
  • function.arguments: Function call parameters (JSON format string)
  • id: Unique identifier for the tool call

Code Examples

By defining function tools and handling function calls, AI models can perform various external operations:
Install SDK
Verify Installation
Complete Example

Scenario Examples

When using function calling, please ensure proper security validation and permission control for external APIs and database operations.

Best Practices

Function Design Principles

  • Single responsibility: Each function should do one thing
  • Clear naming: Function and parameter names should be meaningful
  • Complete description: Provide detailed function and parameter descriptions

Security Considerations

  • Input validation: Strictly validate all input parameters
  • Permission control: Limit function access permissions
  • Logging: Record function call logs

Parameter Design

Error Handling

Input Validation

Permission Control

It is recommended to provide detailed documentation and examples for each function to help the model better understand the function’s purpose and usage.
Function calling involves code execution. Please ensure appropriate security measures are implemented, including input validation, permission control, and error handling.