Skip to content

Agent Zero AI framework

Clarify required Agent Editor instructions

Alessandroabc8f13cb89a
diff --git a/plugins/_agent_editor/webui/main.html b/plugins/_agent_editor/webui/main.html
index b23d9c920..c94ff3944 100644
--- a/plugins/_agent_editor/webui/main.html
+++ b/plugins/_agent_editor/webui/main.html
@@ -170,10 +170,10 @@
<section class="agent-easy-field">
<div class="agent-field-heading">
- <div><label for="agent-editor-instructions" class="agent-field-label">Instructions</label><p>What should this agent do, and how should it behave?</p></div>
+ <div><label for="agent-editor-instructions" class="agent-field-label">Instructions <span class="agent-status-badge compact" x-show="$store.agentEditor.draft?.creating">Required</span></label><p>What should this agent do, and how should it behave?</p></div>
</div>
<div>
- <textarea id="agent-editor-instructions" rows="9" x-model="$store.agentEditor.instructions.value" @input="$store.agentEditor.markPromptSet('agent.system.main.specifics.md')" placeholder="Research technical topics, verify important claims with reliable sources, and return concise reports with links." :aria-invalid="$store.agentEditor.fieldIssue('instructions') ? 'true' : null" :aria-describedby="$store.agentEditor.fieldIssue('instructions') ? 'agent-editor-instructions-error' : null"></textarea>
+ <textarea id="agent-editor-instructions" rows="9" x-model="$store.agentEditor.instructions.value" @input="$store.agentEditor.markPromptSet('agent.system.main.specifics.md')" placeholder="Research technical topics, verify important claims with reliable sources, and return concise reports with links." :required="$store.agentEditor.draft?.creating" :aria-invalid="$store.agentEditor.fieldIssue('instructions') ? 'true' : null" :aria-describedby="$store.agentEditor.fieldIssue('instructions') ? 'agent-editor-instructions-error' : null"></textarea>
<span id="agent-editor-instructions-error" class="field-error" role="alert" x-show="$store.agentEditor.fieldIssue('instructions')" x-text="$store.agentEditor.fieldIssue('instructions')?.message"></span>
<button type="button" class="text-button restore-action" x-show="$store.agentEditor.instructions.has_override && !$store.agentEditor.instructions.reset" @click="$store.agentEditor.restoreInstructions()"><x-icon name="restart_alt"></x-icon><span>Reset to default</span></button>
</div>
@@ -375,7 +375,7 @@
</div>
<div class="footer-actions">
<button type="button" class="btn agent-editor-secondary-action" x-show="$store.agentEditor.view === 'editor' && !$store.agentEditor.draft?.creating" @click="$store.agentEditor.save(true)" :disabled="$store.agentEditor.saving || $store.agentEditor.validationIssues().length > 0">Save & test</button>
- <button type="button" class="btn btn-ok" x-show="$store.agentEditor.view === 'editor'" @click="$store.agentEditor.save(false)" :disabled="$store.agentEditor.saving || $store.agentEditor.avatarUploading || $store.agentEditor.validationIssues().length > 0" :title="$store.agentEditor.validationIssues().length ? 'Fix the highlighted issues before saving' : ''"><span x-text="$store.agentEditor.saving ? 'Saving…' : $store.agentEditor.draft?.creating ? 'Create agent' : 'Save changes'"></span></button>
+ <button type="button" class="btn btn-ok" x-show="$store.agentEditor.view === 'editor'" @click="$store.agentEditor.save(false)" :disabled="$store.agentEditor.saving || $store.agentEditor.avatarUploading || $store.agentEditor.validationIssues().length > 0" :title="$store.agentEditor.validationErrors().join(' ')"><span x-text="$store.agentEditor.saving ? 'Saving…' : $store.agentEditor.draft?.creating ? 'Create agent' : 'Save changes'"></span></button>
</div>
</div>
</div>
diff --git a/tests/test_agent_editor_webui.py b/tests/test_agent_editor_webui.py
index 1a28ec0e5..9ab675bb3 100644
--- a/tests/test_agent_editor_webui.py
+++ b/tests/test_agent_editor_webui.py
@@ -12,6 +12,7 @@ import pytest
ROOT = Path(__file__).resolve().parents[1]
STORE = ROOT / "plugins" / "_agent_editor" / "webui" / "agent-editor-store.js"
MODAL = ROOT / "plugins" / "_agent_editor" / "webui" / "main.html"
+TOOLTIP_STORE = ROOT / "webui" / "components" / "tooltips" / "tooltip-store.js"
SWITCHER = (
ROOT
/ "plugins"
@@ -175,6 +176,9 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert "Replace with simple instructions" not in modal
assert "easyInstructionsEditable" not in modal
assert '<textarea id="agent-editor-instructions"' in modal
+ assert ':required="$store.agentEditor.draft?.creating"' in easy_surface
+ assert '>Instructions <span class="agent-status-badge compact"' in easy_surface
+ assert ">Required</span>" in easy_surface
assert "<h2" not in modal
assert "Section 1" not in modal
assert '<textarea id="agent-editor-description" rows="2"' in modal
@@ -216,6 +220,8 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert modal.count('role="alert"') >= 4
assert "Fix ${$store.agentEditor.validationIssues().length}" in modal
assert modal.count("$store.agentEditor.validationIssues().length > 0") == 2
+ assert ':title="$store.agentEditor.validationErrors().join(\' \')"' in modal
+ assert "Fix the highlighted issues before saving" not in modal
assert "$store.agentEditor.view === 'editor' && !$store.agentEditor.pendingMutation" in modal
assert 'x-show="$store.agentEditor.view === \'editor\' && !$store.agentEditor.draft?.creating"' in modal
assert 'class="btn btn-ok" x-show="$store.agentEditor.view === \'editor\'"' in modal
@@ -301,6 +307,46 @@ def test_agent_editor_store_has_no_conversational_or_model_builder_path() -> Non
assert "toast-link" not in source and ".toast-link" not in modal
[email protected](not shutil.which("node"), reason="node is required")
+def test_empty_dynamic_title_disposes_its_tooltip() -> None:
+ source = re.sub(
+ r"^import .*?;\n",
+ "",
+ TOOLTIP_STORE.read_text(encoding="utf-8"),
+ flags=re.MULTILINE,
+ )
+ source += "\nexport { ensureBootstrapTooltip };\n"
+ module_url = "data:text/javascript;base64," + base64.b64encode(
+ ("const createStore = (_name, value) => value;\n" + source).encode("utf-8")
+ ).decode("ascii")
+ script = f"""
+class FakeElement {{
+ constructor() {{ this.attributes = new Map([["title", "Instructions are required."]]); }}
+ getAttribute(name) {{ return this.attributes.has(name) ? this.attributes.get(name) : null; }}
+ hasAttribute(name) {{ return this.attributes.has(name); }}
+ setAttribute(name, value) {{ this.attributes.set(name, String(value)); }}
+ removeAttribute(name) {{ this.attributes.delete(name); }}
+}}
+globalThis.Element = FakeElement;
+let instance = null;
+class Tooltip {{
+ static getInstance(element) {{ return instance?.element === element ? instance : null; }}
+ constructor(element) {{ this.element = element; instance = this; }}
+ dispose() {{ instance = null; }}
+ setContent() {{}}
+}}
+globalThis.bootstrap = {{ Tooltip }};
+const {{ ensureBootstrapTooltip }} = await import({module_url!r});
+const element = new FakeElement();
+ensureBootstrapTooltip(element);
+if (!instance || element.getAttribute("data-bs-original-title") !== "Instructions are required.") throw new Error("tooltip was not initialized");
+element.setAttribute("title", "");
+ensureBootstrapTooltip(element);
+if (instance || element.hasAttribute("data-bs-original-title") || element.hasAttribute("data-bs-tooltip-initialized")) throw new Error("cleared title left a stale tooltip");
+"""
+ subprocess.run(["node", "--input-type=module", "-e", script], check=True)
+
+
@pytest.mark.skipif(not shutil.which("node"), reason="node is required")
def test_local_slugging_and_fresh_chat_profile_selection_are_deterministic() -> None:
source = STORE.read_text(encoding="utf-8")
diff --git a/webui/components/tooltips/tooltip-store.js b/webui/components/tooltips/tooltip-store.js
index b5ec67738..2a273b0e6 100644
--- a/webui/components/tooltips/tooltip-store.js
+++ b/webui/components/tooltips/tooltip-store.js
@@ -9,7 +9,16 @@ function ensureBootstrapTooltip(element) {
if (!bs?.Tooltip) return;
const existing = bs.Tooltip.getInstance(element);
- const title = element.getAttribute("title") || element.getAttribute("data-bs-original-title");
+ const boundTitle = element.getAttribute("title");
+ if (element.hasAttribute("title") && !boundTitle) {
+ disposeBootstrapTooltip(element);
+ element.removeAttribute("data-bs-original-title");
+ element.removeAttribute("data-bs-toggle");
+ element.removeAttribute("data-bs-trigger");
+ element.removeAttribute("data-bs-tooltip-initialized");
+ return;
+ }
+ const title = boundTitle || element.getAttribute("data-bs-original-title");
if (!title) return;