Skip to main content

Async Python SDK for invoking Opal agents over PAT-authenticated REST and socket.io.

Project description

opal-agent-sdk (Python)

Async Python SDK for invoking Opal agents programmatically over a Personal Access Token (PAT).

Install

pip install opal-agent-sdk            # core
pip install "opal-agent-sdk[cli]"     # adds the `opal` CLI

Python 3.10+. Async-only.

Quickstart

import asyncio
import os
from opal_agent_sdk import OpalClient, OpalConfig, PATAuth

async def main() -> None:
    async with OpalClient(
        auth=PATAuth(os.environ["OPAL_PAT"]),
        config=OpalConfig(instance_id="your-instance-id"),
    ) as client:
        result = await client.agents.specialized.run(
            agent_id="your-agent-uuid",
            parameters={"query": "Where is order #1234?"},
        )
        print(result.output_text)

asyncio.run(main())

See examples/ for more (streaming, multi-turn chat, workflow agents, canvas access).

Configuration

Parameter Env var Default Description
base_url OPAL_BASE_URL https://api.opal.optimizely.com API Gateway URL
instance_id OPAL_INSTANCE_ID (required) Opal instance ID
timeout_s 30.0 Per-request timeout in seconds
retry_max_attempts 3 Max retry attempts for idempotent 5xx
verify_ssl True SSL certificate verification. Set to False for localdev only — do not disable in production

You can also use OpalConfig.from_env() to load from environment variables.

Streaming

async with OpalClient(auth=PATAuth(pat), config=config) as client:
    async for event in client.agents.specialized.stream(
        agent_id="your-agent-uuid",
        parameters={"query": "Summarize this article"},
    ):
        if event.event_type == "response_chunk":
            print(event.payload["content"], end="", flush=True)

Multi-turn Chat

async with client.agents.specialized.chat_stream(
    agent_id="your-agent-uuid",
) as chat:
    async for event in chat.send("Hello"):
        ...  # handle events

    async for event in chat.send("Tell me more"):
        ...  # chat.memory_id and chat.etag are managed automatically

Catalog: list / export / import Agents and Skills

Agents

# List + iterate
page = await client.agents.list(type="specialized")
for agent in page:
    print(agent.agent_id, agent.name)
async for agent in client.agents.iter(type="all"):
    print(agent.agent_id)

# Export — single agent (returns dict, optionally writes file)
doc = await client.agents.export("agent-id", type="specialized")
await client.agents.export("agent-id", type="specialized", output_file=Path("/tmp/a.json"))

# Export — recursive workflow tree (returns AgentExportTree)
tree = await client.agents.export("wf-id", type="workflow", recursive=True)
await client.agents.export(
    "wf-id", type="workflow", recursive=True,
    output_file=Path("/tmp/agents/"),
)

# Import — single agent, or recursive tree (topological sort + cycle detection)
result = await client.agents.import_(doc, type="specialized")
results = await client.agents.import_tree(Path("/tmp/agents/"))

# Shares
grants = await client.agents.list_shares("agent-id", type="specialized")

Skills

# List
page = await client.skills.list(scope="org")
for skill in page:
    print(skill.skill_guid, skill.title)

# Export — JSON envelope, SKILL.md, or whole plugin bundle
doc = await client.skills.export("skill-guid", scope="org")
await client.skills.export(
    "skill-guid", scope="org", format="skill_md",
    output_file=Path("/tmp/skills/"),  # directory; SKILL.md is a directory artifact
)
result = await client.skills.export_as_plugin(
    ["g1", "g2"], scope="org",
    plugin_name="my-plugin", plugin_description="...",
    output_dir=Path("/tmp/plugin/"),
)

# Import — JSON, SKILL.md, or whole plugin bundle
r = await client.skills.import_(doc, scope="org")
rs = await client.skills.import_plugin(Path("/tmp/plugin/"))

For the wire shapes and round-trip semantics, see docs/tech-spec/agent-framework/agent-sdk/skills-agents-export-import.md.

Development

make install        # pip install -e ".[dev,cli]"
make test           # pytest
make lint           # ruff check
make format         # ruff format
make typecheck      # mypy --strict
make check          # all of the above

Demo App

A FastAPI + HTML demo app is included in demo/ — see its README for setup instructions.

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

opal_agent_sdk-0.2.1.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

opal_agent_sdk-0.2.1-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: opal_agent_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for opal_agent_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0d95591983acd79c10c7cbc5da9ea6136f33ee75cdc2613924c7049ccc114320
MD5 f43df8f7287a7fac17c742dc43ff966f
BLAKE2b-256 4aaae8b8000ac61b25f713757bcd9c1643f15ff8865b5eedf097276d064b06e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: opal_agent_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 55.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for opal_agent_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52d46db6f5ccf152fad0619179a811039936b9dbfbcc31f9069010b5c0886abf
MD5 fd5466506ac550bec32526cc12fa2502
BLAKE2b-256 2ab13d1531599443847065de7b9cd250321bb9b15e7e08133df3609d2948c501

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