Skip to main content

asgard-sdk-python

Python SDK for the Asgard Core API. Sync-first, with async extensibility in mind.

Installation

uv add asgard-sdk-python

Or for development:

uv sync --extra dev

Requirements

Python 3.11+

Quick Start

BotProviderClient

from asgard import BotProviderClient, GenericBotMessage

client = BotProviderClient(
    host="http://localhost:8080",
    namespace="my-ns",
    bot_provider_name="my-bot",
    api_key="secret",
)

# Send a message (REST)
message = GenericBotMessage(custom_channel_id="ch-1", custom_message_id="m-1", text="hello")
reply = client.send_message(message)
for m in reply.messages:
    print(m.text)

# Stream a message (SSE)
with client.stream(message) as stream:
    for event in stream:
        if event.event_type.value == "asgard.message.delta":
            print(event.fact.message_delta.text, end="", flush=True)

# Upload a blob
with open("image.png", "rb") as f:
    blobs = client.upload_blob(custom_channel_id="ch-1", file=f, filename="image.png", mime="image/png")

FunctionAgentClient

from asgard import FunctionAgentClient

client = FunctionAgentClient(
    host="http://localhost:8080",
    namespace="my-ns",
    bot_provider_name="my-agent",
    api_key="secret",
)

result = client.trigger_json({"key": "value"})

with open("data.csv", "rb") as f:
    result = client.trigger_form({"key": "value"}, file=f, filename="data.csv", mime="text/csv")

Environment Variables

Variable Description
EDGE_SERVER_HOST EdgeServer host URL
NAMESPACE Asgard namespace
BOT_PROVIDER_NAME Bot/agent name
BOT_PROVIDER_API_KEY API key

CLI

# Bot interactive REPL (SSE by default)
asgard-cli --host http://localhost:8080 --namespace default --bot my-bot --apikey secret

# Switch to REST transport
asgard-cli --host ... --namespace ... --bot ... --apikey ... --transport rest

# Using env vars
export EDGE_SERVER_HOST=http://localhost:8080
export NAMESPACE=default
export BOT_PROVIDER_NAME=my-bot
export BOT_PROVIDER_API_KEY=secret
asgard-cli

# Function agent — JSON trigger
asgard-cli --agent function --json-trigger \
  --trigger-payload '{"key": "value"}' \
  --host ... --namespace ... --bot ... --apikey ...

# Function agent — Form trigger
asgard-cli --agent function --form-trigger \
  --trigger-payload '{"key": "value"}' \
  --form-file ./data.csv --form-mime text/csv \
  --host ... --namespace ... --bot ... --apikey ...

Bot REPL commands

Command Description
/help Show help
/exit / /quit Exit
/transport sse|rest Switch transport
/debug on|off Toggle debug mode
/blob <path> [mime] Upload and attach a blob
/blobs Show attached blob IDs
/clear-blobs Clear attached blobs
/channel [id] Show or switch channel
/reset [text] Send RESET_CHANNEL action

Error Handling

from asgard import AsgardError, AsgardStreamError

try:
    reply = client.send_message(message)
except AsgardError as e:
    print(e.detail.message)  # human-readable error
    print(e.detail.code)     # error code

try:
    with client.stream(message) as stream:
        for event in stream:
            ...
except AsgardStreamError as e:
    print(e.detail.message)

Tool Call Consent

from asgard import GenericBotMessage, ToolCallConsentResponseItem, ToolCallConsentResult, PostBackAction

# After receiving a tool_call.consent event:
consent_items = [
    ToolCallConsentResponseItem(
        tool_call_id="tc-1",
        result=ToolCallConsentResult.ALLOW_ONCE,
    )
]

response = GenericBotMessage(
    custom_channel_id="ch-1",
    custom_message_id="m-2",
    action=PostBackAction.RESPONSE_TOOL_CALL_CONSENT,
    tool_call_consents=consent_items,
)
reply = client.send_message(response)

Download files

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

Source Distribution

asgard_sdk-0.1.0.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

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

asgard_sdk-0.1.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file asgard_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: asgard_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asgard_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 523c2202e9a8296cf67bf93e50d9ce8d1fef89a09194cafa1f274c87013d7590
MD5 f5279afb181cf5cdfc5747ed66b0f8e9
BLAKE2b-256 77f8cb6d2bb715f1d763b88b1633cf2cbc09dab3ccdc543c88896adc9fd9caa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgard_sdk-0.1.0.tar.gz:

Publisher: publish.yml on asgard-ai-platform/asgard-sdk-python

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

File details

Details for the file asgard_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asgard_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asgard_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a8833352e8b25e8582d06d6047a6be16fd426ccd2b2d1f40f2eeedce5e4e9b6
MD5 d73f5ee45b3d4d22b950d548c2c12a78
BLAKE2b-256 2d6f674666a63960561fe11a913a020f668739caf7a3d7c034623ba9238939df

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgard_sdk-0.1.0-py3-none-any.whl:

Publisher: publish.yml on asgard-ai-platform/asgard-sdk-python

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.0 This release

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