Agent Zero AI framework
Adapt thoughts instructions only for Anthropic models
Alessandro325d3a982dc9
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.mdindex 08ddc554c..b535fd3ea 100644--- a/plugins/_model_config/AGENTS.md+++ b/plugins/_model_config/AGENTS.md@@ -33,6 +33,7 @@- In model overviews, render the effective Vision Model as a text-only `Vision override / Provider / Model` child aligned with Main's provider column, not as an icon-bearing peer row.- Changing a model provider in the settings UI must clear `api_base` and `kwargs` because both may be provider-specific.- Repair provider-specific model-config aliases at the model-config read/build boundary; keep provider-specific repairs out of provider-agnostic core wrappers such as `models.py`.+- The `Agent.read_prompt/end` Anthropic hook adapts only the two bundled thoughts instructions in main/communication/solving prompt results when the effective main provider or model name contains `anthropic` (case-insensitive, including OpenRouter). Keep prompt files, JSON fields, history, custom wording, and other models unchanged; standalone communication reads must match main-prompt rendering for native protocol projection. Verify with `tests/test_anthropic_thoughts_prompt.py`.- `modelConfig.createPresetEditor()` owns local preset drafts, row actions, and stable UI-only row keys so deletion or renaming cannot rebind nested model fields.- The preset editor maps each model provider's API-key field to the shared API-key store; saving the editor persists dirty keys separately and never writes secrets into preset YAML.- The compact chat selector label combines the effective preset with only the leaf name of its main model; utility and provider text stay out of the closed selector.diff --git a/plugins/_model_config/README.md b/plugins/_model_config/README.mdindex c7f242b55..0c85c1560 100644--- a/plugins/_model_config/README.md+++ b/plugins/_model_config/README.md@@ -9,6 +9,7 @@ Manage the reusable model presets used for Agent Zero's main, utility, and embed- Preset definitions are global and live in `usr/plugins/_model_config/presets.yaml`. Plugin defaults in `mode_presets_fallback.yaml` are used only when a saved collection cannot be initialized.- Non-default presets may omit advanced fields or model slots; omitted values resolve from `Default`, while provider-specific `kwargs` are replaced or cleared instead of leaking between providers.- API keys remain in the approved environment/settings flow and are never written into preset YAML.+- Models whose provider or name contains `anthropic` receive public-action-summary wording for the bundled `thoughts` instructions, including through OpenRouter. Shared prompt files and the `thoughts` JSON field stay unchanged.## Scoped Selectiondiff --git a/plugins/_model_config/extensions/python/_functions/agent/Agent/read_prompt/end/_20_anthropic_thoughts.py b/plugins/_model_config/extensions/python/_functions/agent/Agent/read_prompt/end/_20_anthropic_thoughts.pynew file mode 100644index 000000000..5d80dbbc9--- /dev/null+++ b/plugins/_model_config/extensions/python/_functions/agent/Agent/read_prompt/end/_20_anthropic_thoughts.py@@ -0,0 +1,26 @@+from helpers.extension import Extension+from plugins._model_config.helpers.model_config import get_chat_model_config+++class AnthropicThoughts(Extension):+ def execute(self, data: dict, **kwargs):+ if not self.agent or not isinstance(data.get("result"), str):+ return+ args = data["args"]+ name = args[1] if len(args) > 1 else data["kwargs"].get("file")+ if name not in {+ "agent.system.main.md",+ "agent.system.main.communication.md",+ "agent.system.main.solving.md",+ }:+ return+ config = get_chat_model_config(self.agent)+ if "anthropic" not in f"{config.get('provider', '')}/{config.get('name', '')}".lower():+ return+ data["result"] = data["result"].replace(+ "- thoughts: array thoughts before execution in natural language",+ "- thoughts: array of brief public action summaries; do not disclose private internal reasoning",+ ).replace(+ "explain each step in thoughts",+ "give brief public progress updates in thoughts, not private internal reasoning",+ )diff --git a/tests/test_anthropic_thoughts_prompt.py b/tests/test_anthropic_thoughts_prompt.pynew file mode 100644index 000000000..c828c112d--- /dev/null+++ b/tests/test_anthropic_thoughts_prompt.py@@ -0,0 +1,53 @@+from pathlib import Path+from types import SimpleNamespace++import pytest++from helpers import files, responses_tools+from plugins._model_config.extensions.python._functions.agent.Agent.read_prompt.end import (+ _20_anthropic_thoughts as thoughts,+)++[email protected]("provider,model,adapted", [+ ("anthropic", "claude-opus-5-5", True),+ ("openrouter", "Anthropic/claude-opus-5.5", True),+ ("bedrock", "us.anthropic.claude-opus", True),+ ("openrouter", "openai/gpt-5", False),+])+def test_scoped_prompt_rendering_preserves_templates_and_native_projection(+ monkeypatch, provider, model, adapted,+):+ root = Path(__file__).parents[1] / "prompts"+ monkeypatch.setattr(thoughts, "get_chat_model_config", lambda agent: {+ "provider": provider, "name": model,+ })+ agent = SimpleNamespace()+ hook = thoughts.AnthropicThoughts(agent)++ def read_prompt(name):+ original = files.read_prompt_file(name, _directories=[str(root)]).rstrip("\n")+ data = {"args": (agent,), "kwargs": {"file": name}, "result": original}+ hook.execute(data)+ assert (data["result"] != original) == (adapted and name != "agent.system.main.communication.native.md")+ return data["result"]++ agent.read_prompt = read_prompt+ main = read_prompt("agent.system.main.md")+ assert read_prompt("agent.system.main.communication.md") in main+ assert read_prompt("agent.system.main.solving.md") in main+ assert '"thoughts": [' in main+ assert ("explain each step in thoughts" not in main) == adapted+ loop = SimpleNamespace(params_temporary={})+ responses_tools.register_prompt(agent, loop, "main", main)+ native = responses_tools.project_system_prompt(+ [{"role": "system", "content": files.remove_code_fences(main, language="json")}],+ loop.params_temporary["responses_prompt_replacements"],+ )[0]["content"]+ assert "Use the provided native functions" in native++ for name in ("agent.system.main.md", "fw.initial_message.md"):+ custom = "Custom thoughts guidance."+ data = {"args": (agent, name), "kwargs": {}, "result": custom}+ hook.execute(data)+ assert data["result"] == custom