Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.lithoblocks.com/llms.txt

Use this file to discover all available pages before exploring further.

Use LithoBlocks with LlamaIndex so your agent can send Slack messages via templates. The agent selects a template and payload; a tool calls the LithoBlocks API. You get deterministic messages and far fewer tokens because the LLM does not generate Block Kit JSON. The resulting LLM savings help offset LithoBlocks cost, with net cost reduction at higher volumes.

Prerequisites

  • LithoBlocks API key and at least one template
  • Connecting Slack for your LithoBlocks workspace
  • LlamaIndex installed (pip install llama-index or equivalent)

Why use LithoBlocks with LlamaIndex

  • Deterministic messages — The agent picks a template and data; the tool sends it. No Block Kit in the prompt.
  • Lower LLM cost — The agent outputs only template_id and a small payload; the tool does the HTTP call. LLM savings help offset LithoBlocks cost; at higher volumes, net cost reduction.
  • Consistency — Same layout every time; fewer malformed blocks.

Implementing the tool

Define a LlamaIndex tool that accepts template_id and payload (mapped to API field data), then POSTs to the LithoBlocks API.
import os
from typing import Optional

import requests
from llama_index.core.tools import FunctionTool

LITHOBLOCKS_API_KEY = os.environ.get("LITHOBLOCKS_API_KEY")
BASE_URL = "https://api.lithoblocks.com"

def send_slack_message(template_id: str, payload: dict, channel_id: Optional[str] = None) -> str:
    """Send a Slack message using a LithoBlocks template. Use when the user wants to notify someone in Slack.
    template_id: The LithoBlocks template ID (e.g. from your dashboard).
    payload: JSON object matching the template's placeholders (e.g. {"user": {"name": "Alice"}, "message": "Hello"}).
    channel_id: Optional Slack channel ID for send (see API reference for other destinations).
    """
    url = f"{BASE_URL}/v1/templates/send"
    headers = {
        "Authorization": f"Bearer {LITHOBLOCKS_API_KEY}",
        "Content-Type": "application/json",
    }
    body = {"template_id": template_id, "data": payload}
    if channel_id:
        body["channel_id"] = channel_id
    response = requests.post(url, json=body, headers=headers)
    if response.ok:
        return f"Message sent successfully: {response.json().get('message_ts', 'ok')}"
    return f"Failed to send message: {response.status_code} {response.text}"

send_slack_tool = FunctionTool.from_defaults(
    fn=send_slack_message,
    name="send_slack_message",
    description="Send a Slack message using a LithoBlocks template. Provide template_id and payload (dict matching template placeholders).",
)
For compile (get blocks without sending), use POST /v1/templates/compile with body {"template_id": "...", "data": {...}}. See the API reference for request/response shapes.

Using the tool in an agent

Add the tool to your agent. The agent can then invoke “send Slack message” with template_id and payload.
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-4o-mini", temperature=0)
agent = ReActAgent.from_tools([send_slack_tool], llm=llm, verbose=True)
response = agent.chat("Send a Slack message to #general saying the report is ready.")
The agent will call send_slack_message with the appropriate template_id and payload for your template.

Next steps

AI agents overview

Why templates and agents fit together.

API reference

Endpoints, auth, and parameters.

Placeholders

Template data shape and syntax.