Agents API Overview
The Agents API provides programmatic control over Glean agents, enabling you to build, deploy, and manage AI agents across your organization. This API allows you to integrate Glean's agent capabilities directly into your applications and workflows.
Use Cases
Agent Discovery
Agent Execution
Schema Inspection
Real-time Integration
External Application Integration
API Endpoints
Method | Endpoint | Purpose |
---|---|---|
GET | /rest/api/v1/agents/{agent_id} | Retrieve an agent Returns details of an [agent](https://developers.glean.com/agents/agents-api) created in the Agent Builder. |
GET | /rest/api/v1/agents/{agent_id}/schemas | List an agent's schemas Return [agent](https://developers.glean.com/agents/agents-api)'s input and output schemas. You can use these schemas to detect changes to an agent's input or output structure. |
POST | /rest/api/v1/agents/search | Search agents Search for [agents](https://developers.glean.com/agents/agents-api) by agent name. |
POST | /rest/api/v1/agents/runs/stream | Create an agent run and stream the response Executes an [agent](https://developers.glean.com/agents/agents-api) run and returns the result as a stream of server-sent events (SSE). |
POST | /rest/api/v1/agents/runs/wait | Create an agent run and wait for the response Executes an [agent](https://developers.glean.com/agents/agents-api) run and returns the final response. |
Agent Builder Integration
Agents are created and configured through Glean's Agent Builder interface. The API provides programmatic access to these user-created agents.
Finding Agent IDs
To use an agent programmatically, you'll need its Agent ID. You can find this in the Agent Builder URL:
The Agent ID appears in the URL path: /admin/agents/{agentId}
Protocol Compatibility
The Agents API implements a subset of the LangChain Agent Protocol, specifically:
This ensures compatibility with any agent runtime that supports this standard protocol.
Authentication & Setup
Before using the Agents API, ensure you have:
- API Token: A user-scoped API token with
agents
scope - Agent Access: Permissions to access the agents you want to use
- Base URL: Your organization's Glean instance URL
Common Integration Patterns
Streaming Responses
For real-time chat interfaces, use the streaming endpoints to provide immediate feedback:
const response = await fetch('/agents/agent-123/runs', {
method: 'POST',
headers: { 'Authorization': 'Bearer your-token' },
body: JSON.stringify({
query: 'What is our vacation policy?',
stream: true
})
});
const reader = response.body.getReader();
// Process streaming chunks...
Batch Processing
For bulk operations, use the blocking endpoints to process multiple queries:
import asyncio
from glean.api_client import Glean
async def process_queries(queries):
with Glean(api_token="your-token", instance="your-org") as client:
tasks = [
client.agents.create_and_wait_run(
agent_id="agent-123",
query=query
) for query in queries
]
return await asyncio.gather(*tasks)
Next Steps
- Browse the API endpoint documentation above for detailed request/response schemas
- Check out the Building Agents guide for different ways to create agent-powered applications
- Review authentication requirements for API access