StateGraph — which means the Idun Engine treats it exactly like any other LangGraph agent. No adapter, no glue code: point Idun at the module, get a streaming API, a chat UI, observability, and MCP tools for free.
This guide takes the official text-to-SQL Deep Agent example, drops it behind Idun, and walks all the way to a Gemini-powered agent that queries SQLite, traces every step in the built-in dashboard and Langfuse, and emails its results via a Google Workspace MCP server.
What you will build
Discover the agent
idun init, point the wizard at agent.py.Chat with it
Persist conversations
See what's happening
Plug in a Google Workspace MCP
Prerequisites
- Python 3.12+
- A Gemini API key — get one
- (Step 7) A free Langfuse Cloud account
- (Step 8) A Google Cloud project with a Desktop OAuth client and Gmail API enabled
Clone the Deep Agents example
text-to-sql-agent example. It ships with the Chinook SQLite database and a few skills (query-writing, schema-exploration):agent.py is the very last line:create_deep_agent(...) returns a compiled CompiledStateGraph. Idun’s LangGraph adapter accepts both compiled graphs and raw StateGraph builders, so this Just Works — no rewrite needed.Set up Idun
.env from the template the repo ships:IDUN_ALLOW_OPEN_ADMIN=1 lets you reach /admin/* without an auth gate while you explore locally. Turn it off (or remove it) before exposing the service.`idun init` — the discover flow
config.yaml yourself. idun init boots the standalone server, opens your browser, and — since no agent is configured yet — routes you to the onboarding wizard.- Alembic migrations create the standalone DB.
- The server starts on
http://localhost:8000. - Your browser opens the discover wizard.
- Framework — pick
LangGraph. Deep Agents compile to aStateGraph, so the LangGraph adapter handles them. - Graph definition — point Idun at the compiled graph:
agent.py:agent. Format ispath/to/file.py:variable.
Verify the wired-up agent
text2sql_deepagent; the configuration card shows the framework (LangGraph), the agent name, and the agent.py:agent graph reference.
MemoryMiddleware, SkillsMiddleware, and PatchToolCallsMiddleware before_agent hooks, the model node, the TodoListMiddleware.after_model post-hook, and the tools node. This is the Deep Agents runtime, made visible.
Chat with the Deep Agent
http://localhost:8000/ and ask something the agent has to plan for:Hello, show me the schema for our users and transactions tables and find any customers who haven’t made a purchase in 6 months.The chat collapses the agent’s planning into a Reasoning card. Expand it and you see exactly what the Deep Agent did: it loaded its skills via
read_file, listed the SQL tables, fetched the Customer and Invoice schemas, sanity-checked the date, ran the query through sql_db_query_checker, and finally executed the result.

- “Top 5 best-selling artists?”
- “Which employee generated the most revenue, broken down by country?”
- “Plot revenue by genre and write a one-paragraph summary.”
POST /agent/run endpoint is exposed at the API level — point CopilotKit, Vercel AI SDK, or any AG-UI client at it.Persist conversations with SQLite
sqlite:///deep.db), Save. Idun reloads the checkpointer in place.

Built-in observability


ChatGoogleGenerativeAI calls with their token counts, and the sql_db_query tool span.

Add Langfuse on top
- Sign up for Langfuse Cloud (free) and create a project. Copy the public + secret keys.
- In the Idun admin, open Observability → pick Langfuse, fill in host, public key, secret key, and a run name. Toggle Enabled and Save.

- Ask the agent another question. Refresh the Langfuse dashboard.
ChatGoogleGenerativeAI call with tokens and cost, the tool spans, the full prompt/completion pair. Langfuse also renders the graph topology — same nodes you saw inside Idun, now persisted for evaluation runs and team review.
Plug in the Google Workspace MCP
9a. Get a Desktop OAuth client
In Google Cloud Console:- Create or pick a project, enable the Gmail API and Google Docs API (and any other Workspace APIs you want).
- APIs & Services → Credentials → Create credentials → OAuth client ID → Desktop app.
- Copy the client ID and secret into
.env:
9b. Start the MCP server
Run the Google Workspace MCP locally over streamable HTTP:9c. Register the server in Idun
In the admin: MCP → pick Streamable HTTP → fill in the endpoint (http://127.0.0.1:8000/mcp), name it google-workspace, save.
send_gmail_message, create_doc, create_calendar, append_table_rows, and 116 others.
9d. Wire the tools into the Deep Agent
Deep Agents bind tools at construction time, so we expose Idun’s configured MCP tools tocreate_deep_agent. The engine ships an async helper for this — idun_agent_engine.mcp.get_langchain_tools — that reads the MCP servers from your Idun config and returns ready-to-use LangChain tools.Because agent.py is imported at module load (inside the engine’s lifespan, where an event loop is already running), we wrap the async helper in a one-shot thread so it can be called synchronously:9e. Ask the agent to ship the report
Back in chat:
Find the 10 customers who haven’t bought anything in 6 months. Write up a detailed report as a Google Doc and email it to me at you@example.com.
The Deep Agent plans, runs the SQL, edits its working file with the report content, saves your address to memory via write_todos, then calls the MCP tools to create a Google Doc and send the email with the doc linked.

create_doc and send_gmail_message calls show up in the trace alongside the SQL steps — full causal chain in one place.What this gave you
Starting from anagent.py you didn’t touch, you got:
Next steps
Lock down access
IDUN_ALLOW_OPEN_ADMIN, add SSO/OIDC, generate API keys for /agent/run.