This guide builds a complete docket monitoring agent using LangChain and DocketLayer. By the end, you will have an agent that checks a list of federal cases for new filings on a schedule, pays $0.99 per query via x402, and emails you when something changes.

Prerequisites: Python 3.10+, a Solana wallet funded with USDC (see the wallet setup guide), and an OpenAI or Anthropic API key.

The four components

01

Agent framework

LangChain provides reasoning, tool use, and the execution loop. Open source, extensively documented.

02

Solana wallet + x402

Your agent's payment account. The x402 library handles USDC payments to DocketLayer automatically.

03

DocketLayer integration

Your agent submits a case ID, pays $0.99, gets structured docket changes back as JSON.

04

Notification layer

How the agent tells you when something changes. Email, Slack, webhook — your choice.

Install and configure

pip install langchain langchain-openai x402 solana python-dotenv

Create a .env file. Never commit this to a repository.

SOLANA_PRIVATE_KEY=your_base64_encoded_private_key
OPENAI_API_KEY=your_openai_api_key
[email protected]
ALERT_EMAIL_PASSWORD=your_app_password
[email protected]

Create the DocketLayer tool

import os
from langchain.tools import tool
from x402 import PaymentClient
from dotenv import load_dotenv

load_dotenv()

payment_client = PaymentClient(
  private_key=os.environ["SOLANA_PRIVATE_KEY"],
  network="solana-mainnet",
  currency="USDC"
)

@tool
def check_docket(case_id: str, court_code: str, last_checked: str) -> str:
  """Check a federal case for new filings since last_checked.
  Args: case_id (e.g. 1:24-cv-01234), court_code (e.g. nysd),
  last_checked (ISO 8601 timestamp)"""

  response = payment_client.get(
    "https://api.docketlayer.com/v1/case",
    json={"case_id": case_id, "court_code": court_code, "last_checked": last_checked}
  )
  data = response.json()
  if not data["changed"]:
    return f"No changes on {case_id} since {last_checked}."
  filings = data["new_filings"]
  summary = f"Case {case_id}: {len(filings)} new filing(s):\n"
  for f in filings:
    summary += f"- {f['filing_type'].title()}: {f['description']} ({f['filed_at']})\n"
  return summary

Build the monitoring agent

from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

CASES = [
  {"case_id": "1:24-cv-01234", "court_code": "nysd"},
  {"case_id": "1:22-bk-11068", "court_code": "deb"},
]

llm = ChatOpenAI(model="gpt-4o", api_key=os.environ["OPENAI_API_KEY"])
prompt = ChatPromptTemplate.from_messages([
  ("system", "You are a federal court monitoring agent. Check each case for new docket activity and summarize changes clearly."),
  ("human", "{input}"),
  ("placeholder", "{agent_scratchpad}")
])
agent = create_tool_calling_agent(llm, [check_docket], prompt)
executor = AgentExecutor(agent=agent, tools=[check_docket])

def run_cycle(last_checked):
  case_list = "\n".join([f"- {c['case_id']} in {c['court_code']}" for c in CASES])
  result = executor.invoke({"input": f"Check these cases since {last_checked}:\n{case_list}"})
  return result["output"]

Add notifications and scheduling

import smtplib, time
from email.mime.text import MIMEText
from datetime import datetime, timezone

def send_alert(summary):
  msg = MIMEText(summary)
  msg["Subject"] = "DocketLayer — New court activity"
  msg["From"] = os.environ["ALERT_FROM_EMAIL"]
  msg["To"] = os.environ["ALERT_TO_EMAIL"]
  with smtplib.SMTP_SSL("smtp.gmail.com", 465) as s:
    s.login(os.environ["ALERT_FROM_EMAIL"], os.environ["ALERT_EMAIL_PASSWORD"])
    s.send_message(msg)

last_checked = datetime.now(timezone.utc).isoformat()
while True:
  summary = run_cycle(last_checked)
  if "new filing" in summary.lower(): send_alert(summary)
  last_checked = datetime.now(timezone.utc).isoformat()
  time.sleep(3600) # Check every hour

Deploy for always-on monitoring

For production, deploy to a cloud server rather than running on your laptop. Three straightforward options:

  • Railway — Deploy Python scripts with a few clicks. Low cost for small agents. railway.app
  • Render — Simple cloud hosting with a generous free tier for background workers. render.com
  • Fly.io — Lightweight and inexpensive for low-compute scripts. fly.io

Once deployed, your agent runs continuously — checking cases, paying $0.99 per query, and alerting you only when something changes. Monitoring 100 cases daily costs approximately $300/month — less than a single billable hour for the same monitoring work done manually.