Skip to main content

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

Search and retrieve available agents in your deployment to understand what capabilities are available for integration.

Agent Execution

Create and manage agent runs with streaming or blocking responses for real-time chat interfaces and batch processing.

Schema Inspection

Examine agent input and output schemas for integration planning and validation in your applications.

Real-time Integration

Stream agent responses to chat interfaces and applications for immediate user feedback and interaction.

External Application Integration

Embed Glean agents into your existing systems and workflows for seamless AI-powered assistance.

API Endpoints

MethodEndpointPurpose
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}/schemasList 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/searchSearch agents
Search for [agents](https://developers.glean.com/agents/agents-api) by agent name.
POST/rest/api/v1/agents/runs/streamCreate 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/waitCreate 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.

Agent Builder Interface

Finding Agent IDs

To use an agent programmatically, you'll need its Agent ID. You can find this in the Agent Builder URL:

Agent ID in 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:

  • Agents: Agent discovery and metadata
  • Runs: Agent execution and run management

This ensures compatibility with any agent runtime that supports this standard protocol.

Authentication & Setup

Before using the Agents API, ensure you have:

  1. API Token: A user-scoped API token with agents scope
  2. Agent Access: Permissions to access the agents you want to use
  3. 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