PowerContextMiddleware integrates with LangChain create_agent. It supports sync and async execution, changes only the current model request, and optionally captures a completed turn as Source evidence. It has no adapter-owned PowerContext tools.
Maturity and installation
Install the Server and middleware from the reviewed source commit:
The middleware is independent of
powercontext-langgraph. LangChain may install LangGraph internally, but the two PowerContext adapters have separate settings, Scope types, and lifecycle behavior.Minimum use
The example assumes your application already owns an initialized chat model and its normal agent or model-call loop. PowerContext supplies middleware; it does not choose or create that model. Verify Scope and recall first with the focused middleware tests or a model-free fake, then place the middleware around the real call.invoke and stream in a synchronous application, and ainvoke and astream in an async application.
Execution flow
ModelRequest.system_message. It never writes the recalled block to framework state or a checkpointer. The existing system message remains first; the untrusted context block is appended for that one request.
Capture is opt-in
Enable capture only after deciding that user and final model content may be stored durably:auto_capture defaults to False. after_agent or aafter_agent captures only after successful completion, using the latest non-empty user message plus either a serializable structured_response or the final non-empty assistant response.
The combined Source payload has a separate 200,000 Python-character ceiling. The adapter divides the available budget between user and assistant text and records truncation flags.
Capture creates a Source. It does not create or approve Memory, and the middleware does not flush. Server extraction may run later through the scheduler or an explicit Client operation, and may produce a no-op.
Scope and configuration
PassPowerContextScope on each invocation when one agent serves more than one tenant. Per-invocation values for Scope, base URL, token, and timeout override environment values.
Scope precedence is:
Bearer . The adapter does not strictly validate that syntax. The shared PowerContextClient rejects plaintext HTTP to non-loopback hosts unless the caller supplies an explicitly trusted transport.
Failure, privacy, and Scope boundary
Automatic recall and capture are independent fail-open paths. Missing Scope, malformed configuration, request validation, authentication failures, timeouts, Server failures, or an unserializable structured response do not replace the model result or abort the host run. HTTP 401/403 is logged as configuration trouble, not treated as empty Memory. The middleware does not add explicit PowerContext tools. If the application wraps Python Client mutations as its own tools, their failure contract and permissions belong to the application; automatic fail-open behavior does not make those mutations successful. Capture can store ordinary prompts, code, business data, and final model output. This adapter does not promise complete secret redaction. Keepauto_capture=False until the application has content filtering, consent, retention, and deletion rules. Tool output is excluded, but that alone is not a privacy policy.
Compare with LangGraph
The difference is where recall lives. Pick the lifecycle already owned by your application rather than wrapping one framework to imitate the other.Currently unsupported or not validated
Completion checklist
- The Server runs separately, and the source-installed middleware is pinned to a reviewed commit.
- Sync code runs outside an event loop; async code uses
ainvokeorastream. - A captured model request contains the untrusted recall block, while returned and checkpointed state does not.
- Tests expect recall before every model request, not once per run or once per turn.
- Every invocation receives the intended Scope; a cross-Scope negative test proves tenant isolation.
MAX_BYTESis between 512 and 32,768, queries over 8,192 characters are expected to be clamped, and remote transport uses HTTPS.- With the Server unavailable, the model flow continues and 401/403 remains distinguishable from empty Memory.
auto_captureremains off unless completed-turn storage has an explicit privacy and retention policy.- When capture is enabled, checks inspect Source rather than assuming Memory or flush.
- Unsupported and Not validated items remain distinct in deployment notes.
Seed one explicit Memory, inspect a model request, and inspect framework state. Enable capture only in a separate run, then verify the Source journal and the absence of an automatic flush.

