glean-agent-toolkit 0.2.0__py3-none-any.whl

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.
@@ -0,0 +1,38 @@
1
+ """Web Search tool for searching the internet."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from glean.agent_toolkit.decorators import tool_spec
8
+ from glean.agent_toolkit.tools._common import run_tool
9
+ from glean.api_client import models
10
+
11
+
12
+ @tool_spec(
13
+ name="web_search",
14
+ description=(
15
+ "Can search for up-to-date external information from the web. Closely evaluate the "
16
+ "instructions below for the user query to decide whether to use web search. If you think "
17
+ "the scenarios are contradictory, do not use web search unless there is clear user intent."
18
+ "\n"
19
+ "INSTRUCTIONS:\n"
20
+ "Examples of when to use this tool:\n"
21
+ "- User Intent: Use this tool if the user is asking you to search the web, look online, "
22
+ "provide links/sources, or explicitly looking for current external information (outside "
23
+ "of the company) like weather, news, latest updates/plans, or financial data.\n"
24
+ "- Freshness: Use this tool if you need up-to-date information on time-dependent topics "
25
+ "or any time you would otherwise refuse to answer a question because your knowledge might "
26
+ "be out of date.\n"
27
+ "- Niche Information: If the answer would likely change based on detailed information not "
28
+ "widely known or understood (which might be found on the internet), use web sources "
29
+ "directly rather than relying on the distilled knowledge from pretraining.\n"
30
+ "- Do NOT use this tool for programming related queries. You already know enough about "
31
+ "those.\n"
32
+ "- Do NOT use this tool for queries seeking general ideas, which may not benefit from "
33
+ "specific information."
34
+ ),
35
+ )
36
+ def web_search(parameters: dict[str, models.ToolsCallParameter]) -> dict[str, Any]:
37
+ """Search the web for up-to-date external information."""
38
+ return run_tool("Web Browser", parameters)
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: glean-agent-toolkit
3
+ Version: 0.2.0
4
+ Summary: AI Agent toolkit for adapting Glean's enterprise tools across multiple frameworks
5
+ Project-URL: Source Code, https://github.com/gleanwork/glean-agent-toolkit
6
+ Author-email: Steve Calvert <steve.calvert@glean.com>
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: <4.0,>=3.10
10
+ Requires-Dist: glean-api-client<1.0,>=0.6.0
11
+ Requires-Dist: pydantic<3.0,>=2.7
12
+ Provides-Extra: adk
13
+ Requires-Dist: google-adk<1.0,>=0.1.0; extra == 'adk'
14
+ Provides-Extra: codespell
15
+ Requires-Dist: codespell<3.0,>=2.2.6; extra == 'codespell'
16
+ Provides-Extra: crewai
17
+ Requires-Dist: crewai<1.0,>=0.28.0; extra == 'crewai'
18
+ Provides-Extra: dev
19
+ Requires-Dist: commitizen<5.0,>=4.4.1; extra == 'dev'
20
+ Requires-Dist: pip-audit<3.0,>=2.6.0; extra == 'dev'
21
+ Requires-Dist: vcrpy<7.0,>=6.0.2; extra == 'dev'
22
+ Provides-Extra: langchain
23
+ Requires-Dist: langchain<1.0,>=0.1.0; extra == 'langchain'
24
+ Provides-Extra: lint
25
+ Requires-Dist: ruff<1.0,>=0.5; extra == 'lint'
26
+ Provides-Extra: openai
27
+ Requires-Dist: openai-agents<1.0,>=0.0.11; extra == 'openai'
28
+ Requires-Dist: openai<2.0,>=1.0.0; extra == 'openai'
29
+ Provides-Extra: test
30
+ Requires-Dist: crewai<1.0,>=0.28.0; extra == 'test'
31
+ Requires-Dist: google-adk<1.0,>=0.1.0; extra == 'test'
32
+ Requires-Dist: langchain<1.0,>=0.1.0; extra == 'test'
33
+ Requires-Dist: openai-agents<1.0,>=0.0.11; extra == 'test'
34
+ Requires-Dist: openai<2.0,>=1.0.0; extra == 'test'
35
+ Requires-Dist: pytest-asyncio<1.0,>=0.23.2; extra == 'test'
36
+ Requires-Dist: pytest-cov<6.0,>=4.1.0; extra == 'test'
37
+ Requires-Dist: pytest-httpx<1.0,>=0.35.0; extra == 'test'
38
+ Requires-Dist: pytest<9.0,>=7.4.3; extra == 'test'
39
+ Provides-Extra: typing
40
+ Requires-Dist: pyright<2.0,>=1.1.370; extra == 'typing'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # Glean Agent Toolkit
44
+
45
+ The Glean Agent Toolkit makes it easy to integrate Glean's powerful search and knowledge discovery capabilities into your AI agents. Use our pre-built tools with popular agent frameworks like OpenAI Assistants, LangChain, CrewAI, and Google's Agent Development Kit (ADK), or adapt your own custom tools for cross-framework use.
46
+
47
+ ## Key Features
48
+
49
+ * **Production-Ready Glean Tools:** Instantly add capabilities like enterprise search, employee lookup, calendar search, Gmail search, and more to your agents.
50
+ * **Framework Adapters:** Seamlessly convert Glean tools into formats compatible with major agent SDKs.
51
+ * **Custom Tool Creation:** Define your own tools once using the `@tool_spec` decorator and use them across any supported framework.
52
+
53
+ ## Installation
54
+
55
+ Install the base toolkit:
56
+
57
+ ```bash
58
+ pip install glean-agent-toolkit
59
+ ```
60
+
61
+ To include support for specific agent frameworks, install the relevant extras:
62
+
63
+ ```bash
64
+ pip install glean-agent-toolkit[openai]
65
+ pip install glean-agent-toolkit[adk]
66
+ pip install glean-agent-toolkit[langchain]
67
+ pip install glean-agent-toolkit[crewai]
68
+ ```
69
+
70
+ You can also install all extras:
71
+
72
+ ```bash
73
+ pip install glean-agent-toolkit[all]
74
+ ```
75
+
76
+ Note: The `[openai]` extra installs the standard `openai` Python library, used for direct API interactions like Chat Completions or the Assistants API. The example below for the "OpenAI Agents SDK" uses a separate library, `openai-agents`, which you'll need to install independently: `pip install openai-agents`.
77
+
78
+ ## Prerequisites
79
+
80
+ Before using any Glean tools, you'll need:
81
+
82
+ 1. **Glean API credentials**: Obtain these from your Glean administrator
83
+ 2. **Environment variables**:
84
+ ```bash
85
+ export GLEAN_API_TOKEN="your-api-token"
86
+ export GLEAN_INSTANCE="your-instance-name"
87
+ ```
88
+
89
+ ## Available Tools
90
+
91
+ The toolkit comes with a suite of production-ready tools that connect to various Glean functionalities:
92
+
93
+ * **`glean_search`**: Search your company's knowledge base for relevant documents and information
94
+ * **`web_search`**: Search the public web for up-to-date external information
95
+ * **`ai_web_search`**: Query Google Gemini for AI-powered web information
96
+ * **`calendar_search`**: Find meetings and calendar events
97
+ * **`employee_search`**: Search for employees by name, team, department, or expertise
98
+ * **`code_search`**: Search your company's source code repositories
99
+ * **`gmail_search`**: Search Gmail messages and conversations
100
+ * **`outlook_search`**: Search Outlook mail and calendar items
101
+
102
+ ## Quick Start Examples
103
+
104
+ ### Using `glean_search` with Different Frameworks
105
+
106
+ #### OpenAI Agents SDK
107
+
108
+ ```python
109
+ import os
110
+ from glean.agent_toolkit.tools import glean_search
111
+ from agents import Agent, Runner
112
+
113
+ # Ensure environment variables are set
114
+ assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
115
+ assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
116
+ assert os.getenv("OPENAI_API_KEY"), "OPENAI_API_KEY must be set"
117
+
118
+ # Create an agent with the Glean search tool
119
+ agent = Agent(
120
+ name="KnowledgeAssistant",
121
+ instructions="You help users find information from the company knowledge base using Glean search.",
122
+ tools=[glean_search.func] # Use the underlying function
123
+ )
124
+
125
+ # Run a search query
126
+ result = Runner.run_sync(agent, "Find our Q4 planning documents")
127
+ print(f"Search results: {result.final_output}")
128
+ ```
129
+
130
+ #### LangChain
131
+
132
+ ```python
133
+ import os
134
+ from glean.agent_toolkit.tools import glean_search
135
+ from langchain_openai import ChatOpenAI
136
+ from langchain.agents import AgentExecutor, create_react_agent
137
+ from langchain_core.prompts import ChatPromptTemplate
138
+
139
+ # Ensure environment variables are set
140
+ assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
141
+ assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
142
+
143
+ # Convert to LangChain tool format
144
+ langchain_tool = glean_search.as_langchain_tool()
145
+
146
+ llm = ChatOpenAI(model="gpt-4", temperature=0)
147
+ tools = [langchain_tool]
148
+
149
+ prompt_template = """You are a helpful assistant with access to company knowledge.
150
+ Use the glean_search tool to find relevant information when users ask questions.
151
+
152
+ Tools available:
153
+ {tools}
154
+
155
+ Use this format:
156
+ Question: {input}
157
+ Thought: I should search for information about this topic
158
+ Action: {tool_names}
159
+ Action Input: your search query
160
+ Observation: the search results
161
+ Thought: I can now provide a helpful response
162
+ Final Answer: your response based on the search results
163
+
164
+ Question: {input}
165
+ {agent_scratchpad}"""
166
+
167
+ prompt = ChatPromptTemplate.from_template(prompt_template)
168
+ agent = create_react_agent(llm, tools, prompt)
169
+ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
170
+
171
+ # Search for company information
172
+ result = agent_executor.invoke({"input": "What is our vacation policy?"})
173
+ print(result["output"])
174
+ ```
175
+
176
+ #### CrewAI
177
+
178
+ ```python
179
+ import os
180
+ from glean.agent_toolkit.tools import glean_search
181
+ from crewai import Agent, Task, Crew
182
+
183
+ # Ensure environment variables are set
184
+ assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
185
+ assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
186
+
187
+ # Convert to CrewAI tool format
188
+ crewai_tool = glean_search.as_crewai_tool()
189
+
190
+ # Create a research agent
191
+ researcher = Agent(
192
+ role="Corporate Knowledge Researcher",
193
+ goal="Find and summarize relevant company information",
194
+ backstory="You are an expert at navigating company knowledge bases to find accurate, up-to-date information.",
195
+ tools=[crewai_tool],
196
+ verbose=True
197
+ )
198
+
199
+ # Create a research task
200
+ research_task = Task(
201
+ description="Find information about our company's remote work policy and summarize the key points.",
202
+ expected_output="A clear summary of the remote work policy including eligibility, expectations, and guidelines.",
203
+ agent=researcher
204
+ )
205
+
206
+ # Execute the research
207
+ crew = Crew(agents=[researcher], tasks=[research_task])
208
+ result = crew.kickoff()
209
+ print(result)
210
+ ```
211
+
212
+ ### Real-World Use Cases
213
+
214
+ #### Employee Directory Search
215
+
216
+ ```python
217
+ from glean.agent_toolkit.tools import employee_search
218
+
219
+ # Find engineering team members
220
+ engineering_team = employee_search.as_langchain_tool()
221
+
222
+ # Example usage in an agent:
223
+ # "Who are the senior engineers in the backend team?"
224
+ # "Find Sarah Johnson's contact information"
225
+ # "List all product managers in the San Francisco office"
226
+ ```
227
+
228
+ #### Code Discovery
229
+
230
+ ```python
231
+ from glean.agent_toolkit.tools import code_search
232
+
233
+ # Search company codebases
234
+ code_tool = code_search.as_langchain_tool()
235
+
236
+ # Example queries:
237
+ # "Find authentication middleware implementations"
238
+ # "Show me recent changes to the payment processing module"
239
+ # "Locate configuration files for the staging environment"
240
+ ```
241
+
242
+ #### Email and Calendar Integration
243
+
244
+ ```python
245
+ from glean.agent_toolkit.tools import gmail_search, calendar_search
246
+
247
+ # Search emails and meetings
248
+ gmail_tool = gmail_search.as_langchain_tool()
249
+ calendar_tool = calendar_search.as_langchain_tool()
250
+
251
+ # Example queries:
252
+ # "Find emails about the product launch from last month"
253
+ # "Show me my meetings with the design team this week"
254
+ # "Search for messages containing budget discussions"
255
+ ```
256
+
257
+ #### Web Research with Context
258
+
259
+ ```python
260
+ from glean.agent_toolkit.tools import web_search, ai_web_search
261
+
262
+ # External information gathering
263
+ web_tool = web_search.as_langchain_tool()
264
+ ai_web_tool = ai_web_search.as_langchain_tool()
265
+
266
+ # Example queries:
267
+ # "Latest industry trends in machine learning"
268
+ # "Current market analysis for SaaS companies"
269
+ # "Recent news about our competitors"
270
+ ```
271
+
272
+ ## Creating Custom Tools with `@tool_spec`
273
+
274
+ Define your own tools that work across all supported frameworks:
275
+
276
+ ```python
277
+ from glean.agent_toolkit import tool_spec
278
+ from pydantic import BaseModel
279
+ import requests
280
+
281
+ class WeatherResponse(BaseModel):
282
+ temperature: float
283
+ condition: str
284
+ humidity: int
285
+ city: str
286
+
287
+ @tool_spec(
288
+ name="get_current_weather",
289
+ description="Get current weather information for a specified city",
290
+ output_model=WeatherResponse
291
+ )
292
+ def get_weather(city: str, units: str = "celsius") -> WeatherResponse:
293
+ """Fetch current weather for a city."""
294
+ # Replace with actual weather API call
295
+ api_key = os.getenv("WEATHER_API_KEY")
296
+ response = requests.get(
297
+ f"https://api.weather.com/v1/current?key={api_key}&q={city}&units={units}"
298
+ )
299
+ data = response.json()
300
+
301
+ return WeatherResponse(
302
+ temperature=data["temp"],
303
+ condition=data["condition"],
304
+ humidity=data["humidity"],
305
+ city=city
306
+ )
307
+
308
+ # Use across frameworks
309
+ openai_weather = get_weather.as_openai_tool()
310
+ langchain_weather = get_weather.as_langchain_tool()
311
+ crewai_weather = get_weather.as_crewai_tool()
312
+ ```
313
+
314
+ ## Contributing
315
+
316
+ Interested in contributing? Check out our [Contributing Guide](CONTRIBUTING.md) for instructions on setting up the development environment and submitting changes.
317
+
318
+ ## License
319
+
320
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,25 @@
1
+ glean/agent_toolkit/__init__.py,sha256=4-Ad_YoKmttpEnvYS5HmGcbTmVilkQ5kci-9ripPhpU,681
2
+ glean/agent_toolkit/decorators.py,sha256=CRphbndMjHdv8MAVg7IjVoEyHCS5bRl1R2UOCwAXRjY,8308
3
+ glean/agent_toolkit/py.typed,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
4
+ glean/agent_toolkit/registry.py,sha256=YixBYT4NpVexAucBY6nLH5WOYEzpxhVukp_sIYyWugA,1196
5
+ glean/agent_toolkit/spec.py,sha256=PJpbDdpdIjbdeCG3wsNzQZ0PtazzIzt9e7hgUONo3FY,1389
6
+ glean/agent_toolkit/adapters/__init__.py,sha256=lW--I7NeONJJYoled5myvvJXexh2aELu8izS4A4NfKw,652
7
+ glean/agent_toolkit/adapters/adk.py,sha256=GCrpp0T5Zz6JDfe2zOlvVck_oJY5J4BTqjjHauJpCDo,2535
8
+ glean/agent_toolkit/adapters/base.py,sha256=Hz8LqY-0uKMNC9WsyaLNw4ctw7WYdB15tOCs8ZV3qk0,750
9
+ glean/agent_toolkit/adapters/crewai.py,sha256=35C61F1Bs4oCDk2Eq1OYFZqqj0Qt5nDuhnYICZux5ao,6493
10
+ glean/agent_toolkit/adapters/langchain.py,sha256=UEzKi-EVq32mOXosSG-CS3lnlRy7eVjs5CMTqQ61hcQ,4792
11
+ glean/agent_toolkit/adapters/openai.py,sha256=q6N5rzc9Y8ZUQxlOUy9om1xFtE8NRScohWqDf4I7rjI,4404
12
+ glean/agent_toolkit/tools/__init__.py,sha256=1hnBzI_yR6oi6R2EAylJp-MwtfP_sR6Tqt_FkJVFDVc,1126
13
+ glean/agent_toolkit/tools/_common.py,sha256=2b0l44O-7Wq40x0jmxSMlgK7bKPzKcaKQW7uYhQYqaE,994
14
+ glean/agent_toolkit/tools/ai_web_search.py,sha256=wluXrAqB4IQW0bVavtNHk_niPMVuBEdd4Q6qpLIumpk,2151
15
+ glean/agent_toolkit/tools/calendar_search.py,sha256=GXer9Cfrg4cA2iH5zYsXMe_QjnxBasfNIgx3Sooco5E,565
16
+ glean/agent_toolkit/tools/code_search.py,sha256=QdF3_2SRF0151gtAAetk2Z816wp_tHzmhKZ3-6AlLHM,1006
17
+ glean/agent_toolkit/tools/employee_search.py,sha256=heTHPEVJPZDLmZKLL18v8w-OQIJGrIwye56jHyrI0NU,1460
18
+ glean/agent_toolkit/tools/glean_search.py,sha256=qV1ZtW5d-KituBTTMrTbRVoL8pd1AWYukNcb9cjbFvw,947
19
+ glean/agent_toolkit/tools/gmail_search.py,sha256=KmKqXFSngz4TQD6wkD9IhzF2H12P-rI4OMl56eGGC-Y,765
20
+ glean/agent_toolkit/tools/outlook_search.py,sha256=YBeFmY3BIso6UmROXZan_GukvJjWhiq9u2vOaPRNz5E,775
21
+ glean/agent_toolkit/tools/web_search.py,sha256=hIcmgbPYxPoLPLeLAmfQpqlkm0g9xH7Bfr_iRaOXAMY,1925
22
+ glean_agent_toolkit-0.2.0.dist-info/METADATA,sha256=PID5jnkBqfQrCzev6UdYMHHay3LoSyaxcoE6bFBNmf0,10574
23
+ glean_agent_toolkit-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
+ glean_agent_toolkit-0.2.0.dist-info/licenses/LICENSE,sha256=RAfePGwatR5BOtlNhW60zAKWCeHVgtGpaGBqZQadXNQ,1062
25
+ glean_agent_toolkit-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Glean
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.