AI Agent toolkit for adapting Glean's enterprise tools across multiple frameworks
Project description
Glean Agent Toolkit
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.
Key Features
- Production-Ready Glean Tools: Instantly add capabilities like enterprise search, employee lookup, calendar search, Gmail search, and more to your agents.
- Framework Adapters: Seamlessly convert Glean tools into formats compatible with major agent SDKs.
- Custom Tool Creation: Define your own tools once using the
@tool_specdecorator and use them across any supported framework.
Installation
Install the base toolkit:
pip install glean-agent-toolkit
To include support for specific agent frameworks, install the relevant extras:
pip install glean-agent-toolkit[openai]
pip install glean-agent-toolkit[adk]
pip install glean-agent-toolkit[langchain]
pip install glean-agent-toolkit[crewai]
You can also install all extras:
pip install glean-agent-toolkit[all]
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.
Prerequisites
Before using any Glean tools, you'll need:
- Glean API credentials: Obtain these from your Glean administrator
- Environment variables:
export GLEAN_API_TOKEN="your-api-token" export GLEAN_INSTANCE="your-instance-name"
Available Tools
The toolkit comes with a suite of production-ready tools that connect to various Glean functionalities:
glean_search: Search your company's knowledge base for relevant documents and informationweb_search: Search the public web for up-to-date external informationai_web_search: Query Google Gemini for AI-powered web informationcalendar_search: Find meetings and calendar eventsemployee_search: Search for employees by name, team, department, or expertisecode_search: Search your company's source code repositoriesgmail_search: Search Gmail messages and conversationsoutlook_search: Search Outlook mail and calendar items
Quick Start Examples
Using glean_search with Different Frameworks
OpenAI Agents SDK
import os
from glean.agent_toolkit.tools import glean_search
from agents import Agent, Runner
# Ensure environment variables are set
assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
assert os.getenv("OPENAI_API_KEY"), "OPENAI_API_KEY must be set"
# Create an agent with the Glean search tool
agent = Agent(
name="KnowledgeAssistant",
instructions="You help users find information from the company knowledge base using Glean search.",
tools=[glean_search.func] # Use the underlying function
)
# Run a search query
result = Runner.run_sync(agent, "Find our Q4 planning documents")
print(f"Search results: {result.final_output}")
LangChain
import os
from glean.agent_toolkit.tools import glean_search
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_core.prompts import ChatPromptTemplate
# Ensure environment variables are set
assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
# Convert to LangChain tool format
langchain_tool = glean_search.as_langchain_tool()
llm = ChatOpenAI(model="gpt-4", temperature=0)
tools = [langchain_tool]
prompt_template = """You are a helpful assistant with access to company knowledge.
Use the glean_search tool to find relevant information when users ask questions.
Tools available:
{tools}
Use this format:
Question: {input}
Thought: I should search for information about this topic
Action: {tool_names}
Action Input: your search query
Observation: the search results
Thought: I can now provide a helpful response
Final Answer: your response based on the search results
Question: {input}
{agent_scratchpad}"""
prompt = ChatPromptTemplate.from_template(prompt_template)
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Search for company information
result = agent_executor.invoke({"input": "What is our vacation policy?"})
print(result["output"])
CrewAI
import os
from glean.agent_toolkit.tools import glean_search
from crewai import Agent, Task, Crew
# Ensure environment variables are set
assert os.getenv("GLEAN_API_TOKEN"), "GLEAN_API_TOKEN must be set"
assert os.getenv("GLEAN_INSTANCE"), "GLEAN_INSTANCE must be set"
# Convert to CrewAI tool format
crewai_tool = glean_search.as_crewai_tool()
# Create a research agent
researcher = Agent(
role="Corporate Knowledge Researcher",
goal="Find and summarize relevant company information",
backstory="You are an expert at navigating company knowledge bases to find accurate, up-to-date information.",
tools=[crewai_tool],
verbose=True
)
# Create a research task
research_task = Task(
description="Find information about our company's remote work policy and summarize the key points.",
expected_output="A clear summary of the remote work policy including eligibility, expectations, and guidelines.",
agent=researcher
)
# Execute the research
crew = Crew(agents=[researcher], tasks=[research_task])
result = crew.kickoff()
print(result)
Real-World Use Cases
Employee Directory Search
from glean.agent_toolkit.tools import employee_search
# Find engineering team members
engineering_team = employee_search.as_langchain_tool()
# Example usage in an agent:
# "Who are the senior engineers in the backend team?"
# "Find Sarah Johnson's contact information"
# "List all product managers in the San Francisco office"
Code Discovery
from glean.agent_toolkit.tools import code_search
# Search company codebases
code_tool = code_search.as_langchain_tool()
# Example queries:
# "Find authentication middleware implementations"
# "Show me recent changes to the payment processing module"
# "Locate configuration files for the staging environment"
Email and Calendar Integration
from glean.agent_toolkit.tools import gmail_search, calendar_search
# Search emails and meetings
gmail_tool = gmail_search.as_langchain_tool()
calendar_tool = calendar_search.as_langchain_tool()
# Example queries:
# "Find emails about the product launch from last month"
# "Show me my meetings with the design team this week"
# "Search for messages containing budget discussions"
Web Research with Context
from glean.agent_toolkit.tools import web_search, ai_web_search
# External information gathering
web_tool = web_search.as_langchain_tool()
ai_web_tool = ai_web_search.as_langchain_tool()
# Example queries:
# "Latest industry trends in machine learning"
# "Current market analysis for SaaS companies"
# "Recent news about our competitors"
Creating Custom Tools with @tool_spec
Define your own tools that work across all supported frameworks:
from glean.agent_toolkit import tool_spec
from pydantic import BaseModel
import requests
class WeatherResponse(BaseModel):
temperature: float
condition: str
humidity: int
city: str
@tool_spec(
name="get_current_weather",
description="Get current weather information for a specified city",
output_model=WeatherResponse
)
def get_weather(city: str, units: str = "celsius") -> WeatherResponse:
"""Fetch current weather for a city."""
# Replace with actual weather API call
api_key = os.getenv("WEATHER_API_KEY")
response = requests.get(
f"https://api.weather.com/v1/current?key={api_key}&q={city}&units={units}"
)
data = response.json()
return WeatherResponse(
temperature=data["temp"],
condition=data["condition"],
humidity=data["humidity"],
city=city
)
# Use across frameworks
openai_weather = get_weather.as_openai_tool()
langchain_weather = get_weather.as_langchain_tool()
crewai_weather = get_weather.as_crewai_tool()
Contributing
Interested in contributing? Check out our Contributing Guide for instructions on setting up the development environment and submitting changes.
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glean_agent_toolkit-0.2.0.tar.gz.
File metadata
- Download URL: glean_agent_toolkit-0.2.0.tar.gz
- Upload date:
- Size: 351.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16cfe43ff5803e8da44b25c276f0faa96f9dd5f41e3c5855ff252799fd0d5909
|
|
| MD5 |
a06c6780e66c8314bd5fccc31fb62ac0
|
|
| BLAKE2b-256 |
4a84601c96997f2b936e1e23db98b395ac439ade20343dc99fd7f2c9842c776d
|
Provenance
The following attestation bundles were made for glean_agent_toolkit-0.2.0.tar.gz:
Publisher:
publish.yml on gleanwork/glean-agent-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glean_agent_toolkit-0.2.0.tar.gz -
Subject digest:
16cfe43ff5803e8da44b25c276f0faa96f9dd5f41e3c5855ff252799fd0d5909 - Sigstore transparency entry: 230422488
- Sigstore integration time:
-
Permalink:
gleanwork/glean-agent-toolkit@ab91956def823deb067716d5eb4727f628c7daf9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gleanwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab91956def823deb067716d5eb4727f628c7daf9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file glean_agent_toolkit-0.2.0-py3-none-any.whl.
File metadata
- Download URL: glean_agent_toolkit-0.2.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b70557c8ffd51040de312195e541fba38ce3bf545df43818ae28a4dbeb3214f4
|
|
| MD5 |
845b7aad78341f9b2fd607fa1fbb4bd7
|
|
| BLAKE2b-256 |
0e29ffbb3600fd48246e480ac830b35bad4cff51202d5ac326d47559f8cc6060
|
Provenance
The following attestation bundles were made for glean_agent_toolkit-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on gleanwork/glean-agent-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
glean_agent_toolkit-0.2.0-py3-none-any.whl -
Subject digest:
b70557c8ffd51040de312195e541fba38ce3bf545df43818ae28a4dbeb3214f4 - Sigstore transparency entry: 230422490
- Sigstore integration time:
-
Permalink:
gleanwork/glean-agent-toolkit@ab91956def823deb067716d5eb4727f628c7daf9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gleanwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab91956def823deb067716d5eb4727f628c7daf9 -
Trigger Event:
workflow_dispatch
-
Statement type: