Add Execution Tracking to Your Agent (Python SDK)

The Kynver Python SDK lets you add execution tracking to agents built with LangChain, CrewAI, or plain Python. Once set up, every interaction your agent handles is recorded as a receipt on Kynver.

The SDK must only run on the server. Never expose your API key in browser code or commit it to source control. Use a .env file or environment variable.

Installation

pip install kynver-sdk

Environment Variables

Add these to your .env file and load them with python-dotenv or your preferred method:

# Required — find this in Dashboard → your agent → Profile
KYNVER_AGENT_DID=did:kynver:...

# Required — find this in Dashboard → your agent → Settings → API Keys
KYNVER_API_KEY=kyn_...

# Optional — only needed for Tier 2 self-sovereign signing
# after completing the ownership challenge
KYNVER_SIGNING_KEY=your_hex_key_here

Creating a Tracker

import os
from kynver import KynverTracker

tracker = KynverTracker(
    agent_did=os.environ.get('KYNVER_AGENT_DID'),
    api_key=os.environ.get('KYNVER_API_KEY'),
    # signing_key=os.environ.get('KYNVER_SIGNING_KEY')  # optional, Tier 2
)

You can also use the tracker as a context manager, which handles cleanup automatically:

with KynverTracker(agent_did=..., api_key=...) as tracker:
    result = tracker.report_execution(...)

Reporting Executions

After each agent run, call report_execution():

result = tracker.report_execution(
    instruction='Summarize this document',   # what the user asked
    output='The document says...',           # what the agent replied
    task_category='summarization',           # describe the type of task
    status='success',                        # 'success', 'failure', or 'partial'
)

# result.queued is True as a fallback stub until the receipt endpoint is live

Tracking High-Stakes Actions

For actions with real-world impact — payments, emails, data deletions — capture authorization before the action:

from kynver import KynverAPIError

try:
    token = tracker.capture_authorization(
        action_type='send_email',
        scope='user:123',
        consent_method='in_app',
    )
    do_high_stakes_action()
    tracker.report_execution(
        instruction=...,
        output=...,
        authorization_token_ids=[token.id]
    )
except KynverAPIError as e:
    if e.status_code in (404, 501):
        pass  # block the action if audit endpoint unavailable
    raise

Using the REST Client

The REST client lets you look up agents and reputation data from the Kynver platform:

from kynver import KynverClient, KynverAPIError

with KynverClient(api_key=os.environ.get('KYNVER_API_KEY')) as client:
    agent = client.get_agent('my-agent-slug')
    reputation = client.get_reputation('my-agent-slug')
    print(agent.name, reputation.score)

User Connect

Let users link their Kynver identity to your app:

result = tracker.get_user_connect_info(
    return_url='https://yourapp.com/after-connect'
)
# result.connect_url — pass this to your UI as a link
# result.end_user_token — the user's token for your app
Python auto-instrumentation (equivalent to importing kynver.auto) is coming in a future release. Until it ships, use the manual KynverTracker approach shown above.