OpenClaw + LangGraph playbook
Scheduling, subagents, permissions, and messaging in one system
It’s easy to build an agent that talks. Building one that remembers things, sends messages, runs on a schedule, and generally makes itself useful is a different challenge. That’s where LangGraph and OpenClaw make an interesting combination.
Let’s build one.
The first step is creating the primary agent and establishing its responsibilities through a system prompt.
import os
from datetime import datetime
from langclaw import Langclaw
from langclaw.gateway.commands import CommandContext
# Initialize the master agent application interface
app = Langclaw(
system_prompt=(
“## Corporate Intelligence Agent\n”
“You are a corporate intelligence analyst. You track market trends “
“and draft precise outreach sequences based on current events.\n”
“Delegate deep multi-source research tasks to the web-researcher subagent.”
),
)Tools allow the agent to access capabilities beyond language generation. In this example, the agent can retrieve market intelligence data.
# Custom Tool: Data Extraction Layer
@app.tool()
async def fetch_market_news(sector: str) -> dict:
“”“Extract breaking market developments for a specific commercial sector.”“”
# This acts as a standard tool available to your core reasoning models
return {
“timestamp”: datetime.now().isoformat(),
“sector”: sector,
“headline”: “Warehouse Automation Demands Surge Amid Labor Reshuffling”,
“body”: “Logistics providers face margin pressures, driving immediate infrastructure upgrades.”
}Rather than placing all reasoning responsibilities inside a single agent, LangClaw allows specialised subagents to handle focused tasks.
# Subagent Delegation: Isolated Reasoning Context
app.subagent(
“web-researcher”,
description=”Performs deep multi-step web analysis and synthesis.”,
system_prompt=”You are an investigative researcher. Identify technical pain points and list them.”,
tools=[”web_fetch”, “web_search”],
output=”channel”, # Streams output directly back to the active user channel
)Role-based permissions make it possible to expose different capabilities to different groups of users.
# Role-Based Access Control: Security Gateways
app.role(”premium_analyst”, tools=[”*”])
app.role(”basic_user”, tools=[”fetch_market_news”])Agents do not need to wait for user prompts. Using cron schedules, they can execute tasks automatically.
# Automated Execution: Background Scheduler
@app.cron(”0 8 * * 1-5”) # Executes Monday through Friday at 8:00 AM
async def automated_morning_brief():
“”“Scans market trends autonomously and publishes digests to the user feed.”“”
raw_data = await fetch_market_news(sector=”Logistics”)
instruction = f”Synthesize this market report for the main channel: {raw_data[’body’]}”
# Compile runtime structure down to LangGraph for invocation
compiled_agent = app.compile()
analysis = await compiled_agent.ainvoke(
{”messages”: [{”role”: “user”, “content”: instruction}]},
config={”configurable”: {”subagent”: “web-researcher”}}
)
# Broadcast the completed report directly to your active chat channel
await app.gateway.send_message(
channel=”management_feed”,
text=f”🔔 **Automated Market Digest**\n\n{analysis[’messages’][-1].content}”
)Not every task requires an LLM. For predictable workflows, slash commands can bypass the model entirely.
# Slash Command: High-Speed Utility Routing
@app.command(”template”, description=”Generate static outreach copy without AI overhead”)
async def outreach_template_cmd(ctx: CommandContext) -> str:
“”“Returns a structured outreach framework directly, bypassing the LLM entirely.”“”
args = ctx.message.text.split(’”’)
client_name = args[1] if len(args) > 1 else “Colleague”
# Bypassing the LLM completely saves computation costs and provides sub-millisecond responses
return (
f”📩 **System Template Generated**\n\n”
f”Hello {client_name},\n\n”
f”I noted your team’s footprint in the logistics sector. Given recent automation trends, “
f”I wanted to connect to share notes on how regional hubs are optimizing their margins.\n\n”
f”Regards,\n[Internal System]”
)Once the components are assembled, launching the runtime is straightforward.
if __name__ == “__main__”:
app.run()Once the runtime is launched, the agent becomes more than a collection of functions and workflows. It becomes a persistent service that can receive requests, execute tasks, and communicate results through your chosen channels.
Let’s see how that works.
What happens when the agent goes live
When you invoke app.run(), LangClaw spins up a persistent asynchronous gateway server. It does not wait for a single terminal input; it establishes a permanent network listener.
Interaction happens entirely through your chosen deployment endpoints:
Production chat channels: By adding tokens for Telegram, Discord, or Slack into your .env configuration file, your script logs into those platforms as a live bot user.
LLM invocations: When a user types a natural language question into the chat, LangClaw pipes the string into your LangChain model, runs the necessary code tools, and formats the response.
The slash command route: When a user types
/template “Alex”, the gateway identifies the leading slash character. It isolates the instruction, skips the LLM reasoning step, runs the native Python function, and returns the text.
Hosting your agent for less than £5 per month
Deploying a traditional enterprise application often brings significant server management costs. However, because this framework relies on an event-driven architecture and asynchronous IO libraries, it requires minimal computing resources.
You can host this entire stack for under £5 per month using modern cloud infrastructure.
Virtual Private Servers (VPS)
Platforms like DigitalOcean, Hetzner, or Linode offer entry-level Linux instances with 1GB of RAM and 1 CPU core. Because LangClaw uses a non-blocking asyncio event loop, a single micro-instance can easily manage hundreds of concurrent chat messages and automated cron tasks without breaking a sweat.
Process Management
To ensure your agent runs continuously, you wrap the script using a Linux system process supervisor like systemd or Supervisor. If the server reboots or encounters an unhandled API timeout, the operating system brings the agent back online instantly, providing 99.9% uptime with zero manual maintenance.
We’ve set up an agent, we’ve talked about messaging and about the advantages of full control, about the hosting. Building your automation stack with this methodology yields three immediate operational improvements:
Zero-token utilities: By routing routine structural actions through slash commands, you bypass LLM token fees entirely. This provides instantaneous responses while eliminating API runtime costs for predictable tasks.
Decoupled architecture: Your core business logic remains completely separate from your communication channels. If your team decides to migrate from Telegram to Slack, you alter a single environment variable. The underlying tools, subagents, and schedules require no modifications.
Production readiness: You move from an abstract local script to an enterprise-grade agent. The system manages its own user security roles, schedules its own data retrieval cycles, and operates autonomously around the clock.
Let us know how you get on!


