Skip to main content

Adaptive Context Protocol - Multi-resolution data serialization for token-efficient LLM communication

Project description

ACP Protocol

Adaptive Context Protocol - Multi-resolution data serialization for token-efficient LLM communication.

PyPI version License: MIT Python 3.10+

What is ACP?

ACP enables data sources to serve information at multiple resolution levels, dramatically reducing token consumption when communicating with LLMs.

Level Name Description Typical Tokens
L0 Existence Boolean presence check 1-3
L1 Summary Natural language one-liner 10-30
L2 Key Facts Structured essential fields 50-150
L3 Full Detail Complete data Unbounded

Results: 88-96% token reduction vs JSON for typical workloads.

Installation

pip install adaptive-context-resolution

With optional dependencies:

pip install adaptive-context-resolution[tiktoken]  # Accurate token counting
pip install adaptive-context-resolution[llm]       # LLM-assisted summaries

Quick Start

from acp import ACPDocument, ResolutionLevel

# Your data
user = {
    "id": "user-123",
    "name": "Alice Chen",
    "email": "alice@example.com",
    "role": "Senior Engineer",
    "department": "Platform",
    "status": "active",
    "skills": ["Python", "Go", "Kubernetes"],
    "preferences": {"theme": "dark", "notifications": True}
}

# Create ACP document (auto-generates all levels)
doc = ACPDocument.from_dict(user, entity="user", id="user-123")

# Get data at different resolutions
doc.get(level=ResolutionLevel.L0_EXISTENCE)  # "exists"
doc.get(level=ResolutionLevel.L1_SUMMARY)    # "Alice Chen, Senior Engineer, Platform, active"
doc.get(level=ResolutionLevel.L2_KEY_FACTS)  # {"name": "Alice Chen", "role": "Senior Engineer", ...}
doc.get(level=ResolutionLevel.L3_FULL)       # Full data

# Or specify a token budget
doc.get(token_budget=50)  # Returns highest level that fits

Token Counts

print(doc.token_counts)
# {'L0': 1, 'L1': 12, 'L2': 45, 'L3': 180}

Custom Level Generation

# Specify which fields matter for L2
doc = ACPDocument.from_dict(
    data=user,
    entity="user",
    id="user-123",
    key_fields=["name", "role", "email"],
    summary_template="{name} <{email}>"
)

MCP Integration

from acp.mcp import ACPServer, acp_resource

server = ACPServer()

@server.resource("user", key_fields=["name", "role"])
def get_user(user_id: str) -> dict:
    return database.get_user(user_id)

# Handle requests with resolution control
result = server.handle_request(
    "user",
    {"user_id": "123"},
    level=ResolutionLevel.L2_KEY_FACTS
)

ACP Format Output

print(doc.to_acp_format())
@acp 1.0
@entity: user
@id: user-123

L0: exists

L1: "Alice Chen, Senior Engineer, Platform, active"

L2:
  name: Alice Chen
  role: Senior Engineer
  department: Platform
  status: active

L3:
  {"id": "user-123", "name": "Alice Chen", ...}

@meta:
  tokens: {L0: 1, L1: 12, L2: 45, L3: 180}

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please read our contributing guidelines.

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

adaptive_context_resolution-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

adaptive_context_resolution-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file adaptive_context_resolution-0.1.0.tar.gz.

File metadata

File hashes

Hashes for adaptive_context_resolution-0.1.0.tar.gz
Algorithm Hash digest
SHA256 174d186de93788d7906bc613c4d0e765e899a010e85753cf0c2d7f3e3f0fe010
MD5 2ff75cc250465610f0cd9fe16381f301
BLAKE2b-256 fdc8d39c6b0e94dc2a003c748b12fa9f23c4538aea19e08304ed3ea937639b39

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_context_resolution-0.1.0.tar.gz:

Publisher: publish.yml on bhansa/acp-protocol

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

File details

Details for the file adaptive_context_resolution-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for adaptive_context_resolution-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04d261329bfa63a6244d1cd8ab44fc1c09a7179eba787b6e155fe76a87ddbe1f
MD5 3d46f106b24b1082809643035349c9c3
BLAKE2b-256 b3adf3db9ec026276a62e37cf6d8fe46a4ba45fd139c873e8194a83fcfbb87b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for adaptive_context_resolution-0.1.0-py3-none-any.whl:

Publisher: publish.yml on bhansa/acp-protocol

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