Repository navigation
Description
Description
In a standalone agent project, crewai tool add and crewai tool setup stop with Cannot parse agent.json: Unexpected UTF-8 BOM when agent.json starts with a UTF-8 byte order mark. The same file loads in crewai run's loader (load_jsonc_file reads utf-8-sig, fixed for crew and agent files in #9427). A BOM agent.yaml is not affected.
Cause: _read_definition reads the definition with path.read_text(encoding="utf-8") (lib/cli/src/crewai_cli/agent_tools.py:158 on main at 56c26a7fb3) and passes the text to json.loads, which rejects a leading BOM. Both commands read the definition through it (add_tools_to_agent_project at line 50 and agent_definition_tools at line 105).
Steps to Reproduce
crewai create agent bot --format json, thencd bot.- Prepend the bytes
EF BB BFtoagent.json. - Run
crewai tool add SerperDevTool, orcrewai tool setup.
Expected behavior
The tool is added and the file is rewritten, as for the same file without a BOM. load_jsonc_file in lib/crewai/src/crewai/project/json_loader.py already reads this file with utf-8-sig.
Screenshots/Code snippets
import pathlib, subprocess, tempfile
work = pathlib.Path(tempfile.mkdtemp())
subprocess.run(["crewai", "create", "agent", "bot", "--format", "json"], cwd=work, check=True, stdin=subprocess.DEVNULL)
agent = work / "bot" / "agent.json"
agent.write_bytes(b"\xef\xbb\xbf" + agent.read_bytes())
for cmd in (["tool", "add", "SerperDevTool"], ["tool", "setup"]):
r = subprocess.run(["crewai", *cmd], cwd=work / "bot", capture_output=True, text=True)
print(cmd, r.returncode, (r.stdout + r.stderr).strip()[:140])Operating System
Other (specify in additional context)
Python Version
3.13
crewAI Version
1.15.44 (main at 56c26a7fb3)
crewAI Tools Version
Not used
Virtual Environment
Venv
Evidence
A tool add, agent.json with a BOM | exit 1; SerperDevTool in file: False; BOM kept: True; Error: Cannot parse agent.json: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0). ...
C tool setup, agent.json with a BOM | exit 1; Error: Cannot parse agent.json: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0). ...
E tool add, agent.json no BOM | exit 0; SerperDevTool in file: True; ✔ Added SerperDevTool
G crewai's loader, agent.json BOM | loaded role: General-purpose AI agent
Possible Solution
Read the definition with encoding="utf-8-sig" in _read_definition, as #9427 did for load_jsonc_file.
Additional context
Run on macOS (Darwin). agent.yaml with a BOM was also run and works (it is parsed by PyYAML). A BOM in pyproject.toml is also rejected by crewai tool add, with a TOMLDecodeError, with or without a BOM in agent.json (I and J); this report is about the agent definition. Not run: Windows.
Written with an AI coding agent (Claude Code). CONTRIBUTING asks for the llm-generated label on AI-generated issues; I can't add labels, so could a maintainer add it?
Activity
Vidit-Ostwal commentedon Nov 22, 2026
Thanks for the report, anilkr09. I'm closing this as not planned.
.json is made with cli. I don't see any user tring to make a crew with ,json directly.