feat(connector): one-call setup() for any agent#172
Closed
risjai wants to merge 1 commit into
Closed
Conversation
…t in one block Adds rewind_agent.connector.setup(name=...): a context manager that composes ExplicitClient.session() + intercept.install() in the right order so callers don't have to remember the dance. Eliminates the silent-no-op trap where intercept records nothing because no session is active — the most common Tier-1 integration mistake. Behavior - Wraps the with-block in a fresh session, sets _session_id and _timeline_id contextvars, installs HTTP intercept, yields the ExplicitClient for non-HTTP record_* paths inside the block, and cleans up on exit. - Honors REWIND_ENABLED=0 as a true zero-overhead kill switch (yields None, no install, no HTTP). - Honors REWIND_URL (default 127.0.0.1:4800) and REWIND_LLM_HOSTS (comma-separated) for env-based config; kwargs override env. - When REWIND_SESSION_ID and REWIND_REPLAY_CONTEXT_ID are set (runner-subprocess pattern from docs/runners.md), skips creating a fresh session and lets intercept.install() attach to the existing replay context — no phantom sessions during runner-driven replays. - Idempotent intercept install: doesn't uninstall on exit if the caller already had it installed at entry. Implementation - python/rewind_agent/connector.py — ~150 LOC including docstrings. - python/rewind_agent/__init__.py — re-exports the connector module in __all__ and updates the package docstring. - python/tests/test_connector.py — 12 tests covering kill switch (env + kwarg), session lifecycle, replay-dispatch detection, host predicates from env / kwarg / defaults, idempotent install, and public export. Version - python/pyproject.toml + __init__.py bumped 0.16.0 → 0.16.1 per CLAUDE.md Track 2 (python/ files changed; 0.16.0 is on PyPI). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
6 tasks
Collaborator
Author
|
Combined into #171 — same code, plus docs/hdk.md updated to lead Tier 1 with the new connector.setup() API. Single PR is easier to review and ship together. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rewind_agent.connector.setup(name=...)context manager — one call to composeExplicitClient.session()+intercept.install()in the right order.withblock.rewind-agent0.16.0 → 0.16.1.Why
PR #171 shipped docs that route framework integrators to
intercept.install()for HTTP-shaped LLM clients. But the working pattern requires three things in the right order: open anExplicitClientsession (sets_session_id/_timeline_idcontextvars) → callintercept.install(predicates=...)→ tear both down on exit. Get the order wrong and intercept records nothing — silently, becauserecord_llm_callreturnsNonewhen no session is active (explicit.py:276-278).connector.setup()is the blessed one-liner. ~150 LOC including docstrings; the actual orchestration is a dozen lines. Every Tier-1 integration becomes:What's in the API
REWIND_ENABLED=0makessetup()a true no-op (yieldsNone, no HTTP, no install).REWIND_LLM_HOSTS=a.example,b.example(comma-separated) extends the strict-by-default LLM provider list. Kwargs override env.REWIND_URLenv var orbase_url=kwarg.REWIND_SESSION_ID+REWIND_REPLAY_CONTEXT_IDare set (runner-subprocess pattern from docs/runners.md),setup()skips creating a fresh session and letsintercept.install()attach to the existing replay context. No phantom sessions during runner-driven replays.ExplicitClientfor callers that needrecord_llm_call/record_tool_callon custom transports (gRPC, in-process LLMs).Tests
12 tests in
python/tests/test_connector.pycovering:thread_idandmetadatapropagationFull python suite:
488 passed, 1 skipped(the 1 skip is unrelated env-conditional).Why ship in
rewind_agentrather than as a separate packageThe original plan considered shipping this as an external connector package (one per org). After review, the abstraction is generic: nothing in it is specific to a particular gateway, app, or framework. Every Tier-3 integrator would write the same shape. Keeping it in the SDK gives every consumer one blessed pattern, eliminates the silent-no-op pitfall, and avoids per-team copy-paste drift.
This is meaningfully smaller than the
FrameworkAdapterProtocol Santa Method review rejected from the original plan: no new type, noStore/Recorderleak, no entrypoint discovery, no Protocol — just one@contextmanagerfunction that calls two existing public APIs in the right order.Test plan
cd python && pytest tests/test_connector.py -v— 12/12 green.cd python && pytest --ignore=tests/e2e— full suite green (488 passed locally).with rewind_agent.connector.setup("smoke"): httpx.post("https://api.openai.com/v1/chat/completions", ...)against a runningrewind webserver; confirm session shows up viarewind show latest.REWIND_SESSION_ID+REWIND_REPLAY_CONTEXT_IDin a subshell; confirmsetup()does NOT create a phantom/api/sessions/startcall.python/scripts/publish-pypi.sh.Follow-up
A small docs PR will update
docs/hdk.mdTier 1 to recommendrewind_agent.connector.setup()as the one-liner. Deferred to a separate PR because that file lands in #171, which hasn't merged yet.🤖 Generated with Claude Code