Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/basic_open_agent_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Basic Open Agent Tools.

An open foundational toolkit providing essential components for building AI agents
from typing import List
with minimal dependencies for local (non-HTTP/API) actions.
"""

Expand All @@ -10,21 +9,29 @@
__version__ = "0.1.0"

# Modular structure
from . import exceptions, file_system, text, types

# Helper functions for tool management
from .helpers import (
get_tool_info,
list_all_available_tools,
load_all_filesystem_tools,
load_all_text_tools,
merge_tool_lists,
)

# Future modules (placeholder imports for when modules are implemented)
# from . import text
# from . import system
# from . import network
# from . import data
# from . import crypto
# from . import utilities
# Common infrastructure
from . import exceptions, file_system, types

__all__ = [
# Modular structure
__all__: List[str] = [
# Implemented modules
"file_system",
"text",
# Future modules (uncomment when implemented)
# "text",
# "system",
# "network",
# "data",
Expand All @@ -33,4 +40,10 @@
# Common infrastructure
"exceptions",
"types",
# Helper functions
"load_all_filesystem_tools",
"load_all_text_tools",
"merge_tool_lists",
"get_tool_info",
"list_all_available_tools",
]
142 changes: 142 additions & 0 deletions src/basic_open_agent_tools/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""Helper functions for loading and managing tool collections."""

import inspect
from typing import Any, Callable, Dict, List, Union

from . import file_system, text


def load_all_filesystem_tools() -> List[Callable[..., Any]]:
"""Load all file system tools as a list of callable functions.

Returns:
List of all file system tool functions

Example:
>>> fs_tools = load_all_filesystem_tools()
>>> len(fs_tools) > 0
True
"""
tools = []

# Get all functions from file_system module
for name in file_system.__all__:
func = getattr(file_system, name)
if callable(func):
tools.append(func)

return tools


def load_all_text_tools() -> List[Callable[..., Any]]:
"""Load all text processing tools as a list of callable functions.

Returns:
List of all text processing tool functions

Example:
>>> text_tools = load_all_text_tools()
>>> len(text_tools) > 0
True
"""
tools = []

# Get all functions from text module
for name in text.__all__:
func = getattr(text, name)
if callable(func):
tools.append(func)

return tools


def merge_tool_lists(
*args: Union[List[Callable[..., Any]], Callable[..., Any]],
) -> List[Callable[..., Any]]:
"""Merge multiple tool lists and individual functions into a single list.

Args:
*args: Tool lists (List[Callable]) and/or individual functions (Callable)

Returns:
Combined list of all tools

Raises:
TypeError: If any argument is not a list of callables or a callable

Example:
>>> def custom_tool(x): return x
>>> fs_tools = load_all_filesystem_tools()
>>> text_tools = load_all_text_tools()
>>> all_tools = merge_tool_lists(fs_tools, text_tools, custom_tool)
>>> custom_tool in all_tools
True
"""
merged = []

for arg in args:
if callable(arg):
# Single function
merged.append(arg)
elif isinstance(arg, list):
# List of functions
for item in arg:
if not callable(item):
raise TypeError(
f"All items in tool lists must be callable, got {type(item)}"
)
merged.append(item)
else:
raise TypeError(
f"Arguments must be callable or list of callables, got {type(arg)}"
)

return merged


def get_tool_info(tool: Callable[..., Any]) -> Dict[str, Any]:
"""Get information about a tool function.

Args:
tool: The tool function to inspect

Returns:
Dictionary containing tool information (name, docstring, signature)

Example:
>>> from basic_open_agent_tools.text import clean_whitespace
>>> info = get_tool_info(clean_whitespace)
>>> info['name']
'clean_whitespace'
"""
if not callable(tool):
raise TypeError("Tool must be callable")

sig = inspect.signature(tool)

return {
"name": tool.__name__,
"docstring": tool.__doc__ or "",
"signature": str(sig),
"module": getattr(tool, "__module__", "unknown"),
"parameters": list(sig.parameters.keys()),
}


def list_all_available_tools() -> Dict[str, List[Dict[str, Any]]]:
"""List all available tools organized by category.

Returns:
Dictionary with tool categories as keys and lists of tool info as values

Example:
>>> tools = list_all_available_tools()
>>> 'file_system' in tools
True
>>> 'text' in tools
True
"""
return {
"file_system": [get_tool_info(tool) for tool in load_all_filesystem_tools()],
"text": [get_tool_info(tool) for tool in load_all_text_tools()],
}
35 changes: 33 additions & 2 deletions src/basic_open_agent_tools/text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
"""Text tools for AI agents.

This module is not yet implemented. See TODO.md for planned functionality.
This module provides text processing and manipulation tools organized into logical submodules:

- processing: Core text cleaning, normalization, and formatting
"""

from typing import List

__all__: List[str] = [] # No functions available yet
# Import all functions from submodules
from .processing import (
clean_whitespace,
extract_sentences,
join_with_oxford_comma,
normalize_line_endings,
normalize_unicode,
smart_split_lines,
strip_html_tags,
to_camel_case,
to_snake_case,
to_title_case,
)

# Re-export all functions at module level for convenience
__all__: List[str] = [
# Text cleaning and normalization
"clean_whitespace",
"normalize_line_endings",
"strip_html_tags",
"normalize_unicode",
# Case conversion
"to_snake_case",
"to_camel_case",
"to_title_case",
# Text splitting and manipulation
"smart_split_lines",
"extract_sentences",
"join_with_oxford_comma",
]
Loading