Skip to content

irreg/native_tool_call_adapter

Repository files navigation

NativeToolCallAdapter

日本語 | English

Overview

  • BEFORE (without this app)
flowchart LR
    A[cline, Roo-Code] --> |XML tool defs|C[LLM]
    C -.-> |XML tool calls
    <u>with a potentially incorrect signature</u>|A
Loading
  • AFTER (with this app)
flowchart LR
    A[cline, Roo-Code] --> |XML tool defs|B[**This app**]
    B --> |native tool defs|C[LLM]
    C -.-> |native tool calls
    <u>with an accurate signature</u>|B
    B -.-> |XML tool calls
    <u>with an accurate signature</u>|A
Loading

With relatively small models, cline and Roo-Code tool calls may not be handled properly. This application parses XML-formatted tool calls from Cline and Roo-Code and converts them into a format compliant with OpenAI API's tool_calls.

Significant improvements in performance have been confirmed with gpt-oss-20b and other models. Even with large models, the reduced load of considering tool calls should lead to more accurate behavior.

Notes

This is an experimental application. Parsing depends on the content of Cline/Roo-Code prompts, so it may stop working if the prompt specifications change in the future.

Execution Steps

  1. `git clone https://github.com/irreg/native_tool_call_adapter.git
  2. uv sync
  3. set TARGET_BASE_URL=actual LLM operating URL
    Example:
  4. uv run main.py
  5. The server will start on port 8000, so configure Cline and Roo-Code.
    Example:
    • API Provider: OpenAI Compatible
    • Base URL: http://localhost:8000/v1
    • API Key: Setting the API key will automatically use it when communicating with TARGET_BASE_URL.

Settings

The following settings can be configured as environment variables

  • TARGET_BASE_URL: (default: https://api.openai.com/v1) URL hosting the LLM
  • TOOL_CALL_ADAPTER_HOST: (default: 0.0.0.0) URL hosting this application
  • TOOL_CALL_ADAPTER_PORT: (default: 8000) Port hosting this application
  • MESSAGE_DUMP_PATH: (default: null) Dumps the message actually sent to the LLM to the specified path, allowing you to verify the converted content
  • TOOL_DUMP_PATH: (default: null) Dumps the list of tool definitions actually sent to the LLM to the specified path, allowing you to verify the converted content.
  • DISABLE_STRICT_SCHEMAS: (default: null) Disables the feature that prevents tool calls that don't match the tool definition.
    Tool calls may become unstable with tools that have overly complex definitions. If you encounter such issues, set this to 1 to disable it.
  • FORCE_TOOL_CALLING: (default: null) Forces the system to always call at least one tool.
    In llama.cpp, enabling this may disable reasoning (likely a llama.cpp bug), so it is disabled by default.
    If no issues occur or reasoning is unnecessary, set it to 1 to enable. This can reduce tool call failures in cline/Roo-Code.

setting.yaml

You can define additional replacement rules using regular expressions in setting.yaml.
If you wish to use the existing JSON version of the settings (deprecated), please delete the YAML file.

Configuration File Structure

additional_replacement:
  - name: Replacement rule name
    role: Target role
    pattern: Regular expression pattern
    replace: Replacement string
    trigger: Condition key to enable replacement
    ref: List of role names to reference

Description of Each Field

  • name: (optional) Name of this replacement rule
  • role: Role of the message this rule applies to
    • system: System prompt
    • user: User-entered message or response sent by cline/Roo-Code to the LLM (e.g., when a tool call fails)
    • tool: Past tool call result
    • assistant: Past LLM response outside of tool calls
    • completion: Newly generated response from the LLM (data returned to cline/Roo-Code, including tool calls)
  • pattern: Regular expression pattern to search for.
  • replace: (optional) Replacement string.
    If omitted, named capture groups within the pattern (e.g., (?P<key>...)) can be captured and used in subsequent pattern/replace processing.
  • ref: (optional) Uses a string captured from the message processed immediately before the specified role in pattern/replace. Replaces strings in pattern/replace matching the format {key} with the captured string.
  • trigger: (optional) Only performs replacement if the string captured from the immediately preceding pattern contains the named capture group key.

Example 1: Replace "XML tags" in cline responses to LLM with "tool calling"

additional_replacement:
  - role: user
    pattern: XML tags
    replace: tool calling

Example 2: Extract user_id from user messages and use it to replace values in LLM output

additional_replacement:
  - role: user
    pattern: ID:(?P<user_id>\d+)
  - role: completion
    trigger: user_id
    ref: [user]
    pattern: Hello
    replace: Hello #{user_id}!

About

Helps agents work more efficiently by translating cline/Roo-Code tool calls into native tool calls in the API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages