Skip to content
Nov 3, 2026 - Version 2026.10 has been released
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build a Python agent with deepagents

Use the Datasentinel MCP server and Skill from a Python script with LangChain deepagents, and run it against your platform.

This developer guide shows how to use the Datasentinel MCP server and Skill from a Python script, using LangChain's deepagents library.

The script on this page is an example of how to use Datasentinel AI Connector from your own code. Use it as a starting point. Review it and adapt it to your environment before you run it in production.

Use this when you want to embed Datasentinel in your own code rather than a turnkey assistant. For the no-code path, see the Deep Agents Code example.

Prerequisites

Set up the project

Install deepagents, the MCP adapter that turns MCP tools into agent tools, and your model provider's package:

pip install deepagents langchain-mcp-adapters langchain-anthropic

Export your model provider's API key:

export ANTHROPIC_API_KEY=<your-key>

Extract the Skill next to your script so the agent can load it. This produces a datasentinel/ folder containing SKILL.md:

mkdir -p skills
unzip datasentinel-skill.zip -d skills/

Write the agent

The script answers one question from the command line and exits. It connects to the Datasentinel MCP server over HTTPS, loads its tools, builds a deep agent (Opus 5) around those tools plus the Datasentinel Skill, and prints the agent's reply. Along the way it runs non-interactively (never asking the user anything) and handles authentication automatically: it sends the platform's 24-hour user token as the Authorization: Bearer header of the MCP connection, reusing a cached token or minting a fresh one when it's missing or expired.

Save this as datasentinel_agent.py:

Notes:

  • The MCP server is protected by OAuth 2.1, and a script has nobody to sign in. So the agent sends the platform's 24-hour user token as the Authorization: Bearer header of the MCP connection (the headers key), which the server accepts like an OAuth session. The script reuses the token from a cache or mints a fresh one when it is missing or expired; the token never appears in the conversation, so the model never sees it. See How authentication works.

  • For an agent that a person starts, the OAuth sign-in is the alternative: pass an OAuthClientProvider from the MCP Python SDK (mcp.client.auth) as the connection's auth key, with a token storage of your own and a handler that prints the authorization link. The person signs in once in the browser, and the provider renews the session by itself. That path needs a certificate the SDK's HTTP client trusts, so the verify=False helper above does not apply to it.

  • get_tools() is asynchronous, which is why the work runs inside async def main.

  • skills=["./skills/"] points at a parent directory: the agent scans its subdirectories for Skill folders (each holding a SKILL.md) and applies a Skill when the request matches its description.

  • The Skill therefore loads on demand: deepagents reads only the frontmatter up front and pulls in the full instructions when the question relates to Datasentinel. If a question is answered generically without the Skill, force it by naming it in the question, for example python datasentinel_agent.py "Use the datasentinel skill: check the platform status".

  • model accepts any model LangChain supports; swap "anthropic:claude-opus-5" for another provider's identifier if you prefer.

  • The system prompt cancels the Skill's closing menu explicitly. The Datasentinel Skill normally ends every result with a numbered "What would you like to do next?" menu, and it treats that block as send-blocking, so a general instruction not to ask questions is not enough to suppress it. The Skill exempts a non-interactive run that the host declares, and the paragraph in SYSTEM_PROMPT is that declaration. Keep it if you adapt this script; drop it only if you want the menu back.

  • The final message is passed through reply_text() rather than printed directly. A reasoning model returns its content as a list of blocks (a thinking block, then the answer), so print(message.content) would dump the raw list, including the thinking block and its base64 signature, instead of the reply. reply_text() keeps only the text blocks and still handles the plain-string case from models that do not think.

Run the script

Call the script with your question as the argument. With no argument it runs the Skill's datasentinel status check:

From here you can ask anything the Skill and the MCP tools support, for example:

Run a fully local agent with Gemma 4

The example above calls a hosted model. To keep the reasoning on your own hardware too, swap it for Google's open-source Gemma 4, run locally with Ollama. Combined with a self-hosted Datasentinel platform, the agent then sends nothing to an external AI provider: the model runs on your machine and the tools are your own MCP server.

Install Ollama, then pull a Gemma 4 model. The small E4B variant is a good starting point:

Install the LangChain Ollama integration:

Then build the agent with the local model instead of a hosted one. Only the import and the model argument change; the rest of the script is identical:

Run it the same way:

A local agent needs a model and runtime that support tool calling. Gemma 4 supports function calling natively, but use a recent Ollama release.

Last updated