Skip to main content

POPMiddleware for LangChain agents.

Project description

CI PyPI version Python versions License

langchain-pop

langchain-pop is a preview middleware package that brings portable persona objects into LangChain agent runtimes.

It allows POP persona objects to be loaded into LangChain, injected as runtime persona framing, and enforced through boundary-aware tool filtering. The package is designed as a middleware and toolkit-style ecosystem integration for the Persona Object Protocol (POP), not as a replacement for LangChain's own agent abstractions.

Status

langchain-pop is an early integration preview.

Current capabilities include:

  • POP v1 canonical object loading
  • legacy pop-0.1 migration
  • persona-aware system prompt construction
  • boundary-based tool filtering
  • LangChain agent construction via create_pop_agent(...)

This package currently demonstrates runtime integration and middleware behavior. It does not yet provide a full interoperability benchmark or production-grade governance system.

Installation

Minimal install

pip install langchain-pop

With OpenAI provider support

pip install "langchain-pop[openai]"

Quick Start

from langchain_openai import ChatOpenAI

from langchain_pop.agent import create_pop_agent


def knowledge_lookup(topic: str) -> str:
    """Look up a topic in a mock knowledge base."""
    return f"Knowledge lookup result for: {topic}"


agent = create_pop_agent(
    pop_source="tests/fixtures/mentor.v1.json",
    model=ChatOpenAI(model="gpt-4o", temperature=0.0),
    tools=[knowledge_lookup],
    name="mentor_agent",
)

print(agent)

To inspect the generated runtime configuration without invoking a live model:

python examples/langchain_middleware_demo.py --print-config

What langchain-pop does

langchain-pop maps a POP persona object into LangChain runtime components:

  • persona role and traits -> system-level runtime framing
  • persona boundaries -> runtime tool filtering
  • POP identity fields -> runtime persona state

This makes persona handling more structured than ad hoc prompt-only role injection and aligns the integration with a toolkit-style runtime workflow instead of a thin adapter layer.

Example: Middleware Preview

from langchain_pop.middleware import POPMiddleware

middleware = POPMiddleware("tests/fixtures/mentor.v1.json")

print(middleware.persona_state())
print(middleware.system_prompt)

Example: Legacy Migration

Legacy pop-0.1 objects are supported through automatic migration:

from langchain_pop.agent import create_pop_agent
from langchain_openai import ChatOpenAI


agent = create_pop_agent(
    pop_source="tests/fixtures/mentor.pop01.json",
    model=ChatOpenAI(model="gpt-4o", temperature=0.0),
    tools=[],
)

Design Scope

langchain-pop is designed as a LangChain ecosystem integration for portable persona objects.

It is not:

  • a full agent framework
  • a replacement for LangChain middleware
  • a production governance framework
  • a complete interoperability standard

Its purpose is to demonstrate that POP persona objects can function as runtime-integrated persona middleware in a real agent stack.

Docs PR Draft

The repository includes a docs-PR-oriented draft page in two forms:

Repository Structure

langchain-pop/
├── src/langchain_pop/
│   ├── __init__.py
│   ├── _pop_compat.py
│   ├── middleware.py
│   └── agent.py
├── tests/
├── examples/
├── docs/
└── README.md

Development

Run tests:

python -m unittest discover -s tests -v

Build distributions:

python -m build

Run demo:

python examples/langchain_middleware_demo.py --print-config

For local editable development:

pip install -e .

Relationship to POP

langchain-pop is an ecosystem integration layer for portable persona objects.

  • persona-object-protocol defines the protocol semantics, schema, examples, and reference tooling.
  • langchain-pop demonstrates how POP persona objects can be consumed inside a real agent runtime.

In other words:

  • POP = protocol layer
  • langchain-pop = runtime integration layer

Maturity

This package should currently be understood as:

  • an early middleware preview
  • a runtime integration proof point
  • a bridge between POP and LangChain agents

It should not yet be interpreted as a final or official LangChain standard component.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_pop-0.1.2.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_pop-0.1.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_pop-0.1.2.tar.gz.

File metadata

  • Download URL: langchain_pop-0.1.2.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_pop-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b0b843e4050398f16e93526b47c4edbea603b84432131976cb6335ce60a0ce6c
MD5 f71a71ed7b155261a8cb202647f04ae5
BLAKE2b-256 ab077df5589b0402532c7ea08bd83bc178ef919f9ce4cdfb3708747bf358afb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_pop-0.1.2.tar.gz:

Publisher: publish.yml on joy7758/langchain-pop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_pop-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: langchain_pop-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_pop-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a52646798016e9de84d5718548d32765627de36e2e517e77081fd45c7019d338
MD5 be6e8bea9e2e442049b594ff2716a20a
BLAKE2b-256 989d01f371525ddf4c793615f9da2cfed8bf5525672959a3a92afd575dcb0b2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_pop-0.1.2-py3-none-any.whl:

Publisher: publish.yml on joy7758/langchain-pop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page