Skip to content

feat(integrations): add Superagent safety middleware#1128

Open
DK09876 wants to merge 9 commits intomainfrom
feat/superagent-integration
Open

feat(integrations): add Superagent safety middleware#1128
DK09876 wants to merge 9 commits intomainfrom
feat/superagent-integration

Conversation

@DK09876
Copy link
Copy Markdown
Contributor

@DK09876 DK09876 commented Apr 17, 2026

Summary

  • Adds hindsight-superagent integration — a safety middleware wrapping Hindsight memory ops with Superagent Guard (prompt injection detection) and Redact (PII removal)
  • SafeHindsight class wraps retain, recall, reflect with configurable guard + redact pipeline
  • Global configure() / per-instance config with env var fallbacks, following existing integration patterns
  • CI job in test.yml + release script entry

Test plan

  • 54 unit tests (config, client resolution, middleware) — all passing
  • 10 e2e tests against live Superagent + Hindsight APIs — all passing
  • Verified SDK usage matches safety-agent package patterns
  • CI passes on this PR

🤖 Generated with Claude Code

@DK09876 DK09876 marked this pull request as ready for review April 23, 2026 15:34
DK09876 and others added 9 commits April 23, 2026 08:40
…mory

Adds hindsight-superagent integration that wraps Hindsight retain/recall/reflect
with Superagent Guard (prompt injection detection) and Redact (PII removal).

- SafeHindsight middleware class with configurable guard + redact pipeline
- Global configure() / per-instance config with env var fallbacks
- CI job and release script entry
- 54 unit tests + 10 e2e tests (all passing)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ured

Matches the pattern used by all other integrations — falls back to
https://api.hindsight.vectorize.io instead of erroring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- resolve_safety_client now raises HindsightError if no API key is
  provided, matching actual safety-agent behavior (create_client()
  requires a key)
- README: document superagent_api_key as required, hindsight_api_url
  defaults to Hindsight Cloud URL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…resolution

The safety-agent SDK's default fallback endpoint (superagent.sh/api/fallback)
returns a 307 redirect that httpx doesn't follow for POST requests, causing
all guard() calls to fail on cold starts. This change:

- Defaults enable_fallback=False so the primary Cloud Run endpoint is used
  directly (60s timeout is sufficient)
- Exposes enable_fallback and fallback_timeout in config/SafeHindsight for
  users who want to opt back in
- Adds os.environ fallback for SUPERAGENT_API_KEY in resolve_safety_client
  so it works without calling configure() first
- Fixes e2e redact test that was blocked by guard on recall query

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Superagent's hosted guard endpoints (Cloud Run Ollama) currently serve
empty model lists, making the default superagent/guard-1.7b unusable.
Update all examples to use guard_model="openai/gpt-4o-mini" and document
the self-hosting alternative. Increase Hindsight client timeout from 30s
to 120s to accommodate reflect's server-side LLM call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
General-purpose LLMs (gpt-4o-mini) over-classify PII content as security
violations, blocking retain before redact runs. Disable guard on retain
in all examples and default test helper. Fix e2e tests to use explicit
guard_model and OpenAI provider instead of broken hosted endpoints.

All 10 e2e tests now pass against live APIs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gpt-4.1-nano correctly distinguishes prompt injection from legitimate
content (including PII), eliminating the need to disable guard on retain.
Re-enables full Guard → Redact → Retain pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace Any return types on recall() and reflect() with
RecallResponse and ReflectResponse from hindsight-client.
Add py.typed marker for PEP 561 type checker support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DK09876 DK09876 force-pushed the feat/superagent-integration branch from e1deb8f to fcfd95c Compare April 23, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant