Example implementations showing how to use Glean to access your company's knowledge base with common AI agent frameworks.
This repository demonstrates how to integrate Glean with different AI agent frameworks. These examples show how to:
- Search and retrieve information from your Glean knowledge base
- Use Glean's chat capabilities for natural language interactions
Uses LangChain's built-in Glean integrations:
GleanSearchRetriever
for semantic search over your knowledge baseChatGlean
for conversational interactions- Example shows both standalone usage and as part of an agent
Shows how to build stateful agents with Glean:
- Maintains conversation context across interactions
- Demonstrates workflow control with Glean's search and chat
- Handles complex multi-step queries
Shows how to use Glean with OpenAI's Assistant framework:
- Uses Glean's MCP server to expose search and chat as Assistant tools
- Demonstrates function calling with Glean's capabilities
- Shows how to maintain context in conversations
In order to setup and run these examples, follow these steps:
-
Prerequisites
- Python 3.13+
- Glean API credentials (subdomain and API token with the
chat
andsearch
scopes) - OpenAI API key (for OpenAI and LangChain examples)
-
Installation
-
install Go-Task:
# macOS with Homebrew brew install go-task/tap/go-task # Linux/macOS with curl sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d # Windows with Scoop scoop install task
-
install uv
# macOS with Homebrew brew install uv # Linux/macOS with curl curl -LsSf https://astral.sh/uv/install.sh | sh # Windows powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
-
Then install the package and set up your environment:
# install dependencies task install # set up environment variables export GLEAN_SUBDOMAIN=your-instance export GLEAN_API_TOKEN=your_token export OPENAI_API_KEY=your_key # If using OpenAI examples
-
-
Running Examples
First, start the server:
# Start the server task serve
Then in a new terminal, you can run examples:
# List available examples task list # Run a specific example task run -- langchain_search "What are our company policies?"
The server will handle requests from multiple examples, so you only need to start it once.
Each example follows a consistent pattern:
- Authenticates with Glean using your credentials
- Sets up the agent framework with appropriate tools/capabilities
- Handles queries by searching or chatting through Glean
- Returns formatted responses
The examples are structured to be:
- Easy to understand and modify
- Production-ready with proper error handling
- Maintainable with clear separation of concerns