Python SDK for creating and managing TryAgent escalations.
Project description
tryagent
Python SDK for creating and managing TryAgent escalations from agents, workflows, and reviewer tooling.
Full documentation: https://tryagentai.mintlify.app/quickstart
Install
The Python SDK package lives in this repository and is not published to PyPI yet. From a checkout, install it locally:
python3 -m pip install -e packages/python-sdk
After the first PyPI release, install it with:
python3 -m pip install tryagent
Create a client
import os
from tryagent import TryAgent
tryagent = TryAgent(api_key=os.environ["TRYAGENT_API_KEY"])
Override base_url for local development or tests:
tryagent = TryAgent(
api_key=os.environ["TRYAGENT_API_KEY"],
base_url="http://localhost:4000",
)
Send an escalation
Request payloads use the TryAgent API's camelCase fields, even from Python.
import os
from tryagent import TryAgent
tryagent = TryAgent(api_key=os.environ["TRYAGENT_API_KEY"])
escalation = tryagent.escalate(
"orders.auth_doc",
{
"agentId": "order-agent",
"runId": "run_4821",
"subject": {
"type": "order",
"id": "ord_4821",
"label": "Order #4821",
},
"question": "The authorization document is missing a signature date. Continue?",
"evidence": [
"Candidate name is present.",
"Employer is present.",
"Signature date is blank.",
],
"choices": [
{"id": "manual_review", "label": "Send to manual review"},
{"id": "continue", "label": "Continue anyway"},
],
"resume": {
"mode": "webhook",
"url": "https://api.example.com/tryagent/resume",
"secret": os.environ["TRYAGENT_WEBHOOK_SECRET"],
},
},
)
print(escalation["id"], escalation["status"])
Resume a workflow
Always pass the raw request body to tryagent.webhooks.construct_event. Parsing
and re-serializing JSON changes the signed bytes.
import os
from tryagent import TryAgent, WebhookSignatureError
tryagent = TryAgent(api_key=os.environ["TRYAGENT_API_KEY"])
def handle_resume(raw_body: bytes, signature: str | None) -> tuple[dict[str, bool], int]:
try:
event = tryagent.webhooks.construct_event(
payload=raw_body,
signature=signature,
secret=os.environ["TRYAGENT_WEBHOOK_SECRET"],
)
except WebhookSignatureError:
return {"ok": False}, 401
resume_workflow(
event["runId"],
{
"escalationId": event["escalationId"],
"choice": event.get("choice"),
"answeredBy": event.get("answeredBy"),
"answeredAt": event.get("answeredAt"),
},
)
return {"ok": True}, 200
Manage escalations
open_escalations = tryagent.escalations.list(status="open")
escalation = tryagent.escalations.get("esc_123")
tryagent.escalations.acknowledge("esc_123")
tryagent.escalations.decide(
"esc_123",
{
"choice": "continue",
"reason": "Signature verified out of band.",
"response": {"approvedLimit": 5000, "riskLevel": "low"},
},
)
tryagent.escalations.cancel("esc_456", {"reason": "Order withdrawn."})
Handle API errors
Non-2xx API responses and network failures raise ApiError. Network failures
use status == 0; API responses use the HTTP status code. body contains the
parsed response body when available, and request_id is read from the
x-request-id response header when present.
from tryagent import ApiError
try:
tryagent.escalate("orders.auth_doc", input)
except ApiError as error:
print(error.status, error.request_id, error.body)
raise
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tryagent-0.0.1.tar.gz.
File metadata
- Download URL: tryagent-0.0.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
736bd4b5a3749a8ae1635b5e9b93d1bf92070b98cf0c8828bf504887143b44f6
|
|
| MD5 |
3ef8958bbdf3b57ef9222d4124b18b5f
|
|
| BLAKE2b-256 |
51d538094b73ccf17576d363d4a0c2dabfc153d63046fa7be4e2ec63685a61a1
|
Provenance
The following attestation bundles were made for tryagent-0.0.1.tar.gz:
Publisher:
publish-python-sdk.yml on hiredbyreact/agentInbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tryagent-0.0.1.tar.gz -
Subject digest:
736bd4b5a3749a8ae1635b5e9b93d1bf92070b98cf0c8828bf504887143b44f6 - Sigstore transparency entry: 1954283119
- Sigstore integration time:
-
Permalink:
hiredbyreact/agentInbox@2b18fcd98d9d6046431ae3e7b9694b24a25be9c8 -
Branch / Tag:
refs/tags/python-sdk-v0.0.1 - Owner: https://github.com/hiredbyreact
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-sdk.yml@2b18fcd98d9d6046431ae3e7b9694b24a25be9c8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tryagent-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tryagent-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0539cb2e556a6da22697650e137eef99c70ee278accf8c9a219ac6846c1a8590
|
|
| MD5 |
ded1916df6f4e8eaeaf16329cda0a63c
|
|
| BLAKE2b-256 |
2b4edc569ad8fbef923073bd886ab141c1640240578de0a4db528cffab3b8f90
|
Provenance
The following attestation bundles were made for tryagent-0.0.1-py3-none-any.whl:
Publisher:
publish-python-sdk.yml on hiredbyreact/agentInbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tryagent-0.0.1-py3-none-any.whl -
Subject digest:
0539cb2e556a6da22697650e137eef99c70ee278accf8c9a219ac6846c1a8590 - Sigstore transparency entry: 1954283319
- Sigstore integration time:
-
Permalink:
hiredbyreact/agentInbox@2b18fcd98d9d6046431ae3e7b9694b24a25be9c8 -
Branch / Tag:
refs/tags/python-sdk-v0.0.1 - Owner: https://github.com/hiredbyreact
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-sdk.yml@2b18fcd98d9d6046431ae3e7b9694b24a25be9c8 -
Trigger Event:
push
-
Statement type: