Skip to main content

A secure SDK for building custom user agents (workers) that run in your environment and connect safely with the akaBot 2.0 platform.

Project description

User Agent SDK

A secure SDK for building custom user agents (workers) that run in your environment and connect safely with the akaBot 2.0 platform.

Overview

The User Agent SDK empowers developers to build secure, customizable worker agents that operate within their own environment while integrating seamlessly with the akaBot 2.0 platform. Each user agent extends workflow capabilities by executing custom node logic locally, ensuring sensitive operations and data remain under the user’s control while maintaining trusted communication and coordination with the central platform.

Prerequisites

  • Python 3.12 or higher
  • uv package manager installed
  • An akaBot 2.0 account with access to the Workflow Builder

Installation

uv add user-agent-sdk

Quick Start

1. Create a credentials.json file

This file contains the authentication details for your user agent. You can download this file from the akaBot 2.0 Workflow Builder when creating a new user agent.

Place this file in the same directory as your user agent code.

{
  "clientId": "your-client-id",
  "clientSecret": "your-client-secret",
  "agentId": "00000000-0000-0000-0000-000000000000#user-agent"
}

2. Create your user agent

The user agent code defines the logic that will be executed when the agent receives a task such as processing data or performing actions.

from logging import Logger
from user_agent_sdk import user_agent


@user_agent()
def sum_agent(input_data: dict, logger: Logger):
    # These logs will be visible in the akaBot 2.0 platform for monitoring
    logger.info("Processing task input")

    # Do some work with the input data
    num1 = input_data.get("num1", 0)
    num2 = input_data.get("num2", 0)
    total = num1 + num2

    return total

3. Run your user agent

Use built-in CLI to run your user agent locally:

useragent run your_agent.py

Alternatively, you can run it without installing the package using uvx:

uvx --from user-agent-sdk useragent run your_agent.py

Folder structure:

your_project/
├── .venv/
├── credentials.json
├── pyproject.toml
└── your_agent.py

Advanced Usage

Custom Error Handling

The SDK automatically handles exceptions during task execution:

  • Agent can be retried (max attempts are 3) on failure by regular exceptions
  • NonRetryableException indicates that the task should not be retried
from user_agent_sdk import user_agent
from user_agent_sdk.utils.exception import NonRetryableException


@user_agent()
def my_agent(input_data):
    user_name = input_data.get("user_name")
    if not user_name:
        raise NonRetryableException("'user_name' is required")

    # Regular processing...

Async Support

The SDK supports asynchronous user agents using async functions.

from user_agent_sdk import user_agent


@user_agent()
async def sum_agent():
    # async processing logic here
    pass

High workload Handling

The SDK can handle high workloads by processing multiple tasks concurrently (vertical scaling), or by running multiple instances of the user agent (horizontal scaling) in different machines.

To increase concurrency workers, use the --workers or -w flag when running the user agent:

# Spawn 4 concurrent workers for handling tasks for a single user agent
useragent run your_agent.py --workers 4

Alternatively, set the workers parameter in the user_agent decorator:

from user_agent_sdk import user_agent


@user_agent(workers=4)
def sum_agent():
    # processing logic here
    pass

If both workers flag and parameter are set, the flag takes precedence.

Multiple User Agents

You can define multiple user agents in a single script by using the user_agent decorator multiple times with different agent_ids.

from user_agent_sdk import user_agent


@user_agent(agent_id="sum agent id")
def sum_agent():
    # processing logic here
    pass


@user_agent(agent_id="minus agent id")
def minus_agent():
    # processing logic here
    pass

Run multiple user agents in one script/project is possible but not recommended. You should keep one user agent per script/project for better maintainability.

Execution History

The SDK automatically records execution history for each task when enabled, allowing you to monitor and debug agent executions.

Enable Execution History Recording

Use the --record-execution-logs or -r flag when running your agent:

useragent run your_agent.py -r

This will create a local SQLite database (execution_history.db) that stores:

  • Task ID
  • Agent ID and User Agent ID
  • Start and end timestamps
  • Execution status (success/error)
  • Input and output data
  • Error messages (if any)

View Execution History

Display a summary of recent executions:

# Show last 50 executions
useragent history

# Filter by agent ID
useragent history --agent-id "your-agent-id"

# Filter by user agent ID
useragent history --user-agent-id "user123"

# Limit number of records
useragent history --limit 100

# Use custom database path
useragent history --db-path /path/to/custom.db

View Detailed Execution Information

To see detailed information about a specific execution, including formatted input/output JSON:

# Show details for execution ID 1
useragent history-detail 1

# Or use the short alias
useragent hd 1

# With custom database path
useragent hd 5 --db-path /path/to/custom.db

The detail view displays:

  • Complete execution metadata (Task ID, Agent ID, timestamps, status)
  • Error messages (if any)
  • Input data - Pretty-printed JSON with syntax highlighting
  • Output data - Pretty-printed JSON with syntax highlighting

This is particularly useful for:

  • Debugging failed executions
  • Analyzing task inputs and outputs
  • Monitoring agent performance
  • Auditing agent activities

License

Apache License 2.0

Project details


Download files

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

Source Distribution

user_agent_sdk-0.2.1.tar.gz (102.3 kB view details)

Uploaded Source

Built Distribution

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

user_agent_sdk-0.2.1-py3-none-any.whl (182.7 kB view details)

Uploaded Python 3

File details

Details for the file user_agent_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: user_agent_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 102.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for user_agent_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c022bf5bc6f9cb3b522b762176cdede880162de270b0902c9171611200ae4aaa
MD5 d5b190f78f6e2d9f8c06303461ffe0cf
BLAKE2b-256 a6c4aca3243908c9cfbaca27c240b13430684072c55a4389c38e1043354c07c8

See more details on using hashes here.

File details

Details for the file user_agent_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for user_agent_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9b3ced0fb8503625d5cf2d3cee387b8d3dcd2096b57e81b87669b8017a421ce
MD5 6463405b3b09041f7a4ca676420fa812
BLAKE2b-256 473ac3d356f20a9e9c82fe9cb25428e7f7e639050a4b9d5927964a4a1a92a212

See more details on using hashes here.

Supported by

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