Glean Agent Toolkit
A Python toolkit that makes it easy to integrate Glean's powerful search and knowledge discovery capabilities into your AI agents. Use pre-built tools with popular agent frameworks or create your own custom tools that work across multiple platforms.
When to Use
- Working with multiple agent frameworks (OpenAI, LangChain, CrewAI, Google ADK)
- Need production-ready Glean tools (search, employee lookup, calendar, etc.)
- Want to define tools once and use across frameworks
- Building agents that require enterprise knowledge access
glean-agent-toolkit
Official Python toolkit for adapting Glean's enterprise tools across multiple agent frameworks
Framework Support
The toolkit provides adapters for major agent frameworks:
Framework | Installation | Use Case |
---|---|---|
OpenAI Assistants | pip install glean-agent-toolkit[openai] | Direct API integration with OpenAI |
LangChain | pip install glean-agent-toolkit[langchain] | Rich Python agent ecosystem |
CrewAI | pip install glean-agent-toolkit[crewai] | Multi-agent collaboration |
Google ADK | pip install glean-agent-toolkit[adk] | Google's Agent Development Kit |
Available Tools
The toolkit comes with production-ready tools that connect to Glean's capabilities:
glean_search
: Search your company's knowledge baseemployee_search
: Find employees by name, team, department, or expertisecalendar_search
: Find meetings and calendar eventscode_search
: Search your company's source code repositoriesgmail_search
: Search Gmail messages and conversationsoutlook_search
: Search Outlook mail and calendar itemsweb_search
: Search the public web for external informationai_web_search
: Query Google Gemini for AI-powered web information
Example: Multi-Framework Usage
from glean.agent_toolkit.tools import glean_search, employee_search
import os
# Ensure environment variables are set
os.environ["GLEAN_API_TOKEN"] = "your-api-token"
os.environ["GLEAN_INSTANCE"] = "your-instance-name"
# Use with LangChain
langchain_search = glean_search.as_langchain_tool()
langchain_employees = employee_search.as_langchain_tool()
# Use with CrewAI
crewai_search = glean_search.as_crewai_tool()
crewai_employees = employee_search.as_crewai_tool()
# Use with OpenAI Assistants
openai_search = glean_search.as_openai_tool()
openai_employees = employee_search.as_openai_tool()
Custom Tool Creation
Define your own tools once using the @tool_spec
decorator and use them across any framework:
from glean.agent_toolkit import tool_spec
from pydantic import BaseModel
import requests
class WeatherResponse(BaseModel):
temperature: float
condition: str
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."""
return WeatherResponse(
temperature=22.5,
condition="sunny",
city=city
)
# Use across all supported frameworks
openai_weather = get_weather.as_openai_tool()
langchain_weather = get_weather.as_langchain_tool()
crewai_weather = get_weather.as_crewai_tool()
Complete Example: Multi-Agent System
from glean.agent_toolkit.tools import glean_search, employee_search, calendar_search
from crewai import Agent, Task, Crew
import os
os.environ["GLEAN_API_TOKEN"] = "your-api-token"
os.environ["GLEAN_INSTANCE"] = "your-instance-name"
# Create agents with different specializations
researcher = Agent(
role='Research Specialist',
goal='Find relevant company information and documents',
backstory='Expert at searching and analyzing company knowledge',
tools=[glean_search.as_crewai_tool()]
)
hr_specialist = Agent(
role='HR Specialist',
goal='Find employee information and schedule meetings',
backstory='Expert at employee relations and scheduling',
tools=[
employee_search.as_crewai_tool(),
calendar_search.as_crewai_tool()
]
)
# Define tasks
research_task = Task(
description='Find information about our remote work policy',
agent=researcher
)
scheduling_task = Task(
description='Find the HR manager and check their availability this week',
agent=hr_specialist
)
# Create and run the crew
crew = Crew(
agents=[researcher, hr_specialist],
tasks=[research_task, scheduling_task]
)
result = crew.kickoff()
Key Benefits
- Framework Agnostic: Write tools once, use everywhere
- Production-Ready: Pre-built tools for common Glean operations
- Easy Integration: Simple adapter pattern for different frameworks
- Consistent API: Same tool interface across all platforms
- Enterprise Features: Built-in support for Glean's enterprise capabilities
Advanced Usage
Tool Composition
from glean.agent_toolkit.tools import glean_search, employee_search
from glean.agent_toolkit import tool_spec
@tool_spec(
name="research_and_contact",
description="Research a topic and find relevant experts to contact"
)
def research_and_contact(topic: str) -> dict:
"""Research a topic and find experts."""
# Search for documents
search_results = glean_search.execute(topic)
# Extract mentioned people from results
mentioned_people = extract_people_from_results(search_results)
# Find employee details
experts = []
for person_name in mentioned_people:
employee_info = employee_search.execute(person_name)
if employee_info:
experts.append(employee_info)
return {
"research_results": search_results,
"experts": experts,
"summary": f"Found {len(search_results)} documents and {len(experts)} experts on {topic}"
}
def extract_people_from_results(results):
"""Extract people mentioned in search results."""
# Implementation to parse names from document content
pass
Error Handling and Retries
from glean.agent_toolkit.tools import glean_search
from glean.agent_toolkit import tool_spec
import time
@tool_spec(
name="robust_search",
description="Search with automatic retries and error handling"
)
def robust_search(query: str, max_retries: int = 3) -> dict:
"""Search with retry logic."""
for attempt in range(max_retries):
try:
return glean_search.execute(query)
except Exception as e:
if attempt < max_retries - 1:
time.sleep(2 ** attempt) # Exponential backoff
continue
else:
return {
"error": f"Search failed after {max_retries} attempts: {str(e)}",
"results": []
}
Next Steps
- Get Started: Install the toolkit with
pip install glean-agent-toolkit
- Documentation: Visit the GitHub repository for complete documentation
- Examples: Check out the example notebooks
- Community: Join the discussion in our GitHub Discussions