Skip to main content

Python SDK for AgentBox private agent state and scoped sharing.

Project description

AgentBox Python SDK

Python SDK for AgentBox private agent state and scoped sharing.

Use the public production service at https://agentbox.niuniu.dev/ for Agent Card discovery and SDK integration. Discovery and package installation work without private repository access.

Full SDK API reference: https://github.com/pengmu/agent-box/blob/main/docs/sdk-reference.md

Install

python3 -m pip install niuniu-agentbox

Import the SDK as agentbox:

from agentbox import AgentBoxClient

Production Auth

Creating boxes in production requires an OIDC identity token from a provider configured by AgentBox, such as Google. Pass that identity token as identity_token with the matching auth_scheme; when a recipient uses an AgentBox grant, keep the scoped grant token separate from the identity token.

First Private Box With Google OIDC

Get a Google ID token for the Google OAuth client configured by AgentBox production, then keep it outside source code:

export AGENTBOX_GOOGLE_ID_TOKEN='<google-id-token>'

The token must be a Google ID token, not an OAuth access token, and its aud claim must match the Google OAuth client trusted by AgentBox.

import os

from agentbox import discover_agentbox

service = discover_agentbox(base_url="https://agentbox.niuniu.dev")

agentbox = service.create_client(
    identity_token=os.environ["AGENTBOX_GOOGLE_ID_TOKEN"],
    auth_scheme="google",
)

agentbox.register_agent({
    "display_name": "My First Agent",
    "capabilities": ["notes"],
})

created = agentbox.create_box({
    "name": "First private box",
})

box_id = created["data"]["box"]["box_id"]

agentbox.put_item({
    "box_id": box_id,
    "key": "notes/hello",
    "value": "Hello from an identity-bound private box.",
    "expected_version": 0,
})

manifest = agentbox.get_manifest({
    "box_id": box_id,
})

print([item["key"] for item in manifest["data"]["items"]])

The box is private to the verified Google identity. To let another identity read selected resources, create an AgentBox grant and pass that grant as grant_token while the recipient still authenticates with its own Google ID token.

Discovery And Workflow

import os

from agentbox import (
    bootstrap_agentbox_agent,
    client_for_grant,
    create_private_box_with_resources,
    create_scoped_read_grant,
)

session = bootstrap_agentbox_agent(
    base_url="https://agentbox.niuniu.dev",
    client={
        "identity_token": os.environ["RESEARCH_OIDC_JWT"],
        "auth_scheme": "google",
    },
    registration={
        "display_name": "Research Agent",
        "capabilities": ["research"],
    },
)

workspace = create_private_box_with_resources(session.client, {
    "name": "Research handoff",
    "items": [
        {
            "key": "research/summary",
            "value": "Only this summary is shared.",
            "expected_version": 0,
        },
        {
            "key": "state/internal",
            "value": "Private notes stay hidden.",
            "expected_version": 0,
        },
    ],
})

grant = create_scoped_read_grant(session.client, {
    "box_id": workspace["box"]["box_id"],
    "subject": "writer-agent",
    "key_prefixes": ["research/"],
    "ttl_seconds": 3600,
})

writer = client_for_grant(
    session.client,
    grant,
    identity_token=os.environ["WRITER_OIDC_JWT"],
    auth_scheme="google",
)

manifest = writer.get_manifest({"box_id": workspace["box"]["box_id"]})

Auth Modes

AgentBox clients authenticate with OIDC identity tokens. Grant clients can carry the AgentBox scoped grant separately with grant_token, or use client_for_grant(...) to derive a least-privilege client from a grant response. Pass auth_scheme for named providers such as google.

API Reference

The SDK exposes discovery helpers, workflow helpers, and client methods for agents, boxes, items, events, artifacts, grants, and audit records. See the full reference for method inputs, return shapes, auth overrides, and error handling: https://github.com/pengmu/agent-box/blob/main/docs/sdk-reference.md

Pilot Network Usage

Native Pilot identity is provided by a Pilot-aware runtime or the AgentBox Pilot adapter before requests reach AgentBox. SDK application code should keep using normal box, item, artifact, grant, manifest, and audit methods. Do not set auth_scheme="pilot" or handcraft Pilot authentication headers in agent code; that path is for the AgentBox adapter/runtime boundary. If a Pilot caller uses an AgentBox grant, pass it as grant_token.

Methods

health()
discover_agentbox(base_url=... | agent_card_url=...)
bootstrap_agentbox_agent(...)
create_private_box_with_resources(client, data)
create_scoped_read_grant(client, data)
client_for_grant(client, grant, ...)
register_agent(data=None)
get_agent_profile()
create_box(data)
list_boxes()
get_manifest({"box_id": ...})
put_item(data)
get_item(data)
list_items(data)
append_event(data)
list_events(data)
attach_artifact(data)
list_artifacts({"box_id": ...})
get_artifact(data)
create_grant(data)
list_grants({"box_id": ...})
revoke_grant(data)
with_auth(identity_token=None, grant_token=None, auth_scheme=None)

Non-2xx responses and AgentBox { "ok": false } responses raise AgentBoxApiError.

License

MIT

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

niuniu_agentbox-0.1.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

niuniu_agentbox-0.1.5-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file niuniu_agentbox-0.1.5.tar.gz.

File metadata

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

File hashes

Hashes for niuniu_agentbox-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b66b83477d117f86f0e249f980a2899c70f92413eaf7b43cf528366c3bf77b15
MD5 41e374c5c8ca613e6feb40e804616f20
BLAKE2b-256 c9ab07501c1fcc7ce32ecc7c061e9d592ee7473e49cefeac57988e92d91344d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for niuniu_agentbox-0.1.5.tar.gz:

Publisher: publish-sdk.yml on pengmu/agent-box

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

File details

Details for the file niuniu_agentbox-0.1.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for niuniu_agentbox-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0eea29cad0b9796d3c6181273dc112c6eeaa1c1c89751f1e9caba58fa8f763c4
MD5 aa448eb9d48c86a4b6ea3dad83e6237e
BLAKE2b-256 50a467f3b07dfc91c5ecd63146459194e52d83eb8863e0b650ffd807053870a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for niuniu_agentbox-0.1.5-py3-none-any.whl:

Publisher: publish-sdk.yml on pengmu/agent-box

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

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