Metadata-Version: 2.5
Name: supertag
Version: 0.3.1
Summary: Python SDK for SuperTag: harness adapters for Worker Hosts and a Gateway client
Project-URL: Homepage, https://github.com/atemaguer/supertag
Project-URL: Documentation, https://github.com/atemaguer/supertag/tree/main/docs
Project-URL: Repository, https://github.com/atemaguer/supertag
Project-URL: Issues, https://github.com/atemaguer/supertag/issues
Author: SuperTag maintainers
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,codex,control-plane,grpc,harness,openai,supertag,workers
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Provides-Extra: agents
Requires-Dist: openai-agents<0.9,>=0.8; extra == 'agents'
Requires-Dist: openai<2.45; extra == 'agents'
Provides-Extra: codex
Requires-Dist: openai-codex<0.145,>=0.144.4; extra == 'codex'
Provides-Extra: dev
Requires-Dist: grpcio-tools==1.85.1; extra == 'dev'
Requires-Dist: grpcio<2,>=1.85.1; extra == 'dev'
Requires-Dist: openai-agents<0.9,>=0.8; extra == 'dev'
Requires-Dist: openai-codex<0.145,>=0.144.4; extra == 'dev'
Requires-Dist: openai<2.45; extra == 'dev'
Requires-Dist: protobuf<8,>=7.36.2; extra == 'dev'
Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'dev'
Requires-Dist: pytest<9,>=8; extra == 'dev'
Requires-Dist: ruff<0.16,>=0.15; extra == 'dev'
Provides-Extra: runtime
Requires-Dist: grpcio<2,>=1.85.1; extra == 'runtime'
Requires-Dist: protobuf<8,>=7.36.2; extra == 'runtime'
Description-Content-Type: text/markdown

# SuperTag Python SDK

The Python SDK has three parts:

- `supertag.harness_adapter`: write a harness adapter that a SuperTag Worker Host starts to run one
  Task Attempt.
- `supertag.openai_agents_adapter`: the OpenAI Agents harness adapter that a Worker Host starts for
  a Tag whose harness is `openai-agents`.
- `supertag.gateway_client`: call a SuperTag Gateway from Python.

It also contains the Worker composition interfaces (`create_worker`, harnesses, execution
environments, Runtime Inputs, and Session continuity) that the OpenAI Agents adapter is built on.

For the SuperTag CLI, Control Plane, and Gateway, see [Requirements](../../docs/operations/requirements.md).
Python dependencies are declared in [pyproject.toml](pyproject.toml).

Install the published SDK from PyPI, pinned to the version of your CLI:

```sh
python -m pip install 'supertag==0.3.1'
python -m pip install 'supertag[runtime]==0.3.1'
```

The `runtime` extra installs gRPC and protobuf for the adapter and Gateway clients. Add the
harness integrations you use:

```sh
python -m pip install 'supertag[codex]==0.3.1'
python -m pip install 'supertag[agents]==0.3.1'
python -m pip install 'supertag[codex,agents]==0.3.1'
```

`agents` installs the OpenAI Agents SDK and `codex` the `openai-codex` SDK. For source development, see [CONTRIBUTING.md](../../CONTRIBUTING.md).

## Run a Python harness adapter with a Worker Host

A Worker Host is the machine or sandbox that provides execution. It launches a harness
adapter to run one Task Attempt, which is a single try at completing a unit of work. Install
the SDK with its `runtime` extra. Pass the executable to the Worker Host through its
`--adapter` option.

```python
import asyncio
import sys

from supertag.harness_adapter import open_harness, runtime

async def main():
    async with open_harness(sys.stdin.buffer) as harness:
        run = await harness.client.Attach(runtime.HarnessAttachRequest(), timeout=5)
        result = f"Received work for {run.task.tag_id}"
        await harness.client.Publish(
            runtime.HarnessPublishRequest(
                sequence=1, text=result, kind=runtime.TASK_EVENT_KIND_MESSAGE
            ),
            timeout=5,
        )
        await harness.client.Complete(
            runtime.HarnessCompleteRequest(succeeded=True, result=result), timeout=5
        )

asyncio.run(main())
```

The Worker Host supplies a private execution connection on standard input. It records the
outcome after the adapter exits successfully. Reuse the same sequence number and request
body when retrying an event.

The OpenAI Agents adapter runs as `python -m supertag.openai_agents_adapter`; the Worker Host starts
it for a Tag whose harness is `openai-agents`. It needs `OPENAI_API_KEY` and the `agents` extra.

## Call the Gateway

Use `supertag.gateway_client`. The `runtime` extra installs gRPC and protobuf. This example
lists Tags, the persistent AI actors in your organization.

```python
import os

from supertag.gateway_client import GatewayClientSync, runtime

with GatewayClientSync(
    os.environ["SUPERTAG_GATEWAY_URL"], os.environ["SUPERTAG_OPERATOR_TOKEN"]
) as client:
    response = client.operator.ListTags(runtime.ListTagsRequest(), timeout=5)
    for tag in response.tags:
        print(tag.name)
```

`GatewayClient` exposes the same services with `async with` and awaitable unary calls.
The generated gRPC methods use the protobuf RPC names, such as `ListTags` and `Watch`.
Pass a `timeout` in seconds to bound a call. Watch streams can resume from their last
`resume_token`. Use HTTPS for a remote Gateway and a loopback IP address for local
cleartext. Pass a PEM `ca` for private TLS and a PEM certificate chain and key as
`identity=(cert, key)` if the Gateway requires mutual TLS. The first call negotiates the
SuperTag protocol version with the Gateway and raises `GatewayProtocolError` when the
Gateway runs an incompatible release.

## Compose a Worker in process

`create_worker(WorkerOptions(...))` composes Worker Profiles, harnesses, execution environment
providers, and optional `RuntimeInputProvider` values into the `Worker` contract, and
`LocalWorklet` runs Workers in the same process. The OpenAI Agents adapter uses them to run one
Task Attempt; they do not connect to a Control Plane by themselves.

Each `HarnessPlan` separates private `runtime` staging from workspace `execution` staging. A
harness receives both accesses. `ContextResolver`, `WorkspaceResolver`, and `ToolProvider` are
focused convenience interfaces built on Runtime Inputs. A `ToolAdapter` turns an allowed
`ToolInput` into the configuration expected by a particular harness. Pass an
`InMemorySessionStateStore` or a `FileSessionStateStore` for Session continuity.

The built-in local environment provider is attempt-scoped and gives child processes only common
process-launch plumbing variables plus values explicitly projected by the provider or process
specification. It supports `supertag.process-output-streaming` version 1: pass
`ProcessSpec(stream_output=True)` and consume `async for chunk in process.output()`. POSIX
processes run in owned process groups; cancellation and timeouts escalate from termination to kill
before cleanup. An environment must raise `ExecutionCleanupError` when it cannot confirm cleanup.

Custom harnesses can emit `TaskProgress(...).event()` to provide a bounded progress summary and
checklist. Progress is a complete latest-wins snapshot, not a reasoning trace: never include
prompts, commands, tool arguments, credentials, or runtime identifiers.
