Skip to main content

tame-ai-sdk

Python SDK for protecting AI agent tool calls with TAME runtime policies.

Install

pip install tame-ai-sdk

For local development in this repo:

cd packages/sdk-python
python -m pip install -e .

Configure

TAME_BASE_URL=https://tame.sh
TAME_API_KEY=tame_sk_replace_me
TAME_ENVIRONMENT=production

Use a runtime API key in agent hosts. Use a control API key only for dashboards, policy management, and administrative reads.

Usage

import os
from tame_ai import TameClient, TameToolError

tame = TameClient(
    base_url=os.environ["TAME_BASE_URL"],
    api_key=os.environ["TAME_API_KEY"],
    agent_id="code-pipeline-agent",
    context={"environment": os.getenv("TAME_ENVIRONMENT", "production")},
    failure_mode="fail_closed",
)

def real_apply_patch(args):
    return {"applied": True}

apply_patch = tame.protect_tool(
    name="apply_patch",
    execute=real_apply_patch,
)

try:
    result = apply_patch({
        "repository": "checkout-service",
        "file_path": "src/auth/session.py",
        "risk_score": 95,
    })
except TameToolError as error:
    print(error.decision["reason"])

TAME checks the tool call before execution. If a policy blocks the call or requires approval, the SDK raises TameToolError and the protected tool is not executed.

Decision Metadata

Decision responses include protection-signal fields:

decision = tame.check_tool_call(
    tool={"name": "send_http_request", "arguments": {"url": "https://example.com/path"}},
)

print(decision["policies_evaluated"])
print(decision["applicable_policies"])
print(decision.get("policy_warning"))

If applicable_policies is 0, the runtime allowed by default because no enabled policy matched the agent/tool/conditions. Treat policy_warning as an integration warning, not as a block.

Failure Modes

failure_mode="fail_closed" is the default. If TAME is unavailable, tool execution fails before the real function runs.

failure_mode="fail_open" returns an allow decision when TAME is unavailable:

tame = TameClient(
    base_url=os.environ["TAME_BASE_URL"],
    api_key=os.environ["TAME_API_KEY"],
    agent_id="support-agent",
    failure_mode="fail_open",
    timeout_ms=1000,
)

Use fail-open only for low-risk workflows.

Approval Flow

decision = tame.check_tool_call(
    tool={"name": "issue_refund", "arguments": {"amount": 250}},
)

if decision["result"] == "require_approval":
    approval = tame.wait_for_approval(decision["approval_id"])
    if approval["status"] == "approved":
        resumed = tame.check_approved_tool_call(
            decision["approval_id"],
            tool={"name": "issue_refund", "arguments": {"amount": 250}},
        )

Memory Writes

write_memory = tame.protect_memory_write(
    source="customer-support-agent",
    content=lambda item: item["memory"],
    write=lambda item: vector_store.add_texts([item["memory"]]),
)

write_memory({"memory": "Customer prefers email follow-up."})

If TAME quarantines the write, TameMemoryWriteError is raised and your store is not updated.

Lifecycle and Model Telemetry

tame.record_agent_event(
    event_type="model.completed",
    trace_id="trace_123",
    payload={
        "provider": "your-provider",
        "model": "your-model-name",
        "outcome": "success",
    },
)

Send metadata only: never prompts, completions, credentials, or raw customer data.

OpenAI Function Calls

from tame_ai import protect_openai_tool

handler = protect_openai_tool(
    tame,
    name="get_customer",
    execute=lambda args: crm.get_customer(args["customer_id"]),
)

result = handler(openai_tool_call)

LangGraph, AutoGen, and CrewAI

The SDK intentionally keeps framework adapters thin. Wrap the underlying callable before registering it with the framework:

from tame_ai.integrations import protect_langgraph_tool, protect_autogen_tool, protect_crewai_tool

safe_lookup = protect_langgraph_tool(tame, name="get_customer", execute=get_customer)
safe_refund = protect_autogen_tool(tame, name="issue_refund", execute=issue_refund)
safe_export = protect_crewai_tool(tame, name="export_customers", execute=export_customers)

The protected callable has the same behavior as tame.protect_tool(...): decision first, execution only on allow, completion telemetry best-effort after success.

Policy Field Notes

Agent IDs are validated server-side. Use stable IDs with letters, numbers, dots, underscores, colons, or hyphens. Avoid spaces and slashes.

For URL policies, prefer server-side host operators:

  • host_in
  • host_not_in
  • starts_with
  • contains
  • matches

This avoids every Python integrator having to derive a URL host field manually.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tame_ai_sdk-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tame_ai_sdk-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file tame_ai_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: tame_ai_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tame_ai_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a36cb2e48204e97094aade447ad54aa4f19541652a8d08f26acee2c2bf4432a0
MD5 7ebb10a6967033012bb0b588e14a10bf
BLAKE2b-256 a2e7f306c8b69b39160b9e849e63df75696f713c24ab02e2a4f2a31526cb335f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tame_ai_sdk-0.1.1.tar.gz:

Publisher: publish-python-sdk.yml on franpfeiffer/tame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tame_ai_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tame_ai_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tame_ai_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04e791906ef334335e439fe733257876f46ba550a7ab067bf72de12e2145ff40
MD5 0887bc656d8657318150fe61e4196f9d
BLAKE2b-256 f51a854d56e8105fa774591c6c25035d71145c9bfb72d21c94c8c5d49272c8e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tame_ai_sdk-0.1.1-py3-none-any.whl:

Publisher: publish-python-sdk.yml on franpfeiffer/tame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page