fix: Claude model tool handling, compaction guard, normalizer model param
This commit is contained in:
Binary file not shown.
@@ -4339,9 +4339,10 @@ def _antigravity_is_simple_user(text):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _antigravity_normalize_context(input_data):
|
def _antigravity_normalize_context(input_data, model=""):
|
||||||
if not isinstance(input_data, list) or len(input_data) < 2:
|
if not isinstance(input_data, list) or len(input_data) < 2:
|
||||||
return input_data
|
return input_data
|
||||||
|
is_claude_model = "claude" in model.lower()
|
||||||
|
|
||||||
latest_user = ""
|
latest_user = ""
|
||||||
latest_user_idx = -1
|
latest_user_idx = -1
|
||||||
@@ -4405,8 +4406,14 @@ def _antigravity_normalize_context(input_data):
|
|||||||
latest_words = set(latest_user.strip().lower().split())
|
latest_words = set(latest_user.strip().lower().split())
|
||||||
has_edit_intent = bool(latest_words.intersection(_ANTIGRAVITY_EDIT_WORDS))
|
has_edit_intent = bool(latest_words.intersection(_ANTIGRAVITY_EDIT_WORDS))
|
||||||
has_ref_intent = bool(latest_words.intersection(_ANTIGRAVITY_REFERENCE_WORDS))
|
has_ref_intent = bool(latest_words.intersection(_ANTIGRAVITY_REFERENCE_WORDS))
|
||||||
|
if is_claude_model:
|
||||||
|
keep_tools = len(tool_outputs)
|
||||||
|
else:
|
||||||
keep_tools = 2 if (has_edit_intent or has_ref_intent) else 1
|
keep_tools = 2 if (has_edit_intent or has_ref_intent) else 1
|
||||||
|
|
||||||
|
if is_claude_model:
|
||||||
|
kept_tools = tool_outputs
|
||||||
|
else:
|
||||||
kept_tools = tool_outputs[-keep_tools:] if tool_outputs and (has_edit_intent or has_ref_intent) else []
|
kept_tools = tool_outputs[-keep_tools:] if tool_outputs and (has_edit_intent or has_ref_intent) else []
|
||||||
|
|
||||||
for idx_t, t_item in enumerate(kept_tools):
|
for idx_t, t_item in enumerate(kept_tools):
|
||||||
@@ -4699,7 +4706,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
body["input"] = input_data
|
body["input"] = input_data
|
||||||
|
|
||||||
compacted = False
|
compacted = False
|
||||||
if policy.get("compaction") and isinstance(input_data, list):
|
if policy.get("compaction") and isinstance(input_data, list) and "claude" not in model.lower():
|
||||||
input_data, compacted = _adaptive_compact(input_data, model, policy)
|
input_data, compacted = _adaptive_compact(input_data, model, policy)
|
||||||
if compacted:
|
if compacted:
|
||||||
body = dict(body)
|
body = dict(body)
|
||||||
@@ -4878,7 +4885,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
body["input"] = input_data
|
body["input"] = input_data
|
||||||
|
|
||||||
compacted = False
|
compacted = False
|
||||||
if policy.get("compaction") and isinstance(input_data, list):
|
if policy.get("compaction") and isinstance(input_data, list) and "claude" not in model.lower():
|
||||||
input_data, compacted = _adaptive_compact(input_data, model, policy)
|
input_data, compacted = _adaptive_compact(input_data, model, policy)
|
||||||
if compacted:
|
if compacted:
|
||||||
body = dict(body)
|
body = dict(body)
|
||||||
@@ -4889,8 +4896,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
body = dict(body)
|
body = dict(body)
|
||||||
body["input"] = input_data
|
body["input"] = input_data
|
||||||
|
|
||||||
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list):
|
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list) and "claude" not in model.lower():
|
||||||
input_data = _antigravity_normalize_context(input_data)
|
input_data = _antigravity_normalize_context(input_data, model)
|
||||||
body = dict(body)
|
body = dict(body)
|
||||||
body["input"] = input_data
|
body["input"] = input_data
|
||||||
|
|
||||||
@@ -4968,7 +4975,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
resp_part["functionResponse"]["id"] = call_id
|
resp_part["functionResponse"]["id"] = call_id
|
||||||
contents.append({"role": "user", "parts": [resp_part]})
|
contents.append({"role": "user", "parts": [resp_part]})
|
||||||
|
|
||||||
if OAUTH_PROVIDER.startswith("google"):
|
if OAUTH_PROVIDER.startswith("google") and "claude" not in model.lower():
|
||||||
sanitized = []
|
sanitized = []
|
||||||
last_user_text = None
|
last_user_text = None
|
||||||
last_role = None
|
last_role = None
|
||||||
@@ -5059,8 +5066,19 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
contents = _gemini_reattach_sigs(contents)
|
contents = _gemini_reattach_sigs(contents)
|
||||||
|
|
||||||
if OAUTH_PROVIDER == "google-antigravity":
|
if OAUTH_PROVIDER == "google-antigravity":
|
||||||
|
latest_user = ""
|
||||||
|
if isinstance(input_data, list):
|
||||||
|
for item in reversed(input_data):
|
||||||
|
if item.get("type") == "message" and item.get("role") == "user":
|
||||||
|
c = item.get("content", "")
|
||||||
|
if isinstance(c, str):
|
||||||
|
latest_user = c
|
||||||
|
elif isinstance(c, list):
|
||||||
|
latest_user = "\n".join(p.get("text", p.get("input_text", "")) for p in c if isinstance(p, dict))
|
||||||
|
break
|
||||||
|
is_latest_simple = _antigravity_is_simple_user(latest_user)
|
||||||
guardrail_found = any("autonomous coding agent" in json.dumps(c.get("parts", []), ensure_ascii=False) for c in contents[:2])
|
guardrail_found = any("autonomous coding agent" in json.dumps(c.get("parts", []), ensure_ascii=False) for c in contents[:2])
|
||||||
if not guardrail_found:
|
if not guardrail_found and not is_latest_simple:
|
||||||
contents.insert(0, {"role": "user", "parts": [{"text": _GEMINI_AGENT_GUARDRAIL}]})
|
contents.insert(0, {"role": "user", "parts": [{"text": _GEMINI_AGENT_GUARDRAIL}]})
|
||||||
|
|
||||||
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list):
|
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list):
|
||||||
|
|||||||
Reference in New Issue
Block a user