From 4efa717796295763b7929870246bdc1d82f1d034 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Thu, 11 Dec 2025 21:55:17 +0100 Subject: [PATCH] fix: improve Steward delegation instructions for Librarian MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update Librarian capability description to highlight CREATE/UPDATE/SEARCH - Add specific Steward guidelines for wiki creation, updates, and research - Add dynamic time injection to user prompts for temporal awareness - Expand domains to include 'create', 'write', 'update' - Update test to match new capability description 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/agents/librarian/capability.py | 9 ++++++-- src/agents/steward/agent.py | 20 ++++++++++-------- src/core/preprocessing.py | 25 +++++++++++++++++++++-- tests/agents/librarian/test_capability.py | 9 +++++--- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/agents/librarian/capability.py b/src/agents/librarian/capability.py index 3a80904..2e3494d 100644 --- a/src/agents/librarian/capability.py +++ b/src/agents/librarian/capability.py @@ -21,8 +21,10 @@ LIBRARIAN_CAPABILITY = HouseholdCapability( role="The Librarian", category="research", description=( - "Research assistant providing knowledge search, wiki access, " - "semantic search, and knowledge graph exploration via library-desk API" + "Research and wiki management: can CREATE wiki pages about topics " + "(with automatic HybridRAG research), UPDATE existing pages, " + "SEARCH wiki/knowledge graph/web, and synthesize information. " + "Use for: 'create a page about X', 'update wiki', 'find info on X'" ), domains=[ "research", @@ -32,6 +34,9 @@ LIBRARIAN_CAPABILITY = HouseholdCapability( "documents", "search", "synthesis", + "create", + "write", + "update", ], cost="medium", # Multiple API calls to library-desk requires_network=True, # Needs library-desk API access diff --git a/src/agents/steward/agent.py b/src/agents/steward/agent.py index 2c34ba1..132896d 100644 --- a/src/agents/steward/agent.py +++ b/src/agents/steward/agent.py @@ -48,7 +48,7 @@ AVAILABLE HOUSEHOLD CAPABILITIES: {capabilities_text} YOUR TASK: -Analyze the user's query and recommend which capabilities are needed. +Analyze the user's query and recommend which capabilities are needed, with specific delegation instructions. {history_text} USER QUERY: {query} @@ -57,18 +57,22 @@ GUIDELINES: - Be conservative - only recommend truly necessary capabilities - Simple greetings/chat → no capabilities needed (conversational response only) - Math/calculations → tatlock_core -- Web searches → tatlock_core +- Quick web searches → tatlock_core - Time/date queries → tatlock_core +- Wiki creation ("create a page about X", "add X to wiki") → librarian with smart_create +- Wiki updates ("update the page", "add to dossier") → librarian with update +- Research queries ("find info", "what do we know about", "search for") → librarian with hybrid_search +- In-depth research, knowledge synthesis, document lookup → librarian with hybrid_search - If conversation history is relevant, note which previous turns matter - Assess complexity: simple (1 tool), moderate (2-3 tools), complex (multiple steps) -- If capabilities are missing, mention what would be needed -RESPOND WITH 2-3 SENTENCES: -1. Which capabilities (if any) are needed and why -2. Complexity assessment (simple/moderate/complex) -3. Any conversation context or missing capabilities +RESPOND WITH 2-4 SENTENCES: +1. Capability needed: name the capability and the specific action (e.g., "librarian to create a wiki page about CI/CD using smart_create") +2. Reason: brief explanation of why this capability handles the request +3. Complexity assessment (simple/moderate/complex) +4. Any relevant conversation context -Use capability names in your response (e.g., "tatlock_core for calculations"). +Be specific about what Tatlock should delegate - include the action verb (create, update, search, etc.). Plain text only - no JSON, no special formatting.""" diff --git a/src/core/preprocessing.py b/src/core/preprocessing.py index 5da48ed..fd9bdb0 100644 --- a/src/core/preprocessing.py +++ b/src/core/preprocessing.py @@ -4,6 +4,7 @@ Request preprocessing pipeline. Analyzes requests via the Steward and creates scoped toolsets for Tatlock. """ from dataclasses import dataclass +from datetime import datetime from typing import Any, Optional from src.agents.steward import analyze_request, format_steward_note @@ -14,6 +15,23 @@ from src.core.logging_config import get_logger logger = get_logger(__name__) +def _inject_temporal_context(request: str) -> str: + """ + Append current time context to user request. + + Provides Tatlock with temporal awareness for time-sensitive queries. + + Args: + request: Original user request + + Returns: + Request with appended time context + """ + now = datetime.now() + time_str = now.strftime("%Y-%m-%d %H:%M") + return f"{request}\n\n[Current time: {time_str}]" + + @dataclass class EnrichedRequest: """ @@ -65,6 +83,9 @@ async def preprocess_request( >>> print(len(enriched.scoped_tools)) 5 # All tatlock_core tools """ + # Inject temporal context for time-aware processing + enriched_request = _inject_temporal_context(user_request) + logger.info( "preprocessing_request", request_preview=user_request[:100], @@ -74,7 +95,7 @@ async def preprocess_request( # Call Steward with full conversation history recommendation = await analyze_request( - user_request, + enriched_request, conversation_history=conversation_history, conversation_id=conversation_id, ) @@ -97,7 +118,7 @@ async def preprocess_request( ) return EnrichedRequest( - original_request=user_request, + original_request=enriched_request, steward_note=steward_note, scoped_tools=scoped_tools, recommendation=recommendation, diff --git a/tests/agents/librarian/test_capability.py b/tests/agents/librarian/test_capability.py index 8dca733..2c7495f 100644 --- a/tests/agents/librarian/test_capability.py +++ b/tests/agents/librarian/test_capability.py @@ -113,9 +113,12 @@ class TestLibrarianRegistration: class TestCapabilityDescription: """Tests for capability description.""" - def test_description_mentions_library_desk(self): - """Test description mentions library-desk API.""" - assert "library-desk" in LIBRARIAN_CAPABILITY.description.lower() + def test_description_mentions_wiki_capabilities(self): + """Test description mentions wiki read/write capabilities.""" + desc = LIBRARIAN_CAPABILITY.description.lower() + assert "create" in desc + assert "update" in desc + assert "search" in desc def test_description_mentions_search(self): """Test description mentions search capability."""