LangChain agents take a tools=[] list. myagentinbox exposes a tiny REST API, so the integration is three @tool decorators — one each for creating an inbox, listing messages, and reading a message.
pip install langchain langchain-openai langgraph httpx
import httpx
from langchain_core.tools import tool
BASE = "https://myagentinbox.com"
@tool
def create_inbox() -> dict:
"""Create a disposable email inbox that expires in 24 hours.
Returns dict with 'address' and 'expires_in'."""
r = httpx.post(f"{BASE}/api/inboxes", timeout=10)
r.raise_for_status()
return r.json()["data"]
@tool
def check_inbox(address: str) -> list:
"""List messages in a disposable inbox.
Args: address - the @myagentinbox.com email address."""
r = httpx.get(f"{BASE}/api/inboxes/{address}/messages", timeout=10)
r.raise_for_status()
return r.json()["data"]
@tool
def read_message(address: str, message_id: str) -> dict:
"""Read the full body of a message.
Args: address - inbox address. message_id - the message ID from check_inbox."""
r = httpx.get(f"{BASE}/api/inboxes/{address}/messages/{message_id}", timeout=10)
r.raise_for_status()
return r.json()["data"]
email_tools = [create_inbox, check_inbox, read_message]
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(
llm,
tools=email_tools,
prompt=(
"You can use disposable email. When you need an address, call create_inbox. "
"Wait 5-10 seconds between check_inbox calls. Give up after 2 minutes."
),
)
result = agent.invoke({
"messages": [{
"role": "user",
"content": "Sign up for example.com and read the verification email.",
}],
})
print(result["messages"][-1].content)
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You can read email via the provided tools."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, email_tools, prompt)
executor = AgentExecutor(agent=agent, tools=email_tools)
executor.invoke({"input": "Create an inbox and tell me the address."})
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const BASE = "https://myagentinbox.com";
export const createInbox = tool(
async () => {
const r = await fetch(`${BASE}/api/inboxes`, { method: "POST" });
return JSON.stringify((await r.json()).data);
},
{
name: "create_inbox",
description: "Create a disposable email inbox (24h TTL).",
schema: z.object({}),
}
);
export const checkInbox = tool(
async ({ address }) => {
const r = await fetch(`${BASE}/api/inboxes/${address}/messages`);
return JSON.stringify((await r.json()).data);
},
{
name: "check_inbox",
description: "List messages in a disposable inbox.",
schema: z.object({ address: z.string() }),
}
);