fix: Claude model tool handling, compaction guard, normalizer model param
This commit is contained in:
@@ -4339,9 +4339,10 @@ def _antigravity_is_simple_user(text):
|
||||
return True
|
||||
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:
|
||||
return input_data
|
||||
is_claude_model = "claude" in model.lower()
|
||||
|
||||
latest_user = ""
|
||||
latest_user_idx = -1
|
||||
@@ -4405,9 +4406,15 @@ def _antigravity_normalize_context(input_data):
|
||||
latest_words = set(latest_user.strip().lower().split())
|
||||
has_edit_intent = bool(latest_words.intersection(_ANTIGRAVITY_EDIT_WORDS))
|
||||
has_ref_intent = bool(latest_words.intersection(_ANTIGRAVITY_REFERENCE_WORDS))
|
||||
keep_tools = 2 if (has_edit_intent or has_ref_intent) else 1
|
||||
if is_claude_model:
|
||||
keep_tools = len(tool_outputs)
|
||||
else:
|
||||
keep_tools = 2 if (has_edit_intent or has_ref_intent) else 1
|
||||
|
||||
kept_tools = tool_outputs[-keep_tools:] if tool_outputs and (has_edit_intent or has_ref_intent) else []
|
||||
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 []
|
||||
|
||||
for idx_t, t_item in enumerate(kept_tools):
|
||||
orig = t_item[1]
|
||||
@@ -4699,7 +4706,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
body["input"] = input_data
|
||||
|
||||
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)
|
||||
if compacted:
|
||||
body = dict(body)
|
||||
@@ -4878,7 +4885,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
body["input"] = input_data
|
||||
|
||||
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)
|
||||
if compacted:
|
||||
body = dict(body)
|
||||
@@ -4889,8 +4896,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
body = dict(body)
|
||||
body["input"] = input_data
|
||||
|
||||
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list):
|
||||
input_data = _antigravity_normalize_context(input_data)
|
||||
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list) and "claude" not in model.lower():
|
||||
input_data = _antigravity_normalize_context(input_data, model)
|
||||
body = dict(body)
|
||||
body["input"] = input_data
|
||||
|
||||
@@ -4968,7 +4975,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
resp_part["functionResponse"]["id"] = call_id
|
||||
contents.append({"role": "user", "parts": [resp_part]})
|
||||
|
||||
if OAUTH_PROVIDER.startswith("google"):
|
||||
if OAUTH_PROVIDER.startswith("google") and "claude" not in model.lower():
|
||||
sanitized = []
|
||||
last_user_text = None
|
||||
last_role = None
|
||||
@@ -5059,8 +5066,19 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
contents = _gemini_reattach_sigs(contents)
|
||||
|
||||
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])
|
||||
if not guardrail_found:
|
||||
if not guardrail_found and not is_latest_simple:
|
||||
contents.insert(0, {"role": "user", "parts": [{"text": _GEMINI_AGENT_GUARDRAIL}]})
|
||||
|
||||
if OAUTH_PROVIDER == "google-antigravity" and isinstance(input_data, list):
|
||||
|
||||
Reference in New Issue
Block a user