Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/algolia_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def _index_entry(raw) -> dict:
"indices": indices,
}
if "searchControls" in config:
tool["searchControls"] = config["searchControls"]
for idx in tool["indices"]:
idx["searchControls"] = config["searchControls"]
if "predefinedSearchParameters" in config:
tool["predefinedSearchParameters"] = config["predefinedSearchParameters"]
return tool
Expand Down Expand Up @@ -300,8 +301,14 @@ def _diff(current: dict, new_payload: dict) -> list[str]:
f"({len(curr_instr.splitlines())} lines → {len(new_instr.splitlines())} lines)"
)

curr_sc = next((t["searchControls"] for t in current.get("tools", []) if "searchControls" in t), None)
new_sc = next((t["searchControls"] for t in new_payload.get("tools", []) if "searchControls" in t), None)
curr_sc = next(
(i.get("searchControls") for t in current.get("tools", []) for i in t.get("indices", [])),
None,
)
new_sc = next(
(i.get("searchControls") for t in new_payload.get("tools", []) for i in t.get("indices", [])),
None,
)
if curr_sc != new_sc:
lines.append(f" searchControls: {json.dumps(curr_sc)} → {json.dumps(new_sc)}")

Expand Down
20 changes: 10 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ def test_build_tool_with_search_controls():
"searchControls": search_controls,
}
tool = build_tool(config)
assert tool["searchControls"] == search_controls
assert "searchControls" not in tool # not at tool level
for idx in tool["indices"]:
assert idx["searchControls"] == search_controls
Comment on lines -748 to +761
assert "predefinedSearchParameters" not in tool


Expand All @@ -767,8 +769,9 @@ def test_build_tool_with_empty_search_controls():
"searchControls": {},
}
tool = build_tool(config)
assert "searchControls" in tool
assert tool["searchControls"] == {}
assert "searchControls" not in tool # not at tool level
for idx in tool["indices"]:
assert idx["searchControls"] == {}


def test_build_tool_with_predefined_search_parameters():
Expand All @@ -784,21 +787,18 @@ def test_build_tool_with_predefined_search_parameters():


def test_diff_detects_search_controls_change():
sc = {"hitsPerPage": {"exposed": True, "default": 5, "constraint": {"max": 5}}}
current = {
"name": "My Agent",
"model": "gemini-2.5-flash",
"instructions": "Hello.",
"tools": [{"type": "algolia_search_index", "indices": [{"index": "products", "description": "Catalog."}]}],
"tools": [{"type": "algolia_search_index", "indices": [{"index": "products", "description": "Catalog.", "searchControls": None}]}],
}
new_payload = {
"name": "My Agent",
"model": "gemini-2.5-flash",
"instructions": "Hello.",
"tools": [{
"type": "algolia_search_index",
"indices": [{"index": "products", "description": "Catalog."}],
"searchControls": {"hitsPerPage": {"exposed": True, "default": 5, "constraint": {"max": 5}}},
}],
"tools": [{"type": "algolia_search_index", "indices": [{"index": "products", "description": "Catalog.", "searchControls": sc}]}],
}
changes = _diff(current, new_payload)
assert len(changes) == 1
Expand All @@ -812,7 +812,7 @@ def test_diff_no_change_when_search_controls_equal():
"name": "My Agent",
"model": "gemini-2.5-flash",
"instructions": "Hello.",
"tools": [{"type": "algolia_search_index", "indices": [], "searchControls": sc}],
"tools": [{"type": "algolia_search_index", "indices": [{"index": "products", "searchControls": sc}]}],
}
changes = _diff(agent, dict(agent))
assert not changes
Loading