Loading...
The @hazeljs/ops-agent package provides an AI-powered DevOps/SRE assistant for Jira tickets, Slack notifications, and incident coordination. It builds on @hazeljs/agent, @hazeljs/ai, and @hazeljs/rag to deliver a ready-to-use ops agent with built-in tools.
The Ops Agent is a specialized agent pre-configured for DevOps workflows:
npm install @hazeljs/ops-agent @hazeljs/ai @hazeljs/agent @hazeljs/core @hazeljs/rag
Peer dependencies: @hazeljs/agent, @hazeljs/ai, @hazeljs/core, @hazeljs/rag (install them in your app).
import { AIEnhancedService } from '@hazeljs/ai';
import {
createOpsRuntime,
runOpsAgent,
createJiraTool,
createSlackTool,
} from '@hazeljs/ops-agent';
async function main() {
const jiraTool = createJiraTool();
const slackTool = createSlackTool();
const runtime = createOpsRuntime({
aiService: new AIEnhancedService(),
tools: { jira: jiraTool, slack: slackTool },
model: 'gpt-4',
});
const result = await runOpsAgent(runtime, {
input: 'Create a Jira ticket in PROJ with summary "DB connection pool exhaustion" and post to #incidents.',
sessionId: `ops-${Date.now()}`,
});
console.log(result.response);
console.log(`Completed in ${result.steps} steps (${result.duration}ms)`);
}
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY | OpenAI API key for the LLM | Yes |
JIRA_HOST | Jira host (e.g. https://your-domain.atlassian.net) | For real Jira |
JIRA_EMAIL | Email for Jira Basic auth | For real Jira |
JIRA_API_TOKEN | API token from Atlassian | For real Jira |
SLACK_BOT_TOKEN | Bot token (xoxb-...) from Slack app OAuth | For real Slack |
Without Jira/Slack credentials, the adapters return placeholder responses so you can develop and test locally. Set the env vars for real integrations.
const jiraTool = createJiraTool({
host: process.env.JIRA_HOST!,
email: process.env.JIRA_EMAIL!,
apiToken: process.env.JIRA_API_TOKEN!,
timeoutMs: 15000,
});
const slackTool = createSlackTool({
token: process.env.SLACK_BOT_TOKEN!,
timeoutMs: 10000,
});
The Ops Agent exposes four tools to the LLM:
Create a new Jira issue (task, bug, or story).
| Parameter | Type | Required | Description |
|---|---|---|---|
project | string | Yes | Project key (e.g. PROJ) |
summary | string | Yes | Issue summary/title |
description | string | No | Detailed description |
issueType | string | No | Task, Bug, or Story (default: Task) |
labels | array | No | Optional labels |
Requires approval by default.
Add a comment to an existing Jira issue.
| Parameter | Type | Required | Description |
|---|---|---|---|
issueKey | string | Yes | Issue key (e.g. PROJ-123) |
body | string | Yes | Comment text |
Fetch details of a Jira issue.
| Parameter | Type | Required | Description |
|---|---|---|---|
issueKey | string | Yes | Issue key (e.g. PROJ-123) |
Post a message to a Slack channel (optionally in a thread).
| Parameter | Type | Required | Description |
|---|---|---|---|
channel | string | Yes | Channel name or ID (#incidents or C123456) |
text | string | Yes | Message text |
threadTs | string | No | Thread timestamp for replies |
Requires approval by default.
Creates an AgentRuntime configured with the Ops Agent, memory, and tools.
export interface CreateOpsRuntimeOptions {
aiService: AIServiceAdapter; // e.g. AIEnhancedService from @hazeljs/ai
tools: OpsAgentToolsConfig; // { jira, slack } from createJiraTool, createSlackTool
model?: string; // default: 'gpt-4'
ragService?: unknown; // optional RAG for runbooks/docs search
memoryManager?: unknown; // optional; uses in-memory BufferMemory by default
}
Convenience helper to run the ops agent for a single request.
const result = await runOpsAgent(runtime, {
input: 'Create PROJ-123 and notify #incidents',
sessionId?: string,
userId?: string,
});
// Returns { response: string; steps: number; duration: number }
Implement JiraToolLike or SlackToolLike to plug in your own adapters (e.g. different ticketing systems):
interface JiraToolLike {
createTicket(input: { project; summary; description?; issueType?; labels? }): Promise<{ key; id; url? }>;
addComment(input: { issueKey; body }): Promise<{ id }>;
getTicket(input: { issueKey }): Promise<{ key; summary; status?; description?; url? }>;
}
interface SlackToolLike {
postToChannel(input: { channel; text; threadTs? }): Promise<{ ts; channel }>;
}
Pass a ragService to enable runbook and docs search during incident triage:
import { RAGService } from '@hazeljs/rag';
const ragService = new RAGService(/* ... */);
const runtime = createOpsRuntime({
aiService: new AIEnhancedService(),
tools: { jira: jiraTool, slack: slackTool },
ragService,
});
The agent can then query your runbooks before suggesting actions.
By default, createOpsRuntime uses in-memory BufferMemory (last 50 messages). For production, pass a MemoryManager with a persistent backend:
import { MemoryManager, RedisMemory } from '@hazeljs/rag';
const memoryManager = new MemoryManager(
new RedisMemory({ client: redisClient }),
{ maxConversationLength: 20, entityExtraction: true }
);
const runtime = createOpsRuntime({
aiService: new AIEnhancedService(),
tools: { jira: jiraTool, slack: slackTool },
memoryManager,
});
See the full example in the HazelJS monorepo: example/src/ops/ops-agent-example.ts. Run it with:
OPENAI_API_KEY=your-key npm run ops:agent
Add JIRA_HOST, JIRA_EMAIL, JIRA_API_TOKEN, and SLACK_BOT_TOKEN for real Jira and Slack integration.