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=true2. 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 automatically4. Verify
agentrust status
agentrust audit tailExamples
Docker entrypoint:
ENV AGENTRUST_AUTOLOAD_EMBED=true
ENV AGENTRUST_AUTOLOAD_AGENT_ID=container-agent
ENV PYTHONSTARTUP=/app/autoload.pyCI 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
@harnessorauto_instrument()in new code - Set
AGENTRUST_AUTOLOAD_AGENT_IDto a meaningful production agent name - Disable with
AGENTRUST_ENABLED=falsefor instant rollback
Common Mistakes
- Autoload without
[embedded]extra whenAGENTRUST_AUTOLOAD_EMBED=true - Conflicting with application's own
PYTHONSTARTUP(merge scripts) - Using autoload in production without monitoring embedded SQLite growth
Troubleshooting
| Issue | Fix |
|---|---|
| No instrumentation | Verify AGENTRUST_AUTO_INSTRUMENT=true |
| Gateway not started | Check AGENTRUST_AUTOLOAD_EMBED=true and [embedded] |
| Import order issues | Ensure PYTHONSTARTUP runs before app imports |