Skip to main content

Tool Calling

Advanced tool calling support for AI agents.

Overview

Tokligence Gateway provides comprehensive tool calling support with automatic format conversion between OpenAI and Anthropic APIs.

Supported Features

FeatureStatusDescription
OpenAI function callingFull tool call support with arguments and results
Anthropic tools conversionAutomatic translation between formats
MCP server supportModel Context Protocol servers
Computer use toolsUI automation tools
Tool adapter filteringFilters unsupported tools
Duplicate detectionPrevents infinite loops

OpenAI Function Calling

Standard OpenAI-style function calling:

{
"model": "gpt-4",
"messages": [{"role": "user", "content": "What's the weather in Tokyo?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
}
}
}]
}

Anthropic Tools Conversion

When routing to Anthropic, OpenAI tools are automatically converted:

OpenAI Tools → Gateway → Anthropic Tools
Anthropic Tool Results → Gateway → OpenAI Format

Codex CLI Integration

Full support for Codex CLI v0.55.0+ including:

  • Responses API: Session management with tool calling
  • Streaming: Real-time SSE events
  • Shell commands: Automatic normalization
  • Duplicate detection: Prevents infinite loops

Example Usage

export OPENAI_BASE_URL=http://localhost:8081/v1
codex --full-auto --config 'model="claude-3-5-sonnet-20241022"'

Duplicate Detection

The gateway automatically detects repeated tool calls:

  • 3 duplicates: Warning logged
  • 5 duplicates: Emergency stop

This prevents infinite loops when models repeatedly call the same tool with the same arguments.

Tool Adapter Filtering

Some tools are filtered for compatibility:

ToolReason
apply_patchCodex-specific, not supported by Anthropic
update_planCodex-specific, not supported by Anthropic

Filtered tools are removed from requests, and guidance is injected to use shell alternatives.

MCP Server Support

Model Context Protocol servers are supported:

{
"tools": [{
"type": "mcp",
"server_url": "http://localhost:3000/mcp",
"name": "my-mcp-server"
}]
}

Computer Use Tools

UI automation tools (computer_20241022) with display dimensions:

{
"tools": [{
"type": "computer_20241022",
"display_width": 1920,
"display_height": 1080
}]
}

Session Management

For multi-turn tool calling workflows:

  1. Gateway maintains session state in memory
  2. SSE connection stays open across tool call cycles
  3. Sessions are cleared on restart

Testing Tool Calls

# Basic tool call test
./tests/integration/tool_calls/test_tool_call_basic.sh

# Duplicate detection test
./tests/integration/duplicate_detection/test_duplicate_emergency_stop.sh