feat: add get_delegation_tools() to household registry

Implements the agent-as-tool pattern in the registry:
- For members WITH an agent: returns delegation wrapper function
- For members WITHOUT an agent: returns raw tools directly

This reduces Tatlock's tool count from 16+ to ~3-5, preventing
cognitive overload and improving Ollama reliability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-13 11:23:10 +01:00
co-authored by Claude Opus 4.5
parent 54b6fcd7cc
commit 1a2e6392d2
+69
View File
@@ -200,6 +200,75 @@ class HouseholdRegistry:
return tools
def get_delegation_tools(self, names: list[str]) -> list[Any]:
"""
Get delegation wrapper tools for specified capabilities.
Instead of returning raw tools (which overloads the LLM),
returns wrapper functions that delegate to expert agents.
This implements the agent-as-tool pattern.
For members WITH an agent: returns delegation wrapper
For members WITHOUT an agent (e.g., tatlock_core): returns raw tools
Args:
names: List of member names to include
Returns:
List of delegation wrappers and/or raw tools
Example:
>>> # Steward recommends librarian + tatlock_core
>>> tools = registry.get_delegation_tools(["librarian", "tatlock_core"])
>>> # Returns: [delegate_to_librarian, calculate, datetime, ...]
>>> # Instead of: [hybrid_search, search_wiki, create_wiki_page, ... (16 tools)]
"""
from src.agents.delegation import delegate_to_librarian
# Map of expert names to their delegation wrappers
delegation_wrappers = {
"librarian": delegate_to_librarian,
# Future: "memory": delegate_to_memory,
# Future: "home_automation": delegate_to_home_automation,
}
tools = []
for name in names:
member = self._members.get(name)
if not member:
logger.warning(
"household_member_not_found",
requested_name=name,
available_names=list(self._members.keys()),
)
continue
# Check if this member has a delegation wrapper
if name in delegation_wrappers and member.agent is not None:
# Use delegation wrapper instead of raw tools
tools.append(delegation_wrappers[name])
logger.debug(
"delegation_wrapper_added",
member=name,
wrapper=delegation_wrappers[name].__name__,
)
else:
# No agent = direct tools (e.g., tatlock_core)
tools.extend(member.tools)
logger.debug(
"raw_tools_added",
member=name,
tool_count=len(member.tools),
)
logger.info(
"delegation_tools_created",
requested_members=names,
total_tools=len(tools),
)
return tools
def list_members(self) -> list[str]:
"""
List all registered member names.