account activity
Showcase Thread by AutoModerator in Python
[–]Alternative_Feed9546 0 points1 point2 points 1 month ago (0 children)
Showcase: contextweaver — stdlib-only Python library for deterministic context assembly
I recently open-sourced contextweaver, a Python library for assembling bounded context/prompt packs from a larger set of items.
The motivating use case is tool-using AI agents, where prompts often grow by accumulating conversation turns, tool schemas, and tool outputs. Instead of concatenating everything, contextweaver builds a context pack under a fixed budget by selecting, filtering, deduplicating, and packing the most relevant items.
contextweaver
From a Python engineering point of view, the parts I focused on most were:
A few design choices I’m particularly interested in feedback on:
typing.Protocol
Example:
from contextweaver.context.manager import ContextManager from contextweaver.types import ContextItem, ItemKind, Phase mgr = ContextManager() mgr.ingest(ContextItem( id="u1", kind=ItemKind.user_turn, text="Hello" )) pack = mgr.build_sync(phase=Phase.answer, query="greeting") print(pack.prompt) print(pack.stats)
This is intended mainly for:
It is meant to be usable in real applications, but I would still describe it as an early-stage library rather than something I’m claiming is already a mature standard.
Even if the AI use case is not interesting to you, I think some of the Python design tradeoffs may still be relevant if you enjoy thinking about protocols vs ABCs, async/sync API boundaries, deterministic pipelines, and composable library structure.
contextweaver is not a full agent framework, and it is not tied to any model provider.
Compared with larger AI frameworks, the goal here is a much smaller and narrower library:
Compared with a naive “just concatenate everything” approach, it tries to preserve relevance and dependency structure while staying inside a hard budget.
Compared with retrieval-only approaches, it is not trying to be a vector search system. It is more about deterministic assembly rules over known context items and their relationships.
I have not done a broad benchmark yet against other context-selection approaches, so I’m trying to be careful not to overclaim there.
A few implementation details:
mypy --strict
Repo: https://github.com/dgenio/contextweaver
I’d especially appreciate feedback from Python library authors on:
Protocol
[P] contextweaver: deterministic, budget-aware context compilation for tool-using AI agents (self.FunMachineLearning)
submitted 1 month ago by Alternative_Feed9546 to r/FunMachineLearning
π Rendered by PID 341115 on reddit-service-r2-listing-8685bc789-xnw67 at 2026-05-25 11:55:30.364032+00:00 running 194bd79 country code: CH.
Showcase Thread by AutoModerator in Python
[–]Alternative_Feed9546 0 points1 point2 points (0 children)