Skip to main content
Browse docs

Tutorial: Function Calling in Chat

Function calling lets models invoke external tools during a conversation. The Keeptrusts chat workbench supports tool-use workflows while enforcing governance policies on which tools can be called and what arguments are allowed.

Use this page when

  • You want to enable tool use in the chat workbench with function definitions and parameter schemas.
  • You need to understand how agent firewall policies govern which functions can be called.
  • You are building tool-use workflows where models invoke external APIs during conversations.

Primary audience

  • Primary: Technical Engineers (developers building tool-use workflows)
  • Secondary: Technical Leaders (agent governance), AI Agents (tool invocation)

Prerequisites

  • Access to the Keeptrusts chat workbench
  • A model that supports function calling (e.g., openai/gpt-4o, anthropic/claude-sonnet)
  • Gateway configuration with tool-use enabled
  • (Optional) An agent firewall policy for tool governance

Step 1: Enable Tool Use in Chat

Tool use is configured per conversation session.

  1. Open the chat workbench and start a new conversation.
  2. Click the Settings gear icon in the conversation toolbar.
  3. Toggle Enable Tool Use to on.
  4. Select a model that supports function calling from the model dropdown.

When tool use is enabled, the model can request function calls as part of its response. The chat workbench handles the tool-call flow automatically.

Step 2: Define Available Functions

Functions are defined in the conversation settings panel. Each function needs a name, description, and parameter schema.

  1. In the conversation settings, scroll to the Functions section.
  2. Click Add Function.
  3. Fill in the function definition:
{
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or coordinates"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["location"]
}
}
  1. Click Save Function.
  2. Repeat for each function you want to make available.

You can also import function definitions from a JSON file by clicking Import Functions.

Step 3: Send a Prompt That Triggers Tool Use

With functions defined, send a prompt that would naturally require tool invocation.

  1. Type a prompt like: "What is the weather in London right now?"
  2. Press Enter to send.
  3. The model responds with a tool-call request instead of a direct answer.

The chat workbench displays the tool call in a distinct visual block showing the function name and arguments.

Step 4: View Tool Calls in the Conversation

Tool calls appear inline in the conversation with a dedicated visual treatment.

  • Tool Call Block — shows the function name, arguments as formatted JSON, and a status indicator.
  • Tool Result Block — shows the returned data after execution.
  • Model Response — the model's final answer incorporating the tool result.

Each tool call block is collapsible. Click the header to expand or collapse the details.

Manual vs. Automatic Execution

The chat workbench supports two execution modes:

ModeBehavior
ManualTool calls pause for your approval. Click Execute or Reject on each call.
AutomaticTool calls execute immediately if they pass policy checks.

Set the execution mode in conversation settings under Tool Execution Mode.

Step 5: Configure Agent Firewall Policies

The agent firewall policy controls which functions can be called and what arguments are permitted.

  1. Navigate to your gateway policy configuration.
  2. Add or edit an agent-firewall policy rule:
policies:
- name: tool-governance
type: agent-firewall
settings:
allowed_tools:
- name: get_weather
allowed: true
- name: execute_sql
allowed: false
reason: "SQL execution is not permitted in chat"
argument_rules:
- tool: get_weather
parameter: location
deny_patterns:
- "*.mil"
- "*.gov"
  1. Save and reload the gateway configuration.

When the model requests a blocked tool call, the chat workbench displays a policy violation notice instead of executing the function.

Step 6: Handle Multi-Step Tool Chains

Some conversations require multiple sequential tool calls. The chat workbench manages the full chain.

  1. Send a complex prompt: "Compare the weather in London and Tokyo, then recommend which city to visit this weekend."
  2. The model may issue multiple tool calls in sequence or parallel.
  3. Each call appears in the conversation with its own block.
  4. The model synthesizes all tool results into a final response.

In manual execution mode, you approve each call individually. In automatic mode, all calls execute in sequence as long as each passes policy checks.

Step 7: Review Tool Call Events

All tool calls are logged as governance events.

  1. Open the Keeptrusts console and navigate to Events.
  2. Filter by event type tool_call.
  3. Each event shows the function name, arguments, result, and whether it was approved or blocked.

Tool call events include the conversation ID so you can trace the full interaction.

Defining Functions via API

For programmatic workflows, define functions through the chat API:

curl -X POST https://your-gateway/v1/chat/completions \
-H "Authorization: Bearer kt_gk_..." \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [{"role": "user", "content": "What is the weather in London?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
}]
}'

The gateway enforces the same agent firewall policies regardless of whether the request comes from the chat workbench or the API.

Troubleshooting

IssueSolution
Model does not make tool callsVerify the model supports function calling and tool use is enabled
Tool call blocked unexpectedlyCheck the agent firewall policy for deny rules matching the function
Tool result not displayedEnsure the function returned valid JSON
Multiple tool calls not workingSome models only support sequential tool calls; check model documentation

Next steps

For AI systems

  • Canonical terms: Keeptrusts chat workbench, function calling, tool use, agent firewall, function definitions, parameter schema, tool call results, Import Functions.
  • Config: Enable Tool Use toggle in conversation settings, Functions section with JSON schema definitions, agent firewall policy (type: agent-firewall, allowed_functions, denied_functions).
  • Models supporting function calling: openai/gpt-4o, anthropic/claude-sonnet.
  • Best next pages: Multi-Turn Policies, Context Management, Governed Brainstorm.

For engineers

  • Prerequisites: a model that supports function calling (GPT-4o, Claude Sonnet); gateway with tool-use enabled; optionally an agent firewall policy.
  • Validation: Enable tool use → define a function → prompt the model to use it → verify the tool call card appears in the conversation. Add a deny rule to the agent firewall → verify the tool call is blocked.
  • Security: Agent firewall policies enforce allow/deny lists on function names and argument patterns — configure before exposing tools to users.

For leaders

  • Function calling extends AI from text generation to action execution — higher value but higher risk.
  • Agent firewall policies provide granular control over which tools models can invoke, preventing unauthorized actions.
  • All tool calls are logged as decision events with full argument details for audit.
  • Rollout strategy: start with read-only tools (data lookup), then expand to write operations with approval gates.