Skip to content

v0.20.0 — align SDK adapter session-limit enforcement

Choose a tag to compare

@flyersworder flyersworder released this 10 May 19:46
· 7 commits to main since this release
5ce86ae

Changed

  • create_sdk_mcp_server now auto-applies session-limit enforcement to all 9 tools by default, matching the v0.19.0 behavior of create_langchain_tools. Pre-v0.20.0, only run_query self-checked ContractSession limits — lookup tools (describe_table, list_metrics, etc.) bypassed. The two adapters now behave identically: a single contract YAML enforces the same way under SDK and LangChain.
  • Practical effect: max_duration_seconds now measures wall-clock from the first tool call (any tool), not just from the first run_query. For most contracts this is invisible — lookups complete in milliseconds. The narrow population that sees a behavior change: agents with tight max_duration_seconds AND lookup-heavy prompts that browse extensively before querying. The new behavior matches the YAML's documented intent ("the agent has N seconds total"), and closes the runaway-loop gap where an agent stuck on lookup tools previously bypassed the duration cap.
  • Escape hatch: pass apply_middleware=False to create_sdk_mcp_server to restore pre-0.20.0 behavior.

Added

  • New _wrap_with_session_check(inner, session) helper in tools/sdk.py — exported as a private symbol so tests can verify the enforcement wrapper directly without going through the SDK's @tool decorator. Mirrors the in-tool enforcement pattern in tools/langchain.py:_to_structured_tool.

Fixed

  • Wrapper-emitted BLOCKED envelopes now include the canonical Remaining: {budget} suffix that run_query's self-emitted blocks have always carried (per factory.py:627-628). Pre-0.20.0 the LangChain wrapper (introduced in v0.19.0) and the new SDK wrapper both omitted this suffix, so agents whose retry-planning logic depended on the suffix would lose context once they hit the wrapper layer instead of run_query's own block. Applies to both _wrap_with_session_check (SDK) and _to_structured_tool / ContractMiddleware._check (LangChain).

Compatibility

  • Public API unchanged — create_sdk_mcp_server gains one optional kwarg with a sensible default. Pre-built ToolDef lists, custom sessions, and all other call shapes continue to work.
  • 6 new tests in tests/test_tools/test_sdk.py cover the wrapper behavior and the new kwarg.