[Bug]: ckg tool inverts the print_body default when the OpenAI schema it generates sends null

Author: sxh313Created Sep 28, 2026Updated Sep 28, 2026

What happened?

The ckg tool's print_body parameter does the opposite of what the tool description promises, for every caller that sends a schema-legal value.

CKGTool.get_description() says:

By default, the tool will print function or class bodies as well as the file path and line number of the function or class. You can disable this by setting the print_body parameter to false.

and the parameter's own description says "This is enabled by default."

But trae_agent/tools/ckg_tool.py:100 reads the argument with a bare truthiness coercion:

python
print_body = bool(arguments.get("print_body")) if "print_body" in arguments else True

Meanwhile Tool.get_input_schema() (trae_agent/tools/base.py:142-151) turns every optional parameter into a required, nullable one when the provider is openai:

python
# For OpenAI strict mode, all params must be in 'required'.
# Optional params are made "nullable" to be compliant.
if self.model_provider == "openai":
    required.append(param.name)
    if not param.required:
        ...
        param_schema["type"] = [current_type, "null"]

So for an OpenAI-backed agent the schema forces the model to send print_body, and invites it to send null — and bool(None) is False. The documented default true is unreachable through the only path the schema offers. Measured at e839e55:

required: ['command', 'path', 'identifier', 'print_body']
print_body schema: {'type': ['boolean', 'null'], 'description': 'Whether to print the body of the function or class. This is enabled by default.'}
print_body=omitted              error=None    body_printed=True
print_body=None (null)          error=None    body_printed=False
print_body=False                error=None    body_printed=False
print_body=True                 error=None    body_printed=True
print_body="false" (string)     error=None    body_printed=True
print_body=0 (int)              error=None    body_printed=False

Two distinct failures, both silent (error=None in every row):

  1. null — legal under the schema we generate for OpenAI — silently disables body output, the opposite of the stated default. The agent loses the code bodies the CKG exists to surface, and nothing tells it why.
  2. "false" — a string, which ToolCallArguments (trae_agent/tools/base.py:45) types as a legal argument value, so nothing on the path rejects it — silently enables body output, ignoring the caller's explicit request to turn it off.

Minimal reproduction (no network, no API key):

python
import asyncio
import tempfile
from pathlib import Path

from trae_agent.tools.base import ToolCallArguments
from trae_agent.tools.ckg_tool import CKGTool

BODY_MARK = "def topSum"


async def main():
    with tempfile.TemporaryDirectory() as codebase:
        (Path(codebase) / "sample.py").write_text(
            "def topSum(a, b):\n    return a + b\n", encoding="utf-8"
        )
        tool = CKGTool(model_provider="openai")
        print("required:", tool.get_input_schema()["required"])
        print("print_body schema:", tool.get_input_schema()["properties"]["print_body"])
        for extra in ({}, {"print_body": None}, {"print_body": False}, {"print_body": "false"}):
            arguments = ToolCallArguments(
                {"command": "search_function", "path": codebase, "identifier": "topSum"}
            )
            arguments.update(extra)
            result = await tool.execute(arguments)
            print(f"{extra!s:26s} error={result.error!r:6} body_printed={BODY_MARK in (result.output or '')}")
        for db in tool._ckg_databases.values():
            db._db_connection.close()


asyncio.run(main())

What did you expect to happen?

  • print_body omitted or null should give the documented default (true) — null means "no value", not "false".
  • An explicit false should disable body output.
  • A value that is neither ("false", 0) should be reported, not guessed at.

The repo already has this convention for boolean tool parameters, in the two other tools that consume them:

python
# trae_agent/tools/json_edit_tool.py:116-120
pretty_print_arg = arguments.get("pretty_print", True)
if not isinstance(pretty_print_arg, bool):
    return ToolExecResult(error="pretty_print parameter must be a boolean.", error_code=-1)
python
# trae_agent/tools/sequential_thinking_tool.py:176-180
if "next_thought_needed" not in arguments or not isinstance(arguments["next_thought_needed"], bool):
    raise ValueError("Invalid next_thought_needed: must be a boolean")

ckg_tool.py:100 is the one place that coerces instead of checking.

Traceback

No traceback — that is the point. Every one of the six rows above returns error=None, so a wrong answer is delivered as a success.

What is your system, Python, dependency version?

  • OS: Windows 11 (10.0.26200)
  • Python: 3.12.13
  • openai: 1.86.0 (not needed for the reproduction)
  • trae-agent at main = e839e559ac61bdd0e057c375dd1dee391fee797d, trae_agent/tools/ckg_tool.py blob 49da80ddc1012ca7411ffb3de480bd3a1586ccdd

Additional information that you believe is relevant to this bug

  • The schema-level nullable trick comes from #175 ("Adapt tool schema generation for strict API validation"); this report is about the tool-side reader not being updated for the null that trick now permits.
  • #458 is the same family in a different tool (JSONEditTool and value=None), already has #459 against it; this issue is about the boolean parameter of the CKG tool and does not overlap that diff.
  • bash_tool.py:214 (if arguments.get("restart"):) coerces the same way, but there null matches the documented default (false), so only the "false" string case misbehaves. Out of scope here; restart is also contested by #457.
  • I am not changing get_input_schema() in the same step: making print_body non-nullable for OpenAI would also be schema-legal, but the reader would still be wrong for any non-boolean value, and the tool description documents a default that must be reachable.
  • I'd like to take this and send a PR with a regression test.