From da5ca0c9035481127f3787fca6bd4babb9839ae9 Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Sun, 8 Jun 2025 14:01:21 -0700 Subject: [PATCH] Adjust post thread parent height from 80 to 60 Reduce post thread parent height to 60 --- bsky_utils.py | 2 +- register_tools.py | 52 +++++++++++++-------------- tools/blocks.py | 89 +++++++++++++++++++++++------------------------ 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/bsky_utils.py b/bsky_utils.py index 9a178d3..e069326 100644 --- a/bsky_utils.py +++ b/bsky_utils.py @@ -250,7 +250,7 @@ def get_post_thread(client: Client, uri: str) -> Optional[Dict[str, Any]]: The thread data or None if not found """ try: - thread = client.app.bsky.feed.get_post_thread({'uri': uri, 'parent_height': 80, 'depth': 10}) + thread = client.app.bsky.feed.get_post_thread({'uri': uri, 'parent_height': 60, 'depth': 10}) return thread except Exception as e: logger.error(f"Error fetching post thread: {e}") diff --git a/register_tools.py b/register_tools.py index cb73518..dde353c 100755 --- a/register_tools.py +++ b/register_tools.py @@ -16,14 +16,14 @@ from tools.functions import ( get_bluesky_feed, attach_user_blocks, detach_user_blocks, - update_user_blocks, + # update_user_blocks, ) # Import Pydantic models for args_schema from tools.search import SearchArgs from tools.post import PostArgs from tools.feed import FeedArgs -from tools.blocks import AttachUserBlockArgs, DetachUserBlockArgs, UpdateUserBlockArgs +from tools.blocks import AttachUserBlockArgs, DetachUserBlockArgs #, UpdateUserBlockArgs load_dotenv() logging.basicConfig(level=logging.INFO) @@ -63,18 +63,18 @@ TOOL_CONFIGS = [ "description": "Detach user-specific memory blocks from the agent. Blocks are preserved for later use.", "tags": ["memory", "blocks", "user"] }, - { - "func": update_user_blocks, - "args_schema": UpdateUserBlockArgs, - "description": "Update the content of user-specific memory blocks", - "tags": ["memory", "blocks", "user"] - }, + # { + # "func": update_user_blocks, + # "args_schema": UpdateUserBlockArgs, + # "description": "Update the content of user-specific memory blocks", + # "tags": ["memory", "blocks", "user"] + # }, ] def register_tools(agent_name: str = "void", tools: List[str] = None): """Register tools with a Letta agent. - + Args: agent_name: Name of the agent to attach tools to tools: List of tool names to register. If None, registers all tools. @@ -82,7 +82,7 @@ def register_tools(agent_name: str = "void", tools: List[str] = None): try: # Initialize Letta client with API key client = Letta(token=os.environ["LETTA_API_KEY"]) - + # Find the agent agents = client.agents.list() agent = None @@ -90,14 +90,14 @@ def register_tools(agent_name: str = "void", tools: List[str] = None): if a.name == agent_name: agent = a break - + if not agent: console.print(f"[red]Error: Agent '{agent_name}' not found[/red]") console.print("\nAvailable agents:") for a in agents: console.print(f" - {a.name}") return - + # Filter tools if specific ones requested tools_to_register = TOOL_CONFIGS if tools: @@ -105,18 +105,18 @@ def register_tools(agent_name: str = "void", tools: List[str] = None): if len(tools_to_register) != len(tools): missing = set(tools) - {t["func"].__name__ for t in tools_to_register} console.print(f"[yellow]Warning: Unknown tools: {missing}[/yellow]") - + # Create results table table = Table(title=f"Tool Registration for Agent '{agent_name}'") table.add_column("Tool", style="cyan") table.add_column("Status", style="green") table.add_column("Description") - + # Register each tool for tool_config in tools_to_register: func = tool_config["func"] tool_name = func.__name__ - + try: # Create or update the tool using the standalone function created_tool = client.tools.upsert_from_function( @@ -124,11 +124,11 @@ def register_tools(agent_name: str = "void", tools: List[str] = None): args_schema=tool_config["args_schema"], tags=tool_config["tags"] ) - + # Get current agent tools current_tools = client.agents.tools.list(agent_id=str(agent.id)) tool_names = [t.name for t in current_tools] - + # Check if already attached if created_tool.name in tool_names: table.add_row(tool_name, "Already Attached", tool_config["description"]) @@ -139,13 +139,13 @@ def register_tools(agent_name: str = "void", tools: List[str] = None): tool_id=str(created_tool.id) ) table.add_row(tool_name, "✓ Attached", tool_config["description"]) - + except Exception as e: table.add_row(tool_name, f"✗ Error: {str(e)}", tool_config["description"]) logger.error(f"Error registering tool {tool_name}: {e}") - + console.print(table) - + except Exception as e: console.print(f"[red]Error: {str(e)}[/red]") logger.error(f"Fatal error: {e}") @@ -157,29 +157,29 @@ def list_available_tools(): table.add_column("Tool Name", style="cyan") table.add_column("Description") table.add_column("Tags", style="dim") - + for tool_config in TOOL_CONFIGS: table.add_row( tool_config["func"].__name__, tool_config["description"], ", ".join(tool_config["tags"]) ) - + console.print(table) if __name__ == "__main__": import argparse - + parser = argparse.ArgumentParser(description="Register Void tools with a Letta agent") parser.add_argument("agent", nargs="?", default="void", help="Agent name (default: void)") parser.add_argument("--tools", nargs="+", help="Specific tools to register (default: all)") parser.add_argument("--list", action="store_true", help="List available tools") - + args = parser.parse_args() - + if args.list: list_available_tools() else: console.print(f"\n[bold]Registering tools for agent: {args.agent}[/bold]\n") - register_tools(args.agent, args.tools) \ No newline at end of file + register_tools(args.agent, args.tools) diff --git a/tools/blocks.py b/tools/blocks.py index cc0dde5..20f50d9 100644 --- a/tools/blocks.py +++ b/tools/blocks.py @@ -63,7 +63,6 @@ class AttachUserBlockTool(BaseTool): client.agents.blocks.attach( agent_id=str(agent_state.id), block_id=str(block.id), - enable_sleeptime=False, ) results.append(f"✓ {handle}: Block attached") @@ -132,61 +131,61 @@ class DetachUserBlockTool(BaseTool): return f"Error detaching user blocks: {str(e)}" -class UserBlockUpdate(BaseModel): - handle: str = Field(..., description="User's Bluesky handle (e.g., 'user.bsky.social')") - content: str = Field(..., description="New content for the user's memory block") +# class UserBlockUpdate(BaseModel): +# handle: str = Field(..., description="User's Bluesky handle (e.g., 'user.bsky.social')") +# content: str = Field(..., description="New content for the user's memory block") -class UpdateUserBlockArgs(BaseModel): - updates: List[UserBlockUpdate] = Field(..., description="List of user block updates") +# class UpdateUserBlockArgs(BaseModel): +# updates: List[UserBlockUpdate] = Field(..., description="List of user block updates") -class UpdateUserBlockTool(BaseTool): - name: str = "update_user_blocks" - args_schema: Type[BaseModel] = UpdateUserBlockArgs - description: str = "Update the content of user-specific memory blocks" - tags: List[str] = ["memory", "blocks", "user"] +# class UpdateUserBlockTool(BaseTool): +# name: str = "update_user_blocks" +# args_schema: Type[BaseModel] = UpdateUserBlockArgs +# description: str = "Update the content of user-specific memory blocks" +# tags: List[str] = ["memory", "blocks", "user"] - def run(self, updates: List[UserBlockUpdate]) -> str: - """Update user-specific memory blocks.""" - import os - from letta_client import Letta +# def run(self, updates: List[UserBlockUpdate]) -> str: +# """Update user-specific memory blocks.""" +# import os +# from letta_client import Letta - try: - client = Letta(token=os.environ["LETTA_API_KEY"]) - results = [] +# try: +# client = Letta(token=os.environ["LETTA_API_KEY"]) +# results = [] - for update in updates: - handle = update.handle - new_content = update.content - # Sanitize handle for block label - completely self-contained - clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_') - block_label = f"user_{clean_handle}" +# for update in updates: +# handle = update.handle +# new_content = update.content +# # Sanitize handle for block label - completely self-contained +# clean_handle = handle.lstrip('@').replace('.', '_').replace('-', '_').replace(' ', '_') +# block_label = f"user_{clean_handle}" - try: - # Find the block - blocks = client.blocks.list(label=block_label) - if not blocks or len(blocks) == 0: - results.append(f"✗ {handle}: Block not found - use attach_user_blocks first") - continue +# try: +# # Find the block +# blocks = client.blocks.list(label=block_label) +# if not blocks or len(blocks) == 0: +# results.append(f"✗ {handle}: Block not found - use attach_user_blocks first") +# continue - block = blocks[0] +# block = blocks[0] - # Update block content - updated_block = client.blocks.modify( - block_id=str(block.id), - value=new_content - ) +# # Update block content +# updated_block = client.blocks.modify( +# block_id=str(block.id), +# value=new_content +# ) - preview = new_content[:100] + "..." if len(new_content) > 100 else new_content - results.append(f"✓ {handle}: Updated - {preview}") +# preview = new_content[:100] + "..." if len(new_content) > 100 else new_content +# results.append(f"✓ {handle}: Updated - {preview}") - except Exception as e: - results.append(f"✗ {handle}: Error - {str(e)}") - logger.error(f"Error updating block for {handle}: {e}") +# except Exception as e: +# results.append(f"✗ {handle}: Error - {str(e)}") +# logger.error(f"Error updating block for {handle}: {e}") - return f"Update results:\n" + "\n".join(results) +# return f"Update results:\n" + "\n".join(results) - except Exception as e: - logger.error(f"Error updating user blocks: {e}") - return f"Error updating user blocks: {str(e)}" +# except Exception as e: +# logger.error(f"Error updating user blocks: {e}") +# return f"Error updating user blocks: {str(e)}" -- 2.51.2