A LangGraph agent that turns a one-sentence brief into about 10 people with verified work emails and a draft campaign, then stops at the approval link.
It uses LangChain's create_agent, which builds a LangGraph graph, with five tools from the official layrcake Python SDK. Nothing is sent. A person approves the campaign in the Layrcake console before any email goes out.
This kit is in Python because most LangGraph users work in Python.
find_leadsfinds people who match your brief.enrichgets each person's work email.verify_emailchecks every address. Onlyvalidandcatch_all_validaddresses are kept.create_campaignsaves a short draft sequence for the kept people. Drafts never send.launch_campaignreturns a preview and an approval link. The graph ends there.
The tools and their rules come from the layrcake SDK's layrcake.agent_tools module, the same code behind the LangChain, LlamaIndex and CrewAI packages. layrcake_tools.py hands five of them to LangChain, so the rules stay in code:
- Each tool's name, description with its price, and argument schema come from the SDK.
launch_campaignhas noconfirmation_tokenargument, so the model cannot approve anything, and the token is removed from what the model reads. - The run state is an
AsyncLayrcakeSessionthat travels as LangGraph runtime context (context_schema=AsyncLayrcakeSession), and each tool reads it throughToolRuntime. The model never sees it. - Every paid call gets
budget_creditsset to what is left ofBUDGET.--dry-runaddsdry_run: trueto every call.create_campaignrefuses any address that did not passverify_emailin this run. Once the approval link appears, every paid tool refuses. - Paid calls take a lock, so the running total stays exact even when the model calls tools in parallel. Each call carries an idempotency key, so a repeated call returns the first result instead of charging again.
launch_campaignis areturn_directtool, so the graph ends as soon as it returns the approval link.- A refused call comes back to the model as the tool result ("Refused: ..."), so it can fix the call or stop.
The hosted MCP server at https://mcp.layrcake.dev/mcp also works with LangGraph through langchain-mcp-adapters. Plain tools keep the schemas small and the guardrails in your code.
- Python 3.10 or later and uv.
- A Layrcake API key. Create one at layrcake.dev/connect. New accounts start with 300 free credits.
- An Anthropic API key from platform.claude.com, or another model provider (see
MODELbelow). - Sending mailboxes in your Layrcake workspace, for the launch preview. Without them,
launch_campaignreturns an error that says what is missing, and the run reports it.
uv sync
cp .env.example .env # then add LAYRCAKE_API_KEY and ANTHROPIC_API_KEY
uv run --env-file .env smoke.py # free check of your Layrcake key, no model callsmoke.py runs the agent's own tools in dry-run mode against the live API, the same way the graph's tool node calls them. It charges nothing and calls no model. It prints something like this:
Key works for workspace "My workspace".
find_leads: would cost up to 3 credits
enrich: would cost up to 5 credits
verify_email: would cost up to 1.25 credits
create_campaign: would cost up to 0 credits
Charged: 0 credits. Your key and the Layrcake API work.
If create_campaign says it would trip: sending_capacity, connect mailboxes in the Layrcake console before a live run.
Set SENDER_NAME in .env to the name your emails are signed with. Without it, every draft is signed [Your name] and the report reminds you to fill it in before you approve.
Start with a dry run. Every Layrcake call returns a plan with its cost instead of data, so it is free. It still uses your model key.
uv run --env-file .env agent.py --dry-runThen run it for real with your own brief:
uv run --env-file .env agent.py "Find 10 heads of sales at software companies in London with 20 to 200 staff and draft a short campaign about cutting time spent on lead research."With no brief, it uses the one above.
Each tool call prints as it runs. The run ends with a short report from the tools themselves:
Live run. Budget: 25 credits.
Brief: Find 3 heads of sales at software companies in London with 20 to 200 staff, verify their work emails, and draft a short campaign about cutting time spent on lead research.
-> find_leads
-> enrich
-> enrich
-> enrich
-> verify_email
-> verify_email
-> verify_email
-> create_campaign
-> launch_campaign
Found 3 people. Kept 3 verified emails (1 catch-all).
Layrcake credits spent: 21.75 of 25.
Nothing has been sent. A person approves or declines here: <approval link>
This is our test run on 20 October 2026, with BUDGET=25, the three-person brief above and openrouter:anthropic/claude-sonnet-5.5 through OpenRouter. It took 31 seconds. Your run will differ. A dry run ends with the model's cost estimate instead of a link.
launch_campaign never sends on its own. Its first answer is a preview, a confirmation_token and an approval_url. The tool returns the link and the graph ends.
A signed-in person in your workspace opens the link, reads the preview and approves or declines. Layrcake can also email an approver in your workspace. After approval, Layrcake starts the campaign itself when the approval says execution: server. Otherwise you repeat the call with the token. This agent never does either: its launch_campaign tool has no token argument.
A run of the default brief usually costs 45 to 55 Layrcake credits. A credit is $0.01. Finding people costs 0.25 credits each, an email costs 5 credits when found, a verification costs 1.25, and lookups that find nothing are free. Drafting the campaign is free. See pricing.
BUDGET in .env is the ceiling for the whole run (default 100). Model usage is billed separately by your model provider.
MODEL takes a provider:model string for LangChain's init_chat_model. The default is anthropic:claude-sonnet-5-5, which reads ANTHROPIC_API_KEY. For OpenAI, run uv add langchain-openai, then set MODEL=openai:<model> and OPENAI_API_KEY.
The kit runs through OpenRouter with langchain-openrouter, which is already a dependency. Put these in .env instead of a direct model key:
OPENROUTER_API_KEY=<your OpenRouter key>
MODEL=openrouter:anthropic/claude-sonnet-5.5
agent.py the agent: model, graph, stop rule, report
layrcake_tools.py the five Layrcake tools, from layrcake.agent_tools
instructions.py the system prompt
smoke.py free setup check, no model call
tests/test_tools.py tool tests with a mocked Layrcake API
tests/test_agent.py the full graph with a scripted chat model
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytestThe tests give the layrcake client an httpx.MockTransport, and drive the graph with a scripted chat model. They need no keys and make no network calls. The run rules themselves are tested in the SDK.
- Layrcake docs: docs.layrcake.dev
- Rules for agents: layrcake.dev/agents.md
- Python SDK: github.com/Layrcake-dev/layrcake-python
- MCP server:
https://mcp.layrcake.dev/mcp - LangGraph: langchain-ai.github.io/langgraph
MIT. See LICENSE.