Embedded Gateway

Autoload

Automatic embedded gateway startup and framework patching.

Autoload

Overview

Autoload enables zero-code AgentTrust bootstrap by starting the embedded gateway and applying auto-instrumentation via environment variables and PYTHONSTARTUP — no changes to your application source code.

Why It Matters

Legacy codebases and third-party tools where you cannot modify imports benefit from governance injection at process startup.

Prerequisites

pip install "agentrust-sdk[embedded,autoload]"

Step-by-Step Guide

1. Set environment variables

export AGENTRUST_AUTOLOAD_EMBED=true
export AGENTRUST_AUTOLOAD_AGENT_ID=my-agent
export AGENTRUST_AUTO_INSTRUMENT=true

2. Configure PYTHONSTARTUP

export PYTHONSTARTUP=$(python -c "import agentrust_sdk; import os; print(os.path.dirname(agentrust_sdk.__file__) + '/autoload.py')")

Or use sitecustomize pattern for site-wide activation.

3. Run your application normally

python your_existing_app.py
# Embedded gateway starts; OpenAI/LangChain/LangGraph patched automatically

4. Verify

agentrust status
agentrust audit tail

Examples

Docker entrypoint:

ENV AGENTRUST_AUTOLOAD_EMBED=true
ENV AGENTRUST_AUTOLOAD_AGENT_ID=container-agent
ENV PYTHONSTARTUP=/app/autoload.py

CI test job:

env:
  AGENTRUST_AUTOLOAD_EMBED: "true"
  AGENTRUST_AUTOLOAD_AGENT_ID: "ci-agent"
  AGENTRUST_ENABLED: "true"

Best Practices

  • Use autoload for brownfield integrations only
  • Prefer explicit @harness or auto_instrument() in new code
  • Set AGENTRUST_AUTOLOAD_AGENT_ID to a meaningful production agent name
  • Disable with AGENTRUST_ENABLED=false for instant rollback

Common Mistakes

  • Autoload without [embedded] extra when AGENTRUST_AUTOLOAD_EMBED=true
  • Conflicting with application's own PYTHONSTARTUP (merge scripts)
  • Using autoload in production without monitoring embedded SQLite growth

Troubleshooting

IssueFix
No instrumentationVerify AGENTRUST_AUTO_INSTRUMENT=true
Gateway not startedCheck AGENTRUST_AUTOLOAD_EMBED=true and [embedded]
Import order issuesEnsure PYTHONSTARTUP runs before app imports