Skip to main content

backloop-sdk

Python SDK for the Agent Feedback Protocol: AI agents POST structured feedback to /feedback on the services they use, so those services learn what agents were trying to do when they got stuck.

  • Standard library only (Python 3.9+). Optional FastAPI and Flask helpers.
  • Validates against the protocol's JSON Schemas.
  • Mirrors the TypeScript SDK (@backloop/sdk): same validation messages, error codes and redaction.
pip install backloop-sdk              # import backloop
pip install "backloop-sdk[fastapi]"   # or [flask]

Agents: send feedback

from backloop import FeedbackClient

client = FeedbackClient("https://api.example.com", api_key=API_KEY, session_id="task_42")

result = client.try_submit({  # never raises: feedback must not break the task
    "type": "missing_capability",
    "goal": "Find companies currently hiring GTM engineers",
    "endpoint": "/companies/search",
    "method": "GET",
    "message": "No hiring-role filter is available",
    "outcome": "blocked",
    "suggestion": "Add a hiring_role query parameter",
})
if result.ok and "known_issue" in result.ack:
    print("Already tracked:", result.ack["known_issue"]["title"])

submit() does the same but raises FeedbackError(message, code, status, details). Both redact secrets, card numbers and emails before sending, and retry once on 429/5xx. Use FeedbackClient.from_discovery(base_url) to find the endpoint through /.well-known/agent-feedback, or feedback_url_from_link(response.headers["link"], url) to read it from an error response.

Give your agent the tool and the instructions:

from backloop import AGENT_FEEDBACK_INSTRUCTIONS, feedback_tool

tools = [feedback_tool()]  # {"name": "submit_feedback", "description", "input_schema"}
# When the model calls it: client.try_submit(tool_use.input)

Services: receive feedback

from backloop import FeedbackHandler, forward_to, hash_account

handler = FeedbackHandler(
    # wait: answer the agent after at most 0.5 s and go on forwarding in a background thread.
    on_record=forward_to("https://collector.example.com", ingest_key=INGEST_KEY, wait=0.5),  # or your own callable
    service="acme-companies-api",
    identify=lambda request: hash_account(current_account_id(request), SECRET) if authenticated(request) else None,
)

FastAPI or Flask:

from backloop import fastapi_router, flask_blueprint

app.include_router(fastapi_router(handler))       # FastAPI
app.register_blueprint(flask_blueprint(handler))  # Flask

Both serve POST /feedback and GET /.well-known/agent-feedback. Any other framework calls the handler directly:

status, body, headers = handler.handle_submit(raw_body, content_type, account, client_ip)
document = handler.discovery("https://api.example.com")

on_record(record) stores or forwards each accepted record. Return {"known_issue": {...}} to pass a tracked issue back to the agent. If it raises, the agent gets 503. Add feedback_link_header() as a Link header on your API's error responses so agents find the endpoint.

Utilities

from backloop import validate_submission, format_issues, redact

result = validate_submission(payload)
if not result.valid:
    print(format_issues(result.issues))  # "goal: is required; type: must be one of: ..."

redact({"note": "auth failed with Bearer 9f8e7d6c5b4a", "password": "hunter2"})
# {"note": "auth failed with [REDACTED]", "password": "[REDACTED]"}

Development

python3 -m unittest discover -s tests -t .

The tests run the shared conformance suite in spec/conformance. src/backloop/_generated.py is generated from spec/ by scripts/sync-schema.mjs; don't edit it by hand.

License: Apache-2.0

Metadata

Release files for backloop-sdk 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backloop-sdk 0.1.3
File Size Uploaded
backloop_sdk-0.1.3.tar.gz 36.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backloop-sdk 0.1.3
File Interpreter ABI Platform
backloop_sdk-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 65.5 kB

Release files / backloop_sdk-0.1.3.tar.gz

Download URL backloop_sdk-0.1.3.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
050af1fd6815de3c5a6c5d2a2603ab5654df95302d5e306693a59dcc52f59272
BLAKE2b-256 checksum
How to use checksums
052c267ef3c0a64d07bd5bffd14d0ebc48afaaa9bdabe156c97cdb3f1f5a6673
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / backloop_sdk-0.1.3-py3-none-any.whl

Download URL backloop_sdk-0.1.3-py3-none-any.whl
Size 28.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1ef92f828c720b476b8e342f32ad39a1b6a25d904edf0f51b1507fa89d2cca5
BLAKE2b-256 checksum
How to use checksums
6ea6030809329b7929dbbfa6abf1195d9abfc0268fad6441a7783ab0976081ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page