The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/gemini,acp): fold tool-call namespace and finish-reason resolution
Teknium1ff3a849b9a6
diff --git a/agent/copilot_acp_client.py b/agent/copilot_acp_client.pyindex db3ccd0e2bc..902b25092e9 100644--- a/agent/copilot_acp_client.py+++ b/agent/copilot_acp_client.py@@ -74,8 +74,7 @@ def _resolve_command() -> str:def _resolve_args() -> list[str]:- raw = os.getenv("HERMES_COPILOT_ACP_ARGS", "").strip()- return shlex.split(raw) if raw else ["--acp", "--stdio"]+ return shlex.split(os.getenv("HERMES_COPILOT_ACP_ARGS", "").strip()) or ["--acp", "--stdio"]def _acp_supported(command: str, args: list[str]) -> bool | None:@@ -257,8 +256,7 @@ class CopilotACPClient:self._acp_args = list(acp_args or args or _resolve_args())self._acp_cwd = str(Path(acp_cwd or os.getcwd()).resolve())self.chat = SimpleNamespace(completions=SimpleNamespace(create=self._create_chat_completion))- self.is_closed = False- self._active_process: subprocess.Popen[str] | None = None+ self.is_closed, self._active_process = False, Noneself._active_process_lock = threading.Lock()def close(self) -> None:diff --git a/agent/credits_tracker.py b/agent/credits_tracker.pyindex 82e1b05217c..0b54133550b 100644--- a/agent/credits_tracker.py+++ b/agent/credits_tracker.py@@ -103,9 +103,8 @@ def new_credits_latch() -> dict:@dataclassclass AgentNotice:- """Driver-agnostic out-of-band notice (``AIAgent.notice_callback`` / ``notice_clear_callback``);- each driver renders its own way. ``kind``/``ttl_ms`` stay expressive so a future- config can switch v1's sticky credits notices to TTL without touching the policy."""+ """Driver-agnostic out-of-band notice (``AIAgent.notice_callback`` / ``notice_clear_callback``); each driver+ renders its own way. ``kind``/``ttl_ms`` stay expressive so a future config can switch v1's sticky notices to TTL."""text: strlevel: str = "info" # info | warn | error | success@@ -120,13 +119,11 @@ def _sticky_notice(text: str, level: str, key: str) -> AgentNotice:def is_free_tier_model(model: str, base_url: str = "") -> bool:- """True when *model* is a Nous free-tier model, using ONLY local data:- (1) ``:free`` suffix — canonical Nous free SKU marker; (2) ``stealth/`` prefix —- stealth-preview SKUs are free without the suffix (naming-convention trust: a PAID- ``stealth/`` model would wrongly suppress the banner); (3) a PEEK into- ``hermes_cli.models``' pricing cache (filled by the model picker; a miss never- fetches). Fail-open to False (depleted notice still shows): a wrong warning is- recoverable noise; hiding it on a paid model masks a real block."""+ """True when *model* is a Nous free-tier model, using ONLY local data: (1) ``:free`` suffix — canonical+ Nous free SKU marker; (2) ``stealth/`` prefix — stealth-preview SKUs are free without the suffix+ (naming-convention trust: a PAID ``stealth/`` model would wrongly suppress the banner); (3) a PEEK into+ ``hermes_cli.models``' pricing cache (filled by the model picker; a miss never fetches). Fail-open to+ False (depleted notice still shows): a wrong warning is recoverable noise; hiding it masks a real block."""if not model:return Falseif model.endswith(":free") or model.startswith("stealth/"):@@ -143,12 +140,10 @@ def is_free_tier_model(model: str, base_url: str = "") -> bool:def evaluate_credits_notices(state: CreditsState, latch: dict, *, model_is_free: bool = False) -> tuple[list[AgentNotice], list[str]]:- """Reconcile credits notices against the latch (see :func:`new_credits_latch`);- mutates ``latch`` IN PLACE. Pure — no I/O, no agent/run_agent imports.- ``model_is_free`` suppresses ``credits.depleted`` (a depleted account on a free- model keeps inferencing) WITHOUT emitting "restored" — that fires only on a- genuine ``paid_access`` flip back to True.- Returns ``(to_show, to_clear)``; caller emits to_clear FIRST, then to_show."""+ """Reconcile credits notices against the latch (see :func:`new_credits_latch`); mutates ``latch`` IN+ PLACE. Pure — no I/O, no agent/run_agent imports. ``model_is_free`` suppresses ``credits.depleted`` (a+ depleted account on a free model keeps inferencing) WITHOUT emitting "restored" — that fires only on a+ genuine ``paid_access`` flip back to True. Returns ``(to_show, to_clear)``; caller emits to_clear FIRST."""to_show: list[AgentNotice] = []to_clear: list[str] = []uf, active = state.used_fraction, latch["active"]diff --git a/agent/gemini_native_adapter.py b/agent/gemini_native_adapter.pyindex 13611ef41ed..fb693723c07 100644--- a/agent/gemini_native_adapter.py+++ b/agent/gemini_native_adapter.py@@ -429,10 +429,8 @@ def _envelope(model: str, object_: str, choice: SimpleNamespace, usage: Any, clsdef _tool_call_ns(name: str, arguments: str, index: int, call_id: str, extra_content: Any) -> SimpleNamespace:"""OpenAI-shaped tool call; ``extra_content`` attached only when it is a dict."""- tool_call = SimpleNamespace(id=call_id, type="function", index=index, function=SimpleNamespace(name=name, arguments=arguments))- if isinstance(extra_content, dict):- tool_call.extra_content = extra_content- return tool_call+ extra = {"extra_content": extra_content} if isinstance(extra_content, dict) else {}+ return SimpleNamespace(id=call_id, type="function", index=index, function=SimpleNamespace(name=name, arguments=arguments), **extra)def _part_text(part: Dict[str, Any]) -> tuple[Optional[str], bool]:@@ -463,11 +461,8 @@ def translate_gemini_response(resp: Dict[str, Any], model: str) -> SimpleNamespapieces[is_thought].append(text)elif fc := _part_function_call(part):tool_calls.append(_tool_call_ns(str(fc["name"]), _dump_call_args(fc), index, _new_call_id(fc), _tool_call_extra_from_part(part)))- if cand is None:- finish_reason, usage = "stop", _usage_from_metadata({})- else:- finish_reason = "tool_calls" if tool_calls else _FINISH_REASON_MAP.get(str(cand.get("finishReason") or "").upper(), "stop")- usage = _usage_from_metadata(resp.get("usageMetadata") or {})+ finish_reason = "tool_calls" if tool_calls else _FINISH_REASON_MAP.get(str((cand or {}).get("finishReason") or "").upper(), "stop")+ usage = _usage_from_metadata((resp.get("usageMetadata") or {}) if cand is not None else {})reasoning = "".join(pieces[True]) or Nonemessage = SimpleNamespace(role="assistant", content="".join(pieces[False]) if pieces[False] else ("" if cand is None else None),tool_calls=tool_calls or None, reasoning=reasoning, reasoning_content=reasoning, reasoning_details=None)