Skip to main content

pushary-openai-agents

Human-in-the-loop for the OpenAI Agents SDK (Python). A function tool that asks a real human to approve, delivered to their phone, and blocks on a fail-closed answer.

Requires the Pushary Partner plan.

Install

pip install pushary-openai-agents

Set PUSHARY_API_KEY (get it in your dashboard).

Connect a phone once

from pushary_openai_agents import connect

link = connect("user_123")  # show this to your end-user; one tap connects their phone

The tool

from agents import Agent, Runner
from pushary_openai_agents import pushary_tool

agent = Agent(
    name="Support",
    instructions="Call ask_human before issuing any refund.",
    tools=[pushary_tool("user_123")],
)
result = await Runner.run(agent, "Refund order 5?")

When the model calls the tool, Pushary delivers the question to that user's phone and the call blocks until they answer. The tool returns a fail-closed instruction. The external_id is bound when you build the tool, never taken from the model, so a prompt-injected agent cannot ask the wrong person.

Gating a tool the model cannot skip

pushary_tool is a tool the model chooses to call. That is right for "go ask someone about this", and wrong for "this must not happen without a yes", because a model that does not want to be interrupted can decline to call it.

The SDK's own gate splits in two: needs_approval decides whether a human is needed, and the run then stops with result.interruptions. Nothing asks anyone. Resolving those interruptions is the caller's job, and resolve_pushary_interruptions is that job done:

from agents import Agent, Runner, function_tool
from pushary_openai_agents import pushary_needs_approval, resolve_pushary_interruptions

@function_tool(needs_approval=pushary_needs_approval())
def issue_refund(amount: float) -> str:
    return charge_back(amount)

agent = Agent(name="Support", instructions="Refund when asked.", tools=[issue_refund])

result = await Runner.run(agent, "Refund order 1234")
while result.interruptions:
    outcome = resolve_pushary_interruptions(result, external_id="user_123")
    if not outcome.all_approved:
        break
    result = await Runner.run(agent, outcome.state)

Resume with outcome.state, not result.to_input_list(). The second replays the conversation without the decisions on it, so the model asks for the same tool again and the person gets paged twice.

Each interruption becomes one decision on the phone, resolved in order so the person sees one question at a time. A denial is handed back to the model as the rejection message, so it knows why it was stopped rather than retrying blindly.

Fail-closed: a denial, an expiry, or nobody answering all reject. For a multi-tenant product, resolve the end-user per interruption:

resolve_pushary_interruptions(
    result, external_id=lambda item: owner_of(item.raw_item.call_id)
)

Pass run_id= when you replay a run under ids you mint yourself, so the replay resolves to the same decisions instead of paging twice.

Durable approvals

For a wait longer than a request can hold, drive your own flow off ask_human with a callback_url on decisions.create and resolve the signed callback:

from pushary_openai_agents import resolve_pushary_callback, SIGNATURE_HEADER

def callback(request):
    cb = resolve_pushary_callback(request.body, request.headers.get(SIGNATURE_HEADER), SECRET)
    if not cb:
        return ("bad signature", 401)
    # look up your parked run by cb["correlationId"], approve/reject, resume
    return ("ok", 200)

For TypeScript, use npm i @pushary/openai-agents.

API

  • connect(external_id, *, api_key=None, base_url=None) — enroll an end-user's phone.
  • pushary_tool(external_id, *, name="ask_human", ...) — an OpenAI Agents function tool bound to that user.
  • ask_human(question, *, external_id, type="confirm", ...) — blocking, returns the decision dict.
  • pushary_needs_approval() — a needs_approval predicate that routes every call to a human.
  • resolve_pushary_interruptions(result, *, external_id, run_id="", ...) — ask about each interruption, then approve or reject it on the run's context.
  • resolve_pushary_callback(raw_body, signature, secret) — verify + parse a callback for the durable path.
  • create_pushary_gate(...) — the raw fail-closed gate, for anything the helpers above do not cover.
  • describe_answer(type, result), is_affirmative(answer), render_approval_question(tool, input), deterministic_key(parts), SIGNATURE_HEADER.

License

MIT

Download files

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

Source Distribution

pushary_openai_agents-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

pushary_openai_agents-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pushary_openai_agents-0.2.0.tar.gz.

File metadata

  • Download URL: pushary_openai_agents-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pushary_openai_agents-0.2.0.tar.gz
Algorithm Hash digest
SHA256 03d7fce61bcaca8863463fc29cbc52b464515960a07e81287e235600755a1958
MD5 af42550727e01de1206f648f17279768
BLAKE2b-256 5bb36fb68e75f99c4c38f890d42689c93fb5939777b76a0524faa2a5df1e9218

See more details on using hashes here.

Provenance

The following attestation bundles were made for pushary_openai_agents-0.2.0.tar.gz:

Publisher: release-pypi.yml on aadilghani1/pushary

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

File details

Details for the file pushary_openai_agents-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pushary_openai_agents-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 875c697a3284bca0894db317c83bfc6f19b8802116f991bc8479e216ae7bc954
MD5 dd0de25364052c0c800be3143e99fc7a
BLAKE2b-256 7648072a5923b90a8a0914f5c9a2c22e2888563adc98f91c7a9cdeb7a83dda1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pushary_openai_agents-0.2.0-py3-none-any.whl:

Publisher: release-pypi.yml on aadilghani1/pushary

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 Sentry Error logging StatusPage Status page