agent-zero icon indicating copy to clipboard operation
agent-zero copied to clipboard

Feature: Auto-create skills/behaviour_adjustments for learned procedures (Memory-Skill-Reflex gap)

Open grodingo opened this issue 7 months ago • 3 comments

Problem

Currently, the Agent Zero memory pipeline automatically extracts fragments (knowledge) and solutions (successful problem-solving patterns) from conversations via the utility model extensions:

  • _50_memorize_fragments.py → extracts facts/knowledge → area: fragments
  • _51_memorize_solutions.py → extracts successful solutions → area: solutions

This works great for passive knowledge storage. However, the documentation (docs/guides/api-integration.md) states:

"Agent Zero will remember this solution. The next time you ask it to generate an image, it will automatically use the approach."

In practice, this only works partially. The solution IS stored in memory and injected into prompts, but there is no automatic reflex to trigger the stored solution contextually. Without an explicit behaviour_adjustment, the agent treats requests as simple questions rather than looking up stored solutions.

Current Architecture

Conversation
    ↓ (utility model)
Fragments / Solutions (FAISS memory)
    ↓ (injected in prompt via memory_load)
Agent has AWARENESS but no REFLEX
    ↓
Requires MANUAL behaviour_adjustment to trigger automatically

The 3-layer pattern documented in memory:

  • Memory = knowledge ✅ (automated)
  • Skill = method ❌ (manual creation required)
  • Behaviour adjustment = reflex ❌ (manual creation required)

Source Code Evidence

The memorization pipeline (monologue_end) has exactly 2 automatic extensions:

Extension Purpose Automatic?
_50_memorize_fragments.py Extract knowledge → FAISS ✅
_51_memorize_solutions.py Extract solutions → FAISS ✅
Missing Auto-create skill/reflex ❌

The behaviour_adjustment tool exists but is only callable manually by the agent. There is no extension that automatically bridges memorized solutions to behaviour adjustments or skills.

Proposed Solution

Add a new extension (e.g., _52_auto_skill_reflex.py) at monologue_end that:

  1. Detects recurring solutions — When a solution is memorized multiple times or has high importance, flag it as a candidate for automation
  2. Auto-generates behaviour_adjustment — Uses the utility model to create a contextual trigger rule (e.g., "When user asks to analyze/describe an image, use the Gemma 4 vision script from memory")
  3. Optionally creates a skill — For complex procedures, encapsulate the method in /a0/usr/skills/ with a SKILL.md

Desired Flow

Conversation
    ↓ (utility model)
Fragments / Solutions (FAISS memory)
    ↓ (new: auto_skill_reflex extension)
Recurring solution detected?
    → YES: Auto-create behaviour_adjustment + optional skill
    → NO: Store as passive knowledge
    ↓
Agent has both AWARENESS and REFLEX

Implementation Ideas

  • Detection heuristic: Track solution frequency / importance score. After N occurrences of similar solutions (configurable), trigger auto-skill creation
  • Utility model prompt: Create a new prompt template (e.g., memory.auto_skill.sys.md) that instructs the utility model to generate appropriate behaviour_adjustments from stored solutions
  • Configuration: Add settings like:
    • memory_auto_skill_enabled (boolean, default: false)
    • memory_auto_skill_threshold (int, number of occurrences before triggering)
    • memory_auto_skill_mode (enum: suggest | auto — suggest logs without applying, auto applies directly)
  • Conservative approach: Start with auto-suggesting skills/adjustments (log them for user review) before auto-applying them
  • Integration point: Reuse the existing update_behaviour() function from behaviour_adjustment.py to merge new rules

Benefits

  • Closes the gap between the documented behavior ("will automatically use the approach") and actual behavior (requires manual reflex setup)
  • Makes the agent truly self-improving: learns procedures AND automates their reuse
  • Reduces manual configuration for common patterns (API integrations, recurring tasks)
  • Aligns with the "show once, use forever" promise in the documentation
  • Leverages the existing consolidation system that already tracks memory frequency and importance

Example Use Case

  1. User provides a Gemini Vision script for image analysis
  2. Agent memorizes the solution → stored in FAISS ✅
  3. User asks to analyze an image in a new conversation
  4. Current: Agent guesses or asks instead of using stored solution ❌
  5. Proposed: Auto-created behaviour_adjustment triggers: "use Gemma 4 vision script from memory" → automatic execution ✅

Environment

  • Agent Zero version: latest (main branch)
  • Observed with: vision analysis scripts (Gemma 4), API integrations

grodingo avatar Apr 05 '26 17:04 grodingo

Update: Simplified Alternative (Prompt-Driven Approach)

After further analysis — inspired by Hermes Agent from NousResearch — we identified a much simpler alternative that requires zero new code.

Key Discovery

Agent Zero already has all the necessary tools:

Need Existing Tool Hermes Equivalent
Create skills text_editor:write + create-skill skill skill_manager_tool(create)
Edit skills text_editor:patch skill_manager_tool(patch)
List skills skills_tool:list Auto-injected index
Load skills skills_tool:load skill_view()
Add reflex behaviour_adjustment Hardcoded prompt

The create-skill skill already exists at /a0/skills/create-skill/SKILL.md with a full wizard.

How behaviour_adjustment Works (Already Built)

  1. behaviour_adjustment tool calls the utility model to merge new rules into existing ruleset
  2. Rules stored in behaviour.md in the memory subdirectory
  3. BehaviourPrompt extension (system_prompt/_20_behaviour_prompt.py) automatically injects rules into every system prompt at position [0]

So the injection mechanism already works perfectly — no new extension needed.

Proposed Simplified Solution

Instead of a new _52_auto_skill_reflex.py extension, simply add a behaviour_adjustment with prompt guidance similar to Hermes:

After solving a complex problem (5+ tool calls), fixing a tricky error, or discovering a reusable workflow:
1. Load the create-skill skill with skills_tool:load
2. Create a new skill in /a0/usr/skills/ following the SKILL.md standard
3. Include trigger patterns so the skill activates contextually

When using a skill and finding it outdated, incomplete, or wrong, patch it immediately with text_editor:patch.
Skills that aren't maintained become liabilities.

Comparison

Aspect Original (Extension) Simplified (Prompt-Driven)
New code needed Extension + prompt templates None
Trigger mechanism Heuristics + utility model Primary LLM decides
Skill quality Medium (utility model context) High (full conversation context)
False positives risk Medium Low (LLM judges relevance)
Implementation time 2-3 hours 5 minutes
Maintenance burden Extension to maintain None

Advantages of Prompt-Driven Approach

  1. Zero code — uses existing tools (behaviour_adjustment, skills_tool, text_editor, create-skill)
  2. Contextually intelligent — the primary LLM has full conversation context (unlike utility model)
  3. Self-improving skills — agent patches outdated skills autonomously (like Hermes)
  4. Immediately deployable — just apply a behaviour_adjustment
  5. Proven pattern — Hermes Agent uses this exact approach successfully

What Still Has Value from Original Proposal

The extension approach could still be valuable as a future enhancement for:

  • Automatic skill suggestion (log recommendations without auto-applying)
  • Frequency-based detection of recurring solutions
  • Skill analytics and health monitoring

But for immediate impact, the prompt-driven approach is the clear winner.

grodingo avatar Apr 05 '26 19:04 grodingo

Final Update: Behaviour Auto-Enrichment (Simplest Approach)

After further discussion, we identified an even simpler approach — no skills needed at all.

The Insight

Instead of creating skills (which need manual loading), just auto-enrich the behaviour_adjustment directly with solution patterns.

Since behaviour_adjustment is already auto-injected at every request for all agents (including subordinates), it is the most token-efficient delivery mechanism.

Implementation: Zero Code

Add a single meta-rule to behaviour_adjustment:

## Rule — Proactive Rule Creation
After a complex task (5+ tool calls), a tricky error resolved,
or a reusable workflow discovered:
→ Update the behaviour_adjustment by adding/correcting
   the solution patterns found in memory.
→ Each rule must be short, targeted, and conditional
   (when to use / when NOT to use).

The behaviour then auto-enriches itself over time. Example after a vision analysis conversation:

## Rule — Image Analysis
When the user asks to analyze, describe, or examine an image:
- If the current LLM IS multimodal (gpt-4o, claude-sonnet,
  gemini-2.0-flash, gemini-2.5-pro) → use its native capabilities directly.
- If the current LLM is NOT multimodal → use the Gemma 4 script
  (gemma-4-31b-it) stored in memory (area: solutions) for analysis.
- NEVER invent or guess the content of an image.

Why This Beats Skills

Aspect Skills Behaviour Auto-Enrichment
Injection Manual (load) Automatic
Token cost Full SKILL.md Short rule
Conditional logic Limited Native (if/else)
Subordinate inheritance Separate memory Shared behaviour.md
Self-maintenance Manual patch Auto-enriching

Subordinate Agents Share the Behaviour

All agents share the same behaviour.md (stored in memory/default/). The get_agent_memory_subdir() function returns "default" for all agents unless project isolation is active. So:

  • Agent 0 creates a rule → all subordinates inherit it
  • Memory (FAISS) is also shared → subordinates can access stored solutions

Applied

This behaviour_adjustment has been applied and is now active. The meta-rule will cause new rules to be added automatically as the agent encounters reusable patterns.

grodingo avatar Apr 05 '26 20:04 grodingo

Closing due to inactivity of 90 days.

github-actions[bot] avatar Jul 05 '26 04:07 github-actions[bot]