Skip to content

Commit c2c2034

Browse files
committed
Added initial Griptape support.
1 parent 1a83796 commit c2c2034

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Overview
66

7-
The Graphlit Agent Tools for Python enables easy interaction with agent frameworks such as [CrewAI](https://crewai.com), allowing developers to easily integrate the Graphlit service with agentic workflows. This document outlines the setup process and provides a basic example of using the tools.
7+
The Graphlit Agent Tools for Python enables easy interaction with agent frameworks such as [CrewAI](https://crewai.com) or [Griptape](https://www.griptape.ai/), allowing developers to easily integrate the Graphlit service with agentic workflows. This document outlines the setup process and provides a basic example of using the tools.
88

99
## Prerequisites
1010

@@ -21,13 +21,25 @@ To install the Graphlit Agent Tools with CrewAI, use pip:
2121
pip install graphlit-tools[crewai]
2222
```
2323

24+
To install the Graphlit Agent Tools with Griptape, use pip:
25+
26+
```bash
27+
pip install graphlit-tools[griptape]
28+
```
29+
2430
### Using the Graphlit agent tools
2531

2632
We have example Google Colab notebooks using CrewAI, which provide an example for [analyzing the web marketing strategy of a company](https://colab.research.google.com/github/graphlit/graphlit-samples/blob/main/python/Notebook%20Examples/Graphlit_2024_12_07_CrewAI_Web_Marketing_Analyzer.ipynb), and for [structured data extraction of products from scraped web pages](https://colab.research.google.com/github/graphlit/graphlit-samples/blob/main/python/Notebook%20Examples/Graphlit_2024_12_08_CrewAI_Product_Data_Extraction.ipynb).
2733

2834
Once you have configured the Graphlit client, as shown below, you will pass the client to the tool constructor.
2935

30-
For use in CrewAI, you will need to convert the tool to the CrewAI tool schema with the `CrewAIConverter.from_tool()` function. We will provide support for additional agent frameworks, such as LangGraph and AutoGen in future.
36+
For use in CrewAI, you will need to convert the tool to the CrewAI tool schema with the `CrewAIConverter.from_tool()` function.
37+
38+
For use in Griptape, you will need to convert the tool to the CrewAI tool schema with the `GriptapeConverter.from_tool()` function.
39+
40+
We will provide support for additional agent frameworks, such as LangGraph and AutoGen in future.
41+
42+
#### CrewAI
3143

3244
```python
3345
from graphlit_tools import WebSearchTool, CrewAIConverter
@@ -44,6 +56,23 @@ web_search_agent = Agent(
4456
)
4557
```
4658

59+
#### Griptape
60+
61+
```python
62+
from graphlit_tools import WebSearchTool, CrewAIConverter
63+
64+
web_search_tool = GriptapeConverter.from_tool(WebSearchTool(graphlit))
65+
66+
web_search_agent = Agent(
67+
role="Web Researcher",
68+
goal="Find the {company} website.",
69+
backstory="",
70+
verbose=True,
71+
allow_delegation=False,
72+
tools=[web_search_tool],
73+
)
74+
```
75+
4776
## Configuration
4877

4978
The Graphlit Client supports environment variables to be set for authentication and configuration:

__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
MicrosoftTeamsIngestTool,
3434
DiscordIngestTool,
3535
SlackIngestTool,
36-
CrewAIConverter
36+
CrewAIConverter,
37+
GriptapeConverter,
3738
)

graphlit_tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .base_tool import BaseTool
22
from .crewai_converter import CrewAIConverter
3+
from .griptape_converter import GriptapeConverter
34
from .exceptions import ToolException
45
from .retrieval.content_retrieval_tool import ContentRetrievalTool
56
from .retrieval.person_retrieval_tool import PersonRetrievalTool

graphlit_tools/griptape_converter.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from typing import Any, cast
2+
from schema import Schema
3+
from .base_tool import BaseTool
4+
5+
GriptapeBaseTool: Any = None
6+
7+
try:
8+
from griptape.tools import BaseTool as GriptapeBaseTool
9+
from griptape.utils.decorators import activity
10+
from griptape.artifacts import TextArtifact
11+
except ImportError:
12+
GriptapeBaseTool = None
13+
14+
if GriptapeBaseTool:
15+
class GriptapeConverter(GriptapeBaseTool):
16+
"""Tool to convert Graphlit tools into Griptape tools."""
17+
18+
graphlit_tool: Any
19+
20+
def _run(
21+
self,
22+
*args: Any,
23+
**kwargs: Any,
24+
) -> Any:
25+
tool = cast(BaseTool, self.graphlit_tool)
26+
27+
return tool.run(*args, **kwargs)
28+
29+
async def _arun(
30+
self,
31+
*args: Any,
32+
**kwargs: Any,
33+
) -> Any:
34+
tool = cast(BaseTool, self.graphlit_tool)
35+
36+
return await tool.arun(*args, **kwargs)
37+
38+
@classmethod
39+
def from_tool(cls, tool: Any, **kwargs: Any) -> "GriptapeConverter":
40+
if not isinstance(tool, BaseTool):
41+
raise ValueError(f"Expected a Graphlit tool, got {type(tool)}")
42+
43+
tool = cast(BaseTool, tool)
44+
45+
if tool.args_schema is None:
46+
raise ValueError("Invalid arguments JSON schema.")
47+
48+
def generate(self, params: dict[str, Any]) -> TextArtifact:
49+
return TextArtifact(str(self.graphlit_tool.run(**params)))
50+
51+
tool_schema = Schema(tool.json_schema)
52+
53+
decorated_generate = activity(
54+
config={
55+
"description": tool.description,
56+
"schema": tool_schema,
57+
}
58+
)(generate)
59+
60+
new_cls = type(
61+
f"{tool.name.capitalize()}GriptapeConverter",
62+
(cls,),
63+
{"graphlit_tool": tool, "generate": decorated_generate},
64+
)
65+
66+
return new_cls(
67+
name=tool.name,
68+
graphlit_tool=tool,
69+
**kwargs,
70+
)
71+
else:
72+
class GriptapeConverter:
73+
"""Fallback GriptapeConverter if griptape is not installed."""
74+
def __init__(self, *args, **kwargs):
75+
raise ImportError(
76+
"GriptapeConverter requires the griptape package. "
77+
"Install it using pip install graphlit-tools[griptape]."
78+
)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
'graphlit-client'
1616
],
1717
extras_require={
18-
"crewai": ["crewai-tools"] # Extras for CrewAI support
18+
"crewai": ["crewai-tools"], # Extras for CrewAI support
19+
"griptape": ["griptape"] # Extras for Griptape support
1920
},
2021
python_requires='>=3.6',
2122
author='Unstruk Data Inc.',

0 commit comments

Comments
 (0)