Skip to content

Commit 2e3ab89

Browse files
Gl/fix 30 version (#84)
* fix lint * update postgres * Update code * update version
1 parent 844b1af commit 2e3ab89

10 files changed

Lines changed: 27 additions & 32 deletions

File tree

grafi/tools/tool_factory.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,8 @@
1111
from typing import Type
1212

1313
from grafi.tools.function_calls.function_call_tool import FunctionCallTool
14-
from grafi.tools.function_calls.impl.agent_calling_tool import AgentCallingTool
15-
from grafi.tools.function_calls.impl.duckduckgo_tool import DuckDuckGoTool
16-
from grafi.tools.function_calls.impl.google_search_tool import GoogleSearchTool
17-
from grafi.tools.function_calls.impl.mcp_tool import MCPTool
18-
from grafi.tools.function_calls.impl.tavily_tool import TavilyTool
1914
from grafi.tools.functions.function_tool import FunctionTool
20-
from grafi.tools.llms.impl.claude_tool import ClaudeTool
21-
from grafi.tools.llms.impl.deepseek_tool import DeepseekTool
22-
from grafi.tools.llms.impl.gemini_tool import GeminiTool
23-
from grafi.tools.llms.impl.ollama_tool import OllamaTool
2415
from grafi.tools.llms.impl.openai_tool import OpenAITool
25-
from grafi.tools.llms.impl.openrouter_tool import OpenRouterTool
2616
from grafi.tools.tool import Tool
2717

2818

@@ -55,17 +45,6 @@ class to instantiate, then delegates to that class's from_dict() method.
5545
"FunctionTool": FunctionTool,
5646
# LLM implementations
5747
"OpenAITool": OpenAITool,
58-
"ClaudeTool": ClaudeTool,
59-
"DeepseekTool": DeepseekTool,
60-
"GeminiTool": GeminiTool,
61-
"OllamaTool": OllamaTool,
62-
"OpenRouterTool": OpenRouterTool,
63-
# FunctionCall implementations
64-
"TavilyTool": TavilyTool,
65-
"DuckDuckGoTool": DuckDuckGoTool,
66-
"GoogleSearchTool": GoogleSearchTool,
67-
"MCPTool": MCPTool,
68-
"AgentCallingTool": AgentCallingTool,
6948
}
7049

7150
@classmethod

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "grafi"
3-
version = "0.0.30"
3+
version = "0.0.31"
44
description = "Grafi - a flexible, event-driven framework that enables the creation of domain-specific AI agents through composable agentic workflows."
55
authors = [{name = "Craig Li", email = "craig@binome.dev"}]
66
license = {text = "Mozilla Public License Version 2.0"}

tests/tools/test_tool_factory.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88

9+
from grafi.tools.function_calls.function_call_tool import FunctionCallTool
910
from grafi.tools.function_calls.impl.duckduckgo_tool import DuckDuckGoTool
1011
from grafi.tools.function_calls.impl.tavily_tool import TavilyTool
1112
from grafi.tools.llms.impl.claude_tool import ClaudeTool
@@ -44,6 +45,7 @@ async def test_tool_factory_openai_tool():
4445
@pytest.mark.asyncio
4546
async def test_tool_factory_claude_tool():
4647
"""Test factory creates ClaudeTool correctly."""
48+
ToolFactory.register_tool_class("ClaudeTool", ClaudeTool)
4749
data = {
4850
"class": "ClaudeTool",
4951
"tool_id": "test-id",
@@ -69,6 +71,7 @@ async def test_tool_factory_claude_tool():
6971
@pytest.mark.asyncio
7072
async def test_tool_factory_deepseek_tool():
7173
"""Test factory creates DeepseekTool correctly."""
74+
ToolFactory.register_tool_class("DeepseekTool", DeepseekTool)
7275
data = {
7376
"class": "DeepseekTool",
7477
"tool_id": "test-id",
@@ -93,6 +96,7 @@ async def test_tool_factory_deepseek_tool():
9396
@pytest.mark.asyncio
9497
async def test_tool_factory_gemini_tool():
9598
"""Test factory creates GeminiTool correctly."""
99+
ToolFactory.register_tool_class("GeminiTool", GeminiTool)
96100
data = {
97101
"class": "GeminiTool",
98102
"tool_id": "test-id",
@@ -116,6 +120,7 @@ async def test_tool_factory_gemini_tool():
116120
@pytest.mark.asyncio
117121
async def test_tool_factory_ollama_tool():
118122
"""Test factory creates OllamaTool correctly."""
123+
ToolFactory.register_tool_class("OllamaTool", OllamaTool)
119124
data = {
120125
"class": "OllamaTool",
121126
"tool_id": "test-id",
@@ -140,6 +145,7 @@ async def test_tool_factory_ollama_tool():
140145
@pytest.mark.asyncio
141146
async def test_tool_factory_openrouter_tool():
142147
"""Test factory creates OpenRouterTool correctly."""
148+
ToolFactory.register_tool_class("OpenRouterTool", OpenRouterTool)
143149
data = {
144150
"class": "OpenRouterTool",
145151
"tool_id": "test-id",
@@ -165,6 +171,7 @@ async def test_tool_factory_openrouter_tool():
165171
@pytest.mark.asyncio
166172
async def test_tool_factory_duckduckgo_tool():
167173
"""Test factory creates DuckDuckGoTool correctly."""
174+
ToolFactory.register_tool_class("DuckDuckGoTool", DuckDuckGoTool)
168175
data = {
169176
"class": "DuckDuckGoTool",
170177
"tool_id": "test-id",
@@ -185,6 +192,7 @@ async def test_tool_factory_duckduckgo_tool():
185192
@pytest.mark.asyncio
186193
async def test_tool_factory_tavily_tool():
187194
"""Test factory creates TavilyTool correctly."""
195+
ToolFactory.register_tool_class("TavilyTool", TavilyTool)
188196
# Set a dummy API key for test
189197
os.environ["TAVILY_API_KEY"] = "test_key"
190198

@@ -261,6 +269,7 @@ async def test_tool_factory_roundtrip_openai():
261269
async def test_tool_factory_roundtrip_claude():
262270
"""Test serialization and deserialization roundtrip for ClaudeTool."""
263271
# Create original tool using builder
272+
ToolFactory.register_tool_class("ClaudeTool", ClaudeTool)
264273
original = (
265274
ClaudeTool.builder()
266275
.name("test_claude")
@@ -340,7 +349,6 @@ async def from_dict(cls, data):
340349
def test_tool_factory_is_registered():
341350
"""Test checking if a class is registered."""
342351
assert ToolFactory.is_registered("OpenAITool")
343-
assert ToolFactory.is_registered("ClaudeTool")
344352
assert not ToolFactory.is_registered("NonExistentTool")
345353

346354

@@ -350,15 +358,9 @@ def test_tool_factory_get_registered_classes():
350358

351359
# Check some expected classes are in the registry
352360
assert "OpenAITool" in registered
353-
assert "ClaudeTool" in registered
354-
assert "DeepseekTool" in registered
355-
assert "GeminiTool" in registered
356-
assert "OllamaTool" in registered
357-
assert "OpenRouterTool" in registered
358-
assert "TavilyTool" in registered
359-
assert "DuckDuckGoTool" in registered
361+
assert "FunctionCallTool" in registered
360362
assert "FunctionTool" in registered
361363

362364
# Verify the classes are correct
363365
assert registered["OpenAITool"] == OpenAITool
364-
assert registered["ClaudeTool"] == ClaudeTool
366+
assert registered["FunctionCallTool"] == FunctionCallTool

tests_integration/mcp_assistant/mpc_deserialize_assistant_example_local.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from grafi.common.events.topic_events.publish_to_topic_event import PublishToTopicEvent
99
from grafi.common.models.invoke_context import InvokeContext
1010
from grafi.common.models.message import Message
11+
from grafi.tools.function_calls.impl.mcp_tool import MCPTool
12+
from grafi.tools.tool_factory import ToolFactory
1113

1214

1315
def get_invoke_context() -> InvokeContext:
@@ -28,6 +30,7 @@ async def test_deserialized_assistant() -> None:
2830
with open(Path(__file__).parent / "MCPAssistant_manifest.json", "r") as f:
2931
manifest_json = f.read()
3032

33+
ToolFactory.register_tool_class("MCPTool", MCPTool)
3134
# Deserialize the assistant using the new method
3235
assistant = await Assistant.from_dict(json.loads(manifest_json))
3336

tests_integration/react_assistant/react_assistant_deserialize_assistant_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from grafi.common.events.topic_events.publish_to_topic_event import PublishToTopicEvent
88
from grafi.common.models.invoke_context import InvokeContext
99
from grafi.common.models.message import Message
10+
from grafi.tools.function_calls.impl.tavily_tool import TavilyTool
11+
from grafi.tools.tool_factory import ToolFactory
1012

1113

1214
def get_invoke_context() -> InvokeContext:
@@ -24,6 +26,7 @@ async def test_deserialized_assistant() -> None:
2426
manifest_json = f.read()
2527

2628
# Deserialize the assistant using the new method
29+
ToolFactory.register_tool_class("TavilyTool", TavilyTool)
2730
assistant = await Assistant.from_dict(json.loads(manifest_json))
2831

2932
print(f"Successfully deserialized assistant: {assistant.name}")

tests_integration/simple_llm_assistant/claude_tool_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ async def test_claude_tool_serialization() -> None:
161161
print(f"Serialized: {serialized}")
162162

163163
# Deserialize back using ToolFactory
164+
ToolFactory.register_tool_class("ClaudeTool", ClaudeTool)
164165
restored_tool = await ToolFactory.from_dict(serialized)
165166

166167
# Test that the restored tool works correctly
@@ -198,6 +199,7 @@ async def test_claude_tool_with_chat_param_serialization() -> None:
198199
serialized = original_tool.to_dict()
199200

200201
# Deserialize back
202+
ToolFactory.register_tool_class("ClaudeTool", ClaudeTool)
201203
restored_tool = await ToolFactory.from_dict(serialized)
202204

203205
# Test that the restored tool works

tests_integration/simple_llm_assistant/deepseek_tool_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ async def test_deepseek_tool_serialization() -> None:
151151
print(f"Serialized: {serialized}")
152152

153153
# Deserialize back using ToolFactory
154+
ToolFactory.register_tool_class("DeepseekTool", DeepseekTool)
154155
restored_tool = await ToolFactory.from_dict(serialized)
155156

156157
# Test that the restored tool works correctly
@@ -184,6 +185,7 @@ async def test_deepseek_tool_with_chat_param_serialization() -> None:
184185
serialized = original_tool.to_dict()
185186

186187
# Deserialize back
188+
ToolFactory.register_tool_class("DeepseekTool", DeepseekTool)
187189
restored_tool = await ToolFactory.from_dict(serialized)
188190

189191
# Test that the restored tool works

tests_integration/simple_llm_assistant/gemini_tool_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ async def test_gemini_tool_serialization() -> None:
152152
print(f"Serialized: {serialized}")
153153

154154
# Deserialize back using ToolFactory
155+
ToolFactory.register_tool_class("GeminiTool", GeminiTool)
155156
restored_tool = await ToolFactory.from_dict(serialized)
156157

157158
# Test that the restored tool works correctly
@@ -188,6 +189,7 @@ async def test_gemini_tool_with_chat_param_serialization() -> None:
188189
serialized = original_tool.to_dict()
189190

190191
# Deserialize back
192+
ToolFactory.register_tool_class("GeminiTool", GeminiTool)
191193
restored_tool = await ToolFactory.from_dict(serialized)
192194

193195
# Test that the restored tool works

tests_integration/simple_llm_assistant/openrouter_tool_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ async def test_openrouter_tool_serialization() -> None:
146146
print(f"Serialized: {serialized}")
147147

148148
# Deserialize back using ToolFactory
149+
ToolFactory.register_tool_class("OpenRouterTool", OpenRouterTool)
149150
restored_tool = await ToolFactory.from_dict(serialized)
150151

151152
# Test that the restored tool works correctly
@@ -179,6 +180,7 @@ async def test_openrouter_tool_with_chat_param_serialization() -> None:
179180
serialized = original_tool.to_dict()
180181

181182
# Deserialize back
183+
ToolFactory.register_tool_class("OpenRouterTool", OpenRouterTool)
182184
restored_tool = await ToolFactory.from_dict(serialized)
183185

184186
# Test that the restored tool works

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)