Skip to content

About

OpenAI Agents SDK starter: find people, verify work emails, draft a campaign that waits for approval. Runs on Layrcake.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Layrcake starter for the OpenAI Agents SDK

An OpenAI 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 the OpenAI Agents SDK for Python and the official layrcake Python SDK. Nothing is sent. A person approves the campaign in the Layrcake console before any email goes out.

What it does

  1. find_leads finds people who match your brief.
  2. enrich gets each person's work email.
  3. verify_email checks every address. Only valid and catch_all_valid addresses are kept.
  4. create_campaign saves a short draft sequence for the kept people. Drafts never send.
  5. launch_campaign returns a preview and an approval link. The agent stops there.

Why the SDK for this kit

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 the Agents SDK as FunctionTools:

  • Each tool's name, description with its price, and strict JSON schema come from the SDK. launch_campaign has no confirmation_token argument, so the model cannot approve anything, and the token is removed from what the model reads.
  • The run state travels in the run context (RunContextWrapper[AsyncLayrcakeSession]): the Layrcake client, the budget, what was spent, and which emails passed verification. Every paid call gets budget_credits set to what is left of BUDGET. --dry-run adds dry_run: true to every call. create_campaign refuses any address that did not pass verify_email in this run.
  • StopAtTools(stop_at_tool_names=["launch_campaign"]) ends the run at the approval link. parallel_tool_calls=False and the session's lock run one Layrcake call at a time, so the running total is exact.
  • A refused call, such as one past the budget, comes back to the model as text that starts with Refused: and says why, so it can fix the call or stop.
  • The SDK handles retries, typed errors and idempotency keys. The session passes a key derived from the call, so a repeated call returns the first result instead of charging again. Credits are Decimal, never floats.

The hosted MCP server at https://mcp.layrcake.dev/mcp also works with the Agents SDK through MCPServerStreamableHttp. Function tools keep the schemas small and the guardrails in your code.

Layrcake's approval happens in the Layrcake console and is enforced by the API. The Agents SDK's own needs_approval option is not needed for it.

Prerequisites

  • 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 OpenAI API key from platform.openai.com.
  • Sending mailboxes in your Layrcake workspace, for the launch preview. Without them, launch_campaign returns an error that says what is missing, and the run reports it.

Setup

uv sync
cp .env.example .env   # then add LAYRCAKE_API_KEY and OPENAI_API_KEY
uv run --env-file .env smoke.py   # free check of your Layrcake key, no model call

smoke.py runs the agent's own tools in dry-run mode against the live API, the same way the agent loop 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.

Run

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 OpenAI key.

uv run --env-file .env agent.py --dry-run

Then 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.

What you will see

Each tool call prints as it starts. The run ends with a short report from the run state:

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 10 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 openai/gpt-5.6-luna through OpenRouter. It took 40 seconds. The search returned 10 people and the agent enriched the 3 the brief asked for. Your run will differ. A dry run ends with the model's cost estimate instead of a link.

How approval works

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 run stops.

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.

Cost

Our test runs of the default brief cost 45.5 to 53 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 OpenAI. Set MODEL to change the model. Without it, the agent uses the Agents SDK default (gpt-5.6-luna in openai-agents 0.24).

The Agents SDK sends traces of each run to your OpenAI dashboard, including tool results such as names and emails. Set OPENAI_AGENTS_DISABLE_TRACING=1 to turn that off.

Using OpenRouter

The kit runs unchanged through OpenRouter. Put these in .env instead of a direct model key:

OPENAI_BASE_URL=https://openrouter.ai/api/v1
OPENAI_API_KEY=<your OpenRouter key>
OPENAI_AGENTS_DISABLE_TRACING=1
MODEL=openai/gpt-5.6-luna

We ran this kit this way on 20 October 2026.

Project layout

agent.py              the agent: model settings, 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 agent loop with a scripted model

Development

uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest

The tests give the layrcake client an httpx.MockTransport, and drive the agent with the Agents SDK's ScriptedModel. They need no keys and make no network calls. The run rules themselves are tested in the SDK.

Links

License

MIT. See LICENSE.

About

OpenAI Agents SDK starter: find people, verify work emails, draft a campaign that waits for approval. Runs on Layrcake.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages