feat(keycardai-langchain): add LangChain integration package - #229
Draft
Larry-Osakwe wants to merge 1 commit into
Draft
feat(keycardai-langchain): add LangChain integration package#229Larry-Osakwe wants to merge 1 commit into
Larry-Osakwe wants to merge 1 commit into
Conversation
Delegated access at the tool-call boundary for LangChain 1.x agents: KeycardGrantMiddleware implements wrap_tool_call, acquires resource tokens under the identity of the run via keycardai-oauth, and exposes the result to tools as a non-throwing AccessContext. KeycardIdentity selects the access pattern per invocation: - subject_token: on-behalf-of (RFC 8693 token exchange) - as_self=True: the agent acts as itself (client credentials); never interrupts, since no user exists to send to a consent page - user_identifier: impersonation (forbidden by default, zone policy) Missing grants and sign-in pause the run with LangGraph interrupts when authorization_url / sign_in_url are set. keycardai.langchain.testing provides mock_access_context for testing tools without a zone. Includes two runnable examples (user-facing on-behalf-of agent with the interrupt/resume loop; background as-itself agent), extracted from the demo spike verified against a live zone. Registers the package in the justfile test and test-coverage targets so its suite runs in CI (fastmcp is missing from those lists, ECO-172).
Contributor
📦 Release PreviewThis analysis shows the expected release impact: 📈 Expected Version Changes📋 Package Details[
{
"package_name": "keycardai-langchain",
"package_dir": "packages/langchain",
"has_changes": true,
"current_version": "0.1.0",
"next_version": "0.2.0",
"increment": "MINOR"
}
]📝 Changelog PreviewThis comment was automatically generated by the release preview workflow. |
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.
New package:
keycardai-langchain. Delegated access at the tool-call boundary for LangChain 1.x agents — one middleware in the agent's middleware list, oneget_access_context()call inside each tool.What's in it
KeycardGrantMiddleware: implementswrap_tool_call/awrap_tool_call; acquires resource tokens per tool call under the identity of the run and exposes them as a non-throwingAccessContext. Works undercreate_agent, raw LangGraph, andcreate_deep_agent.KeycardIdentity(runtime context) selects the access pattern per invocation:subject_token— on-behalf-of (RFC 8693 token exchange)as_self=True— the agent acts as itself (client credentials). Never interrupts: no user exists to send to a consent page, so denials stay on theAccessContextas errors.user_identifier— impersonation (forbidden by default; requires zone policy)sign_in_required/authorization_required) whensign_in_url/authorization_urlare set, so the whole flow can live in the chat surface.keycardai.langchain.testing.mock_access_contextfor testing tools without a zone.examples/user_facing_agent(on-behalf-of, with the interrupt/resume loop) andexamples/background_agent(as-itself digest worker).The on-behalf-of and as-itself paths were verified against a live zone (calendar agent + background PR-digest agent); this package is the extraction of that spike.
Trying it from this branch
uv add "keycardai-langchain @ git+https://github.com/keycardai/python-sdk@larry/keycardai-langchain#subdirectory=packages/langchain"Start with
packages/langchain/README.md— it walks through all three configurations with examples.Tests
17 tests, 92% coverage (gate is 85).
just test-package langchain. Also registered in the justfiletest/test-coveragetargets so CI runs the suite.🤖 Generated with Claude Code