An integration package connecting Glean and LangChain
Project description
langchain-glean
Connect Glean – The Work AI platform connected to all your data – with LangChain.
Overview
The package provides:
- Chat models –
ChatGleanwraps the/v1/chatassistant API andChatGleanAgenttargets specific agents - Retrievers – typed helpers for Glean search and the people directory
- Tools – drop-in utilities for LangChain agents
Each implementation supports three input styles so you can start simple and scale up only when required:
- Plain strings (retrievers only) – pass the search query text
- Simple objects – pass a small Pydantic model (e.g.
ChatBasicRequest,SearchBasicRequest,PeopleProfileBasicRequest) - Full Glean request classes – hand-craft a
glean.models.SearchRequest,glean.models.ChatRequest, orglean.models.ListEntitiesRequest
Installation
pip install -U langchain-glean
Environment variables
export GLEAN_API_TOKEN="<your-token>" # user or global token
export GLEAN_SERVER_URL="https://your-company-be.glean.com" # full backend URL (preferred)
# Deprecated: GLEAN_INSTANCE is still supported as a fallback
# export GLEAN_INSTANCE="acme"
export GLEAN_ACT_AS="user@acme.com" # only for global tokens
Quick Start
Chat with Glean Assistant
from langchain_core.messages import HumanMessage
from langchain_glean.chat_models import ChatGlean
chat = ChatGlean()
response = chat.invoke([HumanMessage(content="When is the next company holiday?")])
print(response.content)
Need streaming? Replace invoke with stream or astream.
Chat Models
ChatGlean
Connect to the Glean Assistant API with LangChain's chat interface.
Basic usage with message list
from langchain_glean.chat_models import ChatGlean
from langchain_core.messages import HumanMessage
chat = ChatGlean()
response = chat.invoke([HumanMessage(content="Hello")])
Using the simplified request object
from langchain_glean.chat_models import ChatGlean, ChatBasicRequest
chat = ChatGlean()
response = chat.invoke(ChatBasicRequest(
message="Hello",
context=["Previous conversation context"]
))
Using the full Glean SDK request
from glean.api_client import models
from langchain_glean.chat_models import ChatGlean
chat = ChatGlean()
req = models.ChatRequest(
messages=[
models.ChatMessage(
author="USER",
message_type="CONTENT",
fragments=[models.ChatMessageFragment(text="Hello")]
)
]
)
response = chat.invoke(req)
ChatGleanAgent
Connect directly to an individual Glean agent.
from langchain_core.messages import HumanMessage
from langchain_glean.chat_models import ChatGleanAgent
agent_chat = ChatGleanAgent(agent_id="abc123")
response = agent_chat.invoke([HumanMessage(content="What are our Q4 sales targets?")])
print(response.content)
You can provide additional input fields for the agent:
response = agent_chat.invoke(
[HumanMessage(content="What are our sales targets?")],
fields={"department": "Marketing", "quarter": "Q4"}
)
Retrievers
GleanSearchRetriever
Search Glean's unified index and get results as LangChain documents.
Simple string query
from langchain_glean.retrievers import GleanSearchRetriever
retriever = GleanSearchRetriever()
results = retriever.invoke("quarterly report")
Using the simplified request object
from langchain_glean.retrievers import GleanSearchRetriever, SearchBasicRequest
retriever = GleanSearchRetriever()
results = retriever.invoke(SearchBasicRequest(
query="quarterly report",
data_sources=["confluence", "drive"]
))
Using the full Glean SDK request
from glean.api_client import models
from langchain_glean.retrievers import GleanSearchRetriever
retriever = GleanSearchRetriever()
req = models.SearchRequest(
query="quarterly report",
page_size=5,
facet_filters=[models.FacetFilter(name="datasource", values=["confluence"])]
)
results = retriever.invoke(req)
GleanPeopleProfileRetriever
Search Glean's people directory and get results as LangChain documents.
Simple string query
from langchain_glean.retrievers import GleanPeopleProfileRetriever
people = GleanPeopleProfileRetriever()
results = people.invoke("jane doe")
Using the simplified request object
from langchain_glean.retrievers import GleanPeopleProfileRetriever, PeopleProfileBasicRequest
people = GleanPeopleProfileRetriever()
results = people.invoke(PeopleProfileBasicRequest(
query="staff engineer",
page_size=3
))
Using the full Glean SDK request
from glean.api_client import models
from langchain_glean.retrievers import GleanPeopleProfileRetriever
people = GleanPeopleProfileRetriever()
req = models.ListEntitiesRequest(
entity_type="PEOPLE",
query="staff engineer",
page_size=3
)
results = people.invoke(req)
Tools for LangChain Agents
Available Tools
| Tool name | Purpose | Arguments |
|---|---|---|
GleanSearchTool |
Search content | Query string or SearchBasicRequest |
GleanPeopleProfileSearchTool |
Find people | Query string or PeopleProfileBasicRequest |
GleanChatTool |
Converse with Glean Assistant | Message string or ChatBasicRequest |
GleanListAgentsTool |
List available agents | None |
GleanGetAgentSchemaTool |
Get agent input schema | agent_id (str) |
GleanRunAgentTool |
Run a specific agent | agent_id (str), fields (dict) |
Basic Search Tool Example
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_glean.retrievers import GleanSearchRetriever
from langchain_glean.tools import GleanSearchTool
# Create the tool
retriever = GleanSearchRetriever()
search_tool = GleanSearchTool(retriever=retriever)
# Set up the agent
llm = ChatOpenAI(model="gpt-3.5-turbo")
prompt = ChatPromptTemplate.from_messages([
("system", "You can search our knowledge base when needed."),
("user", "{input}"),
])
agent = create_openai_tools_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool])
# Run the agent
result = executor.invoke({"input": "Find the latest QBR deck"})
print(result["output"])
Using Glean Agent Tools
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_glean.tools import GleanListAgentsTool, GleanGetAgentSchemaTool, GleanRunAgentTool
# Create tools
list_agents_tool = GleanListAgentsTool()
get_schema_tool = GleanGetAgentSchemaTool()
run_agent_tool = GleanRunAgentTool()
# Set up the agent
llm = ChatOpenAI(model="gpt-4")
prompt = ChatPromptTemplate.from_messages([
("system", "You can find and run Glean agents to answer questions."),
("user", "{input}"),
])
agent = create_openai_tools_agent(llm, [list_agents_tool, get_schema_tool, run_agent_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[list_agents_tool, get_schema_tool, run_agent_tool])
# Run the agent
result = executor.invoke({
"input": "Find an agent that can help with sales data and run it to get Q4 forecast"
})
print(result["output"])
Advanced Usage
Full Request Objects
Pass any SDK request class (SearchRequest, ChatRequest, ListEntitiesRequest) directly for complete API control.
Async Support
Every retriever and tool exposes ainvoke and async streams:
# Async search
documents = await retriever.ainvoke("monthly revenue")
# Async streaming chat
async for chunk in chat.astream([HumanMessage(content="Hello")]):
print(chunk.content, end="", flush=True)
Custom Agent Config
Override model behavior per call:
chat.invoke(
ChatBasicRequest(message="Summarise last quarter"),
agent_config={"agent": "GPT", "mode": "SEARCH"},
timeout_millis=30_000,
)
Resume a Chat
Either pass chat_id per call or set it as a property:
chat = ChatGlean()
chat.chat_id = "abc123"
chat.invoke([HumanMessage(content="Continue...")])
Contributing
mise install && mise run setupmise run lint && mise run test- Open a PR!
Links
- Glean API – https://developer.glean.com
- LangChain docs – https://python.langchain.com
- Source code – https://github.com/langchain-ai/langchain-glean
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 langchain_glean-0.4.0.tar.gz.
File metadata
- Download URL: langchain_glean-0.4.0.tar.gz
- Upload date:
- Size: 130.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef1b957d861f6960e102b86720b3dcf558bb18ff90f833be8de380dc16337854
|
|
| MD5 |
5704c70f2ae2d7abd7dd420dfb1bcb96
|
|
| BLAKE2b-256 |
6cbb6ad25df3c2b66090f02f69126433142dcf7955f56139f1558e3620d2685b
|
Provenance
The following attestation bundles were made for langchain_glean-0.4.0.tar.gz:
Publisher:
publish.yml on gleanwork/langchain-glean
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_glean-0.4.0.tar.gz -
Subject digest:
ef1b957d861f6960e102b86720b3dcf558bb18ff90f833be8de380dc16337854 - Sigstore transparency entry: 1044642249
- Sigstore integration time:
-
Permalink:
gleanwork/langchain-glean@62ecd0b54b3dc9170d4634353cfd8d7865bbe6b7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/gleanwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@62ecd0b54b3dc9170d4634353cfd8d7865bbe6b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_glean-0.4.0-py3-none-any.whl.
File metadata
- Download URL: langchain_glean-0.4.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d7f342e3fbaabb4cc5c7d44f82e87278a3dc36fcbab532dfef8318299f082fe
|
|
| MD5 |
ceb2760eca72dfc7947d3290833c79b4
|
|
| BLAKE2b-256 |
37a67302e134f292c7c677e493ec231d40950e26a6e40043df3da2fc784e5d57
|
Provenance
The following attestation bundles were made for langchain_glean-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on gleanwork/langchain-glean
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_glean-0.4.0-py3-none-any.whl -
Subject digest:
0d7f342e3fbaabb4cc5c7d44f82e87278a3dc36fcbab532dfef8318299f082fe - Sigstore transparency entry: 1044642288
- Sigstore integration time:
-
Permalink:
gleanwork/langchain-glean@62ecd0b54b3dc9170d4634353cfd8d7865bbe6b7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/gleanwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@62ecd0b54b3dc9170d4634353cfd8d7865bbe6b7 -
Trigger Event:
push
-
Statement type: