friday-framework-tools 0.1.0a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. friday_framework_tools-0.1.0a0/.gitignore +24 -0
  2. friday_framework_tools-0.1.0a0/PKG-INFO +83 -0
  3. friday_framework_tools-0.1.0a0/README.md +26 -0
  4. friday_framework_tools-0.1.0a0/pyproject.toml +107 -0
  5. friday_framework_tools-0.1.0a0/src/friday_tools/__init__.py +75 -0
  6. friday_framework_tools-0.1.0a0/src/friday_tools/adapters/__init__.py +33 -0
  7. friday_framework_tools-0.1.0a0/src/friday_tools/adapters/anthropic.py +190 -0
  8. friday_framework_tools-0.1.0a0/src/friday_tools/adapters/langchain.py +145 -0
  9. friday_framework_tools-0.1.0a0/src/friday_tools/adapters/openai.py +226 -0
  10. friday_framework_tools-0.1.0a0/src/friday_tools/archive/__init__.py +6 -0
  11. friday_framework_tools-0.1.0a0/src/friday_tools/archive/archive.py +132 -0
  12. friday_framework_tools-0.1.0a0/src/friday_tools/base.py +224 -0
  13. friday_framework_tools-0.1.0a0/src/friday_tools/code/__init__.py +11 -0
  14. friday_framework_tools-0.1.0a0/src/friday_tools/code/analyze.py +107 -0
  15. friday_framework_tools-0.1.0a0/src/friday_tools/code/format.py +155 -0
  16. friday_framework_tools-0.1.0a0/src/friday_tools/codegen/__init__.py +16 -0
  17. friday_framework_tools-0.1.0a0/src/friday_tools/codegen/prompts.py +103 -0
  18. friday_framework_tools-0.1.0a0/src/friday_tools/codegen/tool.py +206 -0
  19. friday_framework_tools-0.1.0a0/src/friday_tools/data/__init__.py +33 -0
  20. friday_framework_tools-0.1.0a0/src/friday_tools/data/csv_tools.py +163 -0
  21. friday_framework_tools-0.1.0a0/src/friday_tools/data/json_tools.py +179 -0
  22. friday_framework_tools-0.1.0a0/src/friday_tools/data/toml_tools.py +120 -0
  23. friday_framework_tools-0.1.0a0/src/friday_tools/data/xml_tools.py +137 -0
  24. friday_framework_tools-0.1.0a0/src/friday_tools/data/yaml_tools.py +110 -0
  25. friday_framework_tools-0.1.0a0/src/friday_tools/definition.py +307 -0
  26. friday_framework_tools-0.1.0a0/src/friday_tools/encoding/__init__.py +20 -0
  27. friday_framework_tools-0.1.0a0/src/friday_tools/encoding/encoding.py +159 -0
  28. friday_framework_tools-0.1.0a0/src/friday_tools/execution/__init__.py +7 -0
  29. friday_framework_tools-0.1.0a0/src/friday_tools/execution/python.py +65 -0
  30. friday_framework_tools-0.1.0a0/src/friday_tools/execution/unsandboxed_python.py +131 -0
  31. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/__init__.py +102 -0
  32. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/code_chunker.py +550 -0
  33. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/directory.py +487 -0
  34. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/operations.py +280 -0
  35. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/read.py +397 -0
  36. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/__init__.py +54 -0
  37. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/base.py +92 -0
  38. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/csv_reader.py +285 -0
  39. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/docx_reader.py +187 -0
  40. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/encoding.py +285 -0
  41. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/factory.py +378 -0
  42. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/pdf_reader.py +194 -0
  43. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/readers/xlsx_reader.py +323 -0
  44. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/smart_read.py +692 -0
  45. friday_framework_tools-0.1.0a0/src/friday_tools/filesystem/write.py +617 -0
  46. friday_framework_tools-0.1.0a0/src/friday_tools/finance/__init__.py +21 -0
  47. friday_framework_tools-0.1.0a0/src/friday_tools/finance/massive.py +321 -0
  48. friday_framework_tools-0.1.0a0/src/friday_tools/git/__init__.py +25 -0
  49. friday_framework_tools-0.1.0a0/src/friday_tools/git/branches.py +168 -0
  50. friday_framework_tools-0.1.0a0/src/friday_tools/git/staging.py +175 -0
  51. friday_framework_tools-0.1.0a0/src/friday_tools/git/status.py +207 -0
  52. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/__init__.py +93 -0
  53. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/calendar.py +56 -0
  54. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/database.py +33 -0
  55. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/email.py +34 -0
  56. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/moltbook.py +552 -0
  57. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/slack.py +33 -0
  58. friday_framework_tools-0.1.0a0/src/friday_tools/integrations/webhook.py +30 -0
  59. friday_framework_tools-0.1.0a0/src/friday_tools/manifest.py +251 -0
  60. friday_framework_tools-0.1.0a0/src/friday_tools/math/__init__.py +6 -0
  61. friday_framework_tools-0.1.0a0/src/friday_tools/math/math.py +191 -0
  62. friday_framework_tools-0.1.0a0/src/friday_tools/memory/__init__.py +0 -0
  63. friday_framework_tools-0.1.0a0/src/friday_tools/memory/inspection.py +156 -0
  64. friday_framework_tools-0.1.0a0/src/friday_tools/memory/lifecycle.py +57 -0
  65. friday_framework_tools-0.1.0a0/src/friday_tools/memory/maintenance.py +122 -0
  66. friday_framework_tools-0.1.0a0/src/friday_tools/protocols.py +23 -0
  67. friday_framework_tools-0.1.0a0/src/friday_tools/registry.py +312 -0
  68. friday_framework_tools-0.1.0a0/src/friday_tools/sandbox.py +340 -0
  69. friday_framework_tools-0.1.0a0/src/friday_tools/shell/__init__.py +35 -0
  70. friday_framework_tools-0.1.0a0/src/friday_tools/shell/command.py +428 -0
  71. friday_framework_tools-0.1.0a0/src/friday_tools/shell/execute.py +223 -0
  72. friday_framework_tools-0.1.0a0/src/friday_tools/shell/system.py +311 -0
  73. friday_framework_tools-0.1.0a0/src/friday_tools/system/__init__.py +0 -0
  74. friday_framework_tools-0.1.0a0/src/friday_tools/system/health.py +60 -0
  75. friday_framework_tools-0.1.0a0/src/friday_tools/system/transcript.py +79 -0
  76. friday_framework_tools-0.1.0a0/src/friday_tools/text/__init__.py +23 -0
  77. friday_framework_tools-0.1.0a0/src/friday_tools/text/convert.py +120 -0
  78. friday_framework_tools-0.1.0a0/src/friday_tools/text/search.py +96 -0
  79. friday_framework_tools-0.1.0a0/src/friday_tools/text/transform.py +147 -0
  80. friday_framework_tools-0.1.0a0/src/friday_tools/utility/__init__.py +15 -0
  81. friday_framework_tools-0.1.0a0/src/friday_tools/utility/datetime.py +144 -0
  82. friday_framework_tools-0.1.0a0/src/friday_tools/utility/echo.py +42 -0
  83. friday_framework_tools-0.1.0a0/src/friday_tools/web/__init__.py +103 -0
  84. friday_framework_tools-0.1.0a0/src/friday_tools/web/client.py +204 -0
  85. friday_framework_tools-0.1.0a0/src/friday_tools/web/config.py +179 -0
  86. friday_framework_tools-0.1.0a0/src/friday_tools/web/fetch.py +372 -0
  87. friday_framework_tools-0.1.0a0/src/friday_tools/web/http.py +660 -0
  88. friday_framework_tools-0.1.0a0/src/friday_tools/web/reader.py +405 -0
  89. friday_framework_tools-0.1.0a0/src/friday_tools/web/search.py +352 -0
  90. friday_framework_tools-0.1.0a0/src/friday_tools/web/serper.py +420 -0
  91. friday_framework_tools-0.1.0a0/src/friday_tools/web/validators.py +173 -0
  92. friday_framework_tools-0.1.0a0/tests_tools/__init__.py +2 -0
  93. friday_framework_tools-0.1.0a0/tests_tools/test_base.py +66 -0
  94. friday_framework_tools-0.1.0a0/tests_tools/test_code_chunker.py +374 -0
  95. friday_framework_tools-0.1.0a0/tests_tools/test_command_execute.py +594 -0
  96. friday_framework_tools-0.1.0a0/tests_tools/test_filesystem_readers.py +349 -0
  97. friday_framework_tools-0.1.0a0/tests_tools/test_memory_tools.py +211 -0
  98. friday_framework_tools-0.1.0a0/tests_tools/test_moltbook_tools.py +40 -0
  99. friday_framework_tools-0.1.0a0/tests_tools/test_protocols.py +78 -0
  100. friday_framework_tools-0.1.0a0/tests_tools/test_smart_read.py +552 -0
  101. friday_framework_tools-0.1.0a0/tests_tools/test_system_tools.py +87 -0
  102. friday_framework_tools-0.1.0a0/tests_tools/test_web_config.py +209 -0
  103. friday_framework_tools-0.1.0a0/tests_tools/test_web_reader.py +313 -0
  104. friday_framework_tools-0.1.0a0/tests_tools/test_web_validators.py +135 -0
@@ -0,0 +1,24 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .env
4
+ .venv/
5
+ .idea/
6
+ .vscode/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ chroma_db/
11
+ .friday/
12
+ /vector/
13
+ /exports/
14
+ tests/integration/memory/vector/*/
15
+ tests/integration/memory/vector/backups/*/
16
+ tests/integration/memory/vector/reorganization_logs/*
17
+ *.gpickle
18
+ keys.txt
19
+ experiments/*/config/runtime.local.yaml
20
+ experiments/*/artifacts/*
21
+ !experiments/*/artifacts/.gitkeep
22
+ scripts/source-friday-chat-example-env.sh
23
+ scripts/pypi.sh
24
+ /docs/reference/PyPI-Recovery-Codes-cichuck-2026-07-20T15_36_49.709334.txt
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: friday-framework-tools
3
+ Version: 0.1.0a0
4
+ Summary: Comprehensive tool library for AI agents
5
+ Project-URL: Homepage, https://github.com/CIChuck/agent-framework
6
+ Project-URL: Repository, https://github.com/CIChuck/agent-framework
7
+ Project-URL: Issues, https://github.com/CIChuck/agent-framework/issues
8
+ Project-URL: Documentation, https://github.com/CIChuck/agent-framework/tree/main/docs
9
+ Project-URL: Source, https://github.com/CIChuck/agent-framework/tree/main/packages/friday-tools
10
+ Author: Friday Team
11
+ License-Expression: MIT
12
+ Keywords: agents,ai,automation,llm,tools
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: beautifulsoup4>=4.12.0
15
+ Requires-Dist: charset-normalizer>=3.3.0
16
+ Requires-Dist: friday-framework-core==0.1.0a0
17
+ Requires-Dist: gitpython>=3.1.0
18
+ Requires-Dist: httpx>=0.25.0
19
+ Requires-Dist: jinja2>=3.1.0
20
+ Requires-Dist: jsonpath-ng>=1.5.0
21
+ Requires-Dist: lxml>=4.9.0
22
+ Requires-Dist: markdownify>=0.11.0
23
+ Requires-Dist: psutil>=7.2.1
24
+ Requires-Dist: python-dateutil>=2.8.0
25
+ Requires-Dist: pyyaml>=6.0.0
26
+ Provides-Extra: all-adapters
27
+ Requires-Dist: anthropic>=0.25.0; extra == 'all-adapters'
28
+ Requires-Dist: langchain-core>=0.1.0; extra == 'all-adapters'
29
+ Requires-Dist: openai>=1.0.0; extra == 'all-adapters'
30
+ Provides-Extra: all-formats
31
+ Requires-Dist: openpyxl>=3.1; extra == 'all-formats'
32
+ Requires-Dist: pypdf>=4.0; extra == 'all-formats'
33
+ Requires-Dist: python-docx>=1.0; extra == 'all-formats'
34
+ Provides-Extra: anthropic
35
+ Requires-Dist: anthropic>=0.25.0; extra == 'anthropic'
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
38
+ Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
39
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
40
+ Requires-Dist: respx>=0.20.0; extra == 'dev'
41
+ Provides-Extra: documents
42
+ Requires-Dist: pypdf>=4.0; extra == 'documents'
43
+ Requires-Dist: python-docx>=1.0; extra == 'documents'
44
+ Provides-Extra: finance
45
+ Requires-Dist: friday-framework-finance==0.1.0a0; extra == 'finance'
46
+ Provides-Extra: langchain
47
+ Requires-Dist: langchain-core>=0.1.0; extra == 'langchain'
48
+ Provides-Extra: moltbook
49
+ Requires-Dist: friday-framework-moltbook==0.1.0a0; extra == 'moltbook'
50
+ Provides-Extra: openai
51
+ Requires-Dist: openai>=1.0.0; extra == 'openai'
52
+ Provides-Extra: sandbox
53
+ Requires-Dist: friday-framework-sandbox==0.1.0a0; extra == 'sandbox'
54
+ Provides-Extra: spreadsheets
55
+ Requires-Dist: openpyxl>=3.1; extra == 'spreadsheets'
56
+ Description-Content-Type: text/markdown
57
+
58
+ # Friday Framework Tools
59
+
60
+ Tool catalog package for the Friday Framework.
61
+
62
+ This package contains filesystem, shell, web, git, data, text, document,
63
+ memory, finance, code, and integration tools exposed through Friday tool
64
+ contracts.
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ pip install friday-framework-tools
70
+ ```
71
+
72
+ Optional integrations are available through extras such as `sandbox`,
73
+ `finance`, `moltbook`, `documents`, `spreadsheets`, and adapter extras.
74
+
75
+ ## Import Package
76
+
77
+ ```python
78
+ import friday_tools
79
+ ```
80
+
81
+ ## License
82
+
83
+ MIT
@@ -0,0 +1,26 @@
1
+ # Friday Framework Tools
2
+
3
+ Tool catalog package for the Friday Framework.
4
+
5
+ This package contains filesystem, shell, web, git, data, text, document,
6
+ memory, finance, code, and integration tools exposed through Friday tool
7
+ contracts.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install friday-framework-tools
13
+ ```
14
+
15
+ Optional integrations are available through extras such as `sandbox`,
16
+ `finance`, `moltbook`, `documents`, `spreadsheets`, and adapter extras.
17
+
18
+ ## Import Package
19
+
20
+ ```python
21
+ import friday_tools
22
+ ```
23
+
24
+ ## License
25
+
26
+ MIT
@@ -0,0 +1,107 @@
1
+ [project]
2
+ name = "friday-framework-tools"
3
+ version = "0.1.0a0"
4
+ description = "Comprehensive tool library for AI agents"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = "MIT"
8
+ authors = [{ name = "Friday Team" }]
9
+ keywords = ["ai", "agents", "tools", "llm", "automation"]
10
+
11
+ dependencies = [
12
+ # Core protocols
13
+ "friday-framework-core==0.1.0a0",
14
+ # HTTP & Web
15
+ "httpx>=0.25.0",
16
+ "beautifulsoup4>=4.12.0",
17
+ "markdownify>=0.11.0",
18
+ "lxml>=4.9.0",
19
+ # Data formats
20
+ "pyyaml>=6.0.0",
21
+ "jsonpath-ng>=1.5.0",
22
+ # Text & Templates
23
+ "jinja2>=3.1.0",
24
+ # Git
25
+ "gitpython>=3.1.0",
26
+ # Math & Dates
27
+ "python-dateutil>=2.8.0",
28
+ "psutil>=7.2.1",
29
+ # Encoding detection
30
+ "charset-normalizer>=3.3.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/CIChuck/agent-framework"
35
+ Repository = "https://github.com/CIChuck/agent-framework"
36
+ Issues = "https://github.com/CIChuck/agent-framework/issues"
37
+ Documentation = "https://github.com/CIChuck/agent-framework/tree/main/docs"
38
+ Source = "https://github.com/CIChuck/agent-framework/tree/main/packages/friday-tools"
39
+
40
+ [project.optional-dependencies]
41
+ sandbox = [
42
+ "friday-framework-sandbox==0.1.0a0",
43
+ ]
44
+ finance = [
45
+ "friday-framework-finance==0.1.0a0",
46
+ ]
47
+ moltbook = [
48
+ "friday-framework-moltbook==0.1.0a0",
49
+ ]
50
+ dev = [
51
+ "pytest>=8.0.0",
52
+ "pytest-asyncio>=0.23.0",
53
+ "respx>=0.20.0",
54
+ "pytest-mock>=3.10.0",
55
+ ]
56
+
57
+ # Framework adapters (optional - import only when used)
58
+ langchain = ["langchain-core>=0.1.0"]
59
+ anthropic = ["anthropic>=0.25.0"]
60
+ openai = ["openai>=1.0.0"]
61
+ all-adapters = [
62
+ "friday-framework-tools[langchain]==0.1.0a0",
63
+ "friday-framework-tools[anthropic]==0.1.0a0",
64
+ "friday-framework-tools[openai]==0.1.0a0",
65
+ ]
66
+
67
+ # Document format readers (optional)
68
+ documents = [
69
+ "pypdf>=4.0",
70
+ "python-docx>=1.0",
71
+ ]
72
+
73
+ # Spreadsheet readers (optional)
74
+ spreadsheets = [
75
+ "openpyxl>=3.1",
76
+ ]
77
+
78
+ # All file format support
79
+ all-formats = [
80
+ "friday-framework-tools[documents]==0.1.0a0",
81
+ "friday-framework-tools[spreadsheets]==0.1.0a0",
82
+ ]
83
+
84
+ [build-system]
85
+ requires = ["hatchling"]
86
+ build-backend = "hatchling.build"
87
+
88
+ [tool.hatch.build.targets.wheel]
89
+ packages = ["src/friday_tools"]
90
+
91
+ [tool.uv.sources]
92
+ friday-framework-core = { workspace = true }
93
+ friday-framework-sandbox = { workspace = true }
94
+ friday-framework-moltbook = { workspace = true }
95
+ friday-framework-finance = { workspace = true }
96
+
97
+ [tool.pytest.ini_options]
98
+ testpaths = ["tests_tools"]
99
+ asyncio_mode = "auto"
100
+ asyncio_default_fixture_loop_scope = "function"
101
+
102
+ [tool.ruff]
103
+ line-length = 88
104
+ target-version = "py310"
105
+
106
+ [tool.ruff.lint]
107
+ select = ["E", "F", "I", "UP", "B", "SIM"]
@@ -0,0 +1,75 @@
1
+ # mypy: ignore-errors
2
+ """
3
+ Friday Tools - Comprehensive tool library for AI agents.
4
+
5
+ This package provides a wide variety of tools for AI agents including
6
+ filesystem operations, web access, data format handling, git operations,
7
+ and more.
8
+
9
+ Ref: docs/reference/specs/tool_specification.md
10
+ """
11
+
12
+ from .base import FridayTool, ToolResult
13
+ from .definition import BaseTool, FunctionTool, create_tool
14
+
15
+ # Smart file reading
16
+ from .filesystem.smart_read import SmartFileReadTool
17
+
18
+ # Finance tools
19
+ from .finance import (
20
+ GetCryptoDataTool,
21
+ GetMarketDataTool,
22
+ GetTechnicalAnalysisTool,
23
+ MassiveBaseTool,
24
+ )
25
+ from .manifest import ToolManifest
26
+ from .protocols import ToolAdapter, ToolDefinition, ToolRegistry
27
+ from .registry import DefaultToolRegistry, get_default_registry, tool
28
+ from .sandbox import (
29
+ CommandSecurityError,
30
+ FilesystemSandbox,
31
+ PathSecurityError,
32
+ SecurityError,
33
+ ShellSandbox,
34
+ )
35
+
36
+ # Utility tools
37
+ from .utility import EchoTool, GetCurrentDateTimeTool
38
+
39
+ __all__ = [
40
+ # Protocols
41
+ "ToolDefinition",
42
+ "ToolAdapter",
43
+ "ToolRegistry",
44
+ # Base classes
45
+ "BaseTool",
46
+ "FunctionTool",
47
+ "FridayTool",
48
+ "ToolResult",
49
+ # Registry
50
+ "DefaultToolRegistry",
51
+ "get_default_registry",
52
+ # Manifest
53
+ "ToolManifest",
54
+ # Decorators
55
+ "tool",
56
+ "create_tool",
57
+ # Security
58
+ "FilesystemSandbox",
59
+ "ShellSandbox",
60
+ "SecurityError",
61
+ "PathSecurityError",
62
+ "CommandSecurityError",
63
+ # Utility tools
64
+ "GetCurrentDateTimeTool",
65
+ "EchoTool",
66
+ # Smart file reading
67
+ "SmartFileReadTool",
68
+ # Finance tools
69
+ "MassiveBaseTool",
70
+ "GetMarketDataTool",
71
+ "GetCryptoDataTool",
72
+ "GetTechnicalAnalysisTool",
73
+ ]
74
+
75
+ __version__ = "0.1.0"
@@ -0,0 +1,33 @@
1
+ # mypy: ignore-errors
2
+ """
3
+ Framework adapters for converting external tools to Friday format.
4
+
5
+ Ref: docs/reference/specs/tool_specification.md - Section 6: Adapters
6
+
7
+ These adapters allow tools from other frameworks (LangChain, Anthropic,
8
+ OpenAI) to be used within the Friday framework.
9
+
10
+ Optional Dependencies:
11
+ - langchain-core: For LangChainToolAdapter
12
+ - anthropic: For AnthropicToolAdapter
13
+ - openai: For OpenAIToolAdapter
14
+
15
+ Example:
16
+ ```python
17
+ from friday_tools.adapters import LangChainToolAdapter
18
+ from langchain_community.tools import DuckDuckGoSearchRun
19
+
20
+ adapter = LangChainToolAdapter()
21
+ friday_tool = adapter.adapt(DuckDuckGoSearchRun())
22
+ ```
23
+ """
24
+
25
+ from .anthropic import AnthropicToolAdapter
26
+ from .langchain import LangChainToolAdapter
27
+ from .openai import OpenAIToolAdapter
28
+
29
+ __all__ = [
30
+ "LangChainToolAdapter",
31
+ "AnthropicToolAdapter",
32
+ "OpenAIToolAdapter",
33
+ ]
@@ -0,0 +1,190 @@
1
+ # mypy: ignore-errors
2
+ """
3
+ Anthropic tool adapter.
4
+
5
+ Ref: docs/reference/specs/tool_specification.md - Section 6.2: Anthropic Adapter
6
+
7
+ Converts Anthropic tool definitions (dict format) to Friday's ToolDefinition.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from collections.abc import Callable
14
+ from typing import Any
15
+
16
+ from ..definition import BaseTool
17
+ from ..protocols import ToolDefinition
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ class AnthropicToolWrapper(BaseTool):
23
+ """Wraps an Anthropic tool definition as a Friday tool."""
24
+
25
+ def __init__(
26
+ self,
27
+ tool_def: dict[str, Any],
28
+ handler: Callable[..., Any] | None = None,
29
+ ):
30
+ """
31
+ Initialize wrapper.
32
+
33
+ Args:
34
+ tool_def: Anthropic tool definition dict.
35
+ handler: Optional function to execute the tool.
36
+ """
37
+ self._tool_def = tool_def
38
+ self._handler = handler
39
+
40
+ @property
41
+ def name(self) -> str:
42
+ return self._tool_def["name"]
43
+
44
+ @property
45
+ def description(self) -> str:
46
+ return self._tool_def.get("description", f"Execute {self.name}")
47
+
48
+ @property
49
+ def parameters_schema(self) -> dict[str, Any]:
50
+ """Get input schema from Anthropic format."""
51
+ return self._tool_def.get(
52
+ "input_schema",
53
+ {
54
+ "type": "object",
55
+ "properties": {},
56
+ },
57
+ )
58
+
59
+ async def execute(self, **kwargs: Any) -> str:
60
+ """Execute the tool using the provided handler."""
61
+ if self._handler is None:
62
+ raise RuntimeError(
63
+ f"No handler provided for tool '{self.name}'. "
64
+ "Anthropic tools require a handler function."
65
+ )
66
+
67
+ import asyncio
68
+ import inspect
69
+
70
+ if inspect.iscoroutinefunction(self._handler):
71
+ result = await self._handler(**kwargs)
72
+ else:
73
+ loop = asyncio.get_event_loop()
74
+ result = await loop.run_in_executor(None, lambda: self._handler(**kwargs))
75
+
76
+ return str(result) if result is not None else ""
77
+
78
+
79
+ class AnthropicToolAdapter:
80
+ """
81
+ Adapts Anthropic tool definitions to Friday ToolDefinition.
82
+
83
+ Anthropic tools are defined as dictionaries with the following format:
84
+ ```python
85
+ {
86
+ "name": "get_weather",
87
+ "description": "Get the current weather",
88
+ "input_schema": {
89
+ "type": "object",
90
+ "properties": {
91
+ "location": {"type": "string", "description": "City name"}
92
+ },
93
+ "required": ["location"]
94
+ }
95
+ }
96
+ ```
97
+
98
+ Example:
99
+ ```python
100
+ adapter = AnthropicToolAdapter()
101
+
102
+ anthropic_tool = {
103
+ "name": "calculator",
104
+ "description": "Evaluate math expressions",
105
+ "input_schema": {
106
+ "type": "object",
107
+ "properties": {
108
+ "expression": {"type": "string"}
109
+ },
110
+ "required": ["expression"]
111
+ }
112
+ }
113
+
114
+ def calc_handler(expression: str) -> str:
115
+ return str(eval(expression))
116
+
117
+ friday_tool = adapter.adapt(anthropic_tool, handler=calc_handler)
118
+ ```
119
+ """
120
+
121
+ def adapt(
122
+ self,
123
+ external_tool: dict[str, Any],
124
+ handler: Callable[..., Any] | None = None,
125
+ ) -> ToolDefinition:
126
+ """
127
+ Convert an Anthropic tool definition to Friday's ToolDefinition.
128
+
129
+ Args:
130
+ external_tool: Anthropic tool definition dict.
131
+ handler: Function to execute when the tool is called.
132
+
133
+ Returns:
134
+ Friday ToolDefinition (actually an AnthropicToolWrapper).
135
+ """
136
+ self._validate_anthropic_tool(external_tool)
137
+ return AnthropicToolWrapper(external_tool, handler=handler)
138
+
139
+ def adapt_many(
140
+ self,
141
+ tools: list[dict[str, Any]],
142
+ handlers: dict[str, Callable[..., Any]] | None = None,
143
+ ) -> list[ToolDefinition]:
144
+ """
145
+ Convert multiple Anthropic tool definitions.
146
+
147
+ Args:
148
+ tools: List of Anthropic tool definition dicts.
149
+ handlers: Optional dict mapping tool names to handler functions.
150
+
151
+ Returns:
152
+ List of Friday ToolDefinition instances.
153
+ """
154
+ handlers = handlers or {}
155
+ return [self.adapt(tool, handler=handlers.get(tool["name"])) for tool in tools]
156
+
157
+ def _validate_anthropic_tool(self, tool: dict[str, Any]) -> None:
158
+ """Validate that the dict is a valid Anthropic tool definition."""
159
+ if not isinstance(tool, dict):
160
+ raise TypeError(
161
+ f"Expected dict for Anthropic tool, got {type(tool).__name__}"
162
+ )
163
+
164
+ if "name" not in tool:
165
+ raise ValueError("Anthropic tool must have 'name' field")
166
+
167
+ @staticmethod
168
+ def from_anthropic_response(
169
+ response_tools: list[dict[str, Any]],
170
+ ) -> list[dict[str, Any]]:
171
+ """
172
+ Extract tool definitions from an Anthropic API response.
173
+
174
+ This is useful when you want to re-use tools defined by
175
+ an Anthropic API response.
176
+
177
+ Args:
178
+ response_tools: List of tool dicts from Anthropic API.
179
+
180
+ Returns:
181
+ List of tool definitions in Anthropic format.
182
+ """
183
+ return [
184
+ {
185
+ "name": t["name"],
186
+ "description": t.get("description", ""),
187
+ "input_schema": t.get("input_schema", {}),
188
+ }
189
+ for t in response_tools
190
+ ]
@@ -0,0 +1,145 @@
1
+ # mypy: ignore-errors
2
+ """
3
+ LangChain tool adapter.
4
+
5
+ Ref: docs/reference/specs/tool_specification.md - Section 6.1: LangChain Adapter
6
+
7
+ Converts LangChain BaseTool instances to Friday's ToolDefinition format.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import asyncio
13
+ import logging
14
+ from typing import TYPE_CHECKING, Any
15
+
16
+ from ..definition import BaseTool
17
+ from ..protocols import ToolDefinition
18
+
19
+ if TYPE_CHECKING:
20
+ from langchain_core.tools import BaseTool as LCBaseTool
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+
25
+ class LangChainToolWrapper(BaseTool):
26
+ """Wraps a LangChain tool as a Friday tool."""
27
+
28
+ def __init__(self, lc_tool: LCBaseTool):
29
+ """
30
+ Initialize wrapper.
31
+
32
+ Args:
33
+ lc_tool: The LangChain tool to wrap.
34
+ """
35
+ self._lc_tool = lc_tool
36
+
37
+ @property
38
+ def name(self) -> str:
39
+ return self._lc_tool.name
40
+
41
+ @property
42
+ def description(self) -> str:
43
+ return self._lc_tool.description
44
+
45
+ @property
46
+ def parameters_schema(self) -> dict[str, Any]:
47
+ """Convert LangChain schema to JSON Schema."""
48
+ # LangChain tools have an args_schema (Pydantic model)
49
+ if hasattr(self._lc_tool, "args_schema") and self._lc_tool.args_schema:
50
+ return self._lc_tool.args_schema.model_json_schema()
51
+
52
+ # Fallback to simple string input
53
+ return {
54
+ "type": "object",
55
+ "properties": {
56
+ "input": {
57
+ "type": "string",
58
+ "description": "Input to the tool",
59
+ }
60
+ },
61
+ "required": ["input"],
62
+ }
63
+
64
+ async def execute(self, **kwargs: Any) -> str:
65
+ """Execute the LangChain tool."""
66
+ # LangChain tools can be sync or async
67
+ if hasattr(self._lc_tool, "arun"):
68
+ # Use async version if available
69
+ if len(kwargs) == 1 and "input" in kwargs:
70
+ result = await self._lc_tool.arun(kwargs["input"])
71
+ else:
72
+ result = await self._lc_tool.arun(**kwargs)
73
+ elif hasattr(self._lc_tool, "run"):
74
+ # Fall back to sync version
75
+ loop = asyncio.get_event_loop()
76
+ if len(kwargs) == 1 and "input" in kwargs:
77
+ result = await loop.run_in_executor(
78
+ None, self._lc_tool.run, kwargs["input"]
79
+ )
80
+ else:
81
+ result = await loop.run_in_executor(
82
+ None, lambda: self._lc_tool.run(**kwargs)
83
+ )
84
+ else:
85
+ raise RuntimeError("LangChain tool has no run or arun method")
86
+
87
+ return str(result) if result is not None else ""
88
+
89
+
90
+ class LangChainToolAdapter:
91
+ """
92
+ Adapts LangChain BaseTool to Friday ToolDefinition.
93
+
94
+ Example:
95
+ ```python
96
+ from langchain_community.tools import DuckDuckGoSearchRun
97
+
98
+ adapter = LangChainToolAdapter()
99
+ ddg_tool = DuckDuckGoSearchRun()
100
+ friday_tool = adapter.adapt(ddg_tool)
101
+
102
+ # Now use with Friday
103
+ result = await friday_tool.execute(input="weather today")
104
+ ```
105
+ """
106
+
107
+ def adapt(self, external_tool: LCBaseTool) -> ToolDefinition:
108
+ """
109
+ Convert a LangChain tool to Friday's ToolDefinition.
110
+
111
+ Args:
112
+ external_tool: LangChain BaseTool instance.
113
+
114
+ Returns:
115
+ Friday ToolDefinition (actually a LangChainToolWrapper).
116
+ """
117
+ self._validate_langchain_tool(external_tool)
118
+ return LangChainToolWrapper(external_tool)
119
+
120
+ def adapt_many(self, tools: list[LCBaseTool]) -> list[ToolDefinition]:
121
+ """
122
+ Convert multiple LangChain tools.
123
+
124
+ Args:
125
+ tools: List of LangChain BaseTool instances.
126
+
127
+ Returns:
128
+ List of Friday ToolDefinition instances.
129
+ """
130
+ return [self.adapt(tool) for tool in tools]
131
+
132
+ def _validate_langchain_tool(self, tool: Any) -> None:
133
+ """Validate that the object is a LangChain tool."""
134
+ try:
135
+ from langchain_core.tools import BaseTool as LCBaseTool
136
+
137
+ if not isinstance(tool, LCBaseTool):
138
+ raise TypeError(
139
+ f"Expected LangChain BaseTool, got {type(tool).__name__}"
140
+ )
141
+ except ImportError:
142
+ raise ImportError( # noqa: B904
143
+ "langchain-core is required for LangChainToolAdapter. "
144
+ "Install with: pip install langchain-core"
145
+ )