How contextweaver Fits

May 27, 2026 · View on GitHub

Where does contextweaver sit relative to my agent runtime, my LLM provider, and my tool catalog? What does it own, and what does it deliberately leave to the rest of the stack? This page is the orientation map.

In a hurry? Which pattern fits my use case? is a symptom-based decision tree that lands each branch on one concrete next step.

Positioning — policy vs. execution

contextweaver is a policy layer. It decides what tools to expose, what context to compile, and what to compact. It never executes tools, never calls LLMs, and never carries transport or auth.

Runtimes are the execution layer. FastMCP, LangChain, LangGraph, LlamaIndex, the OpenAI Agents SDK, Google's ADK / Vertex AI Agent Builder, and Pipecat all sit on the outside, driving the agent loop, invoking tools, and talking to model providers. contextweaver sits inside that loop and is composed in, not composed over.

Boundary diagram

┌──────────────────────────────────────────────────────────────┐
│ Runtime (FastMCP / LangChain / LangGraph / LlamaIndex / ADK /│
│          Pipecat / your custom loop)                          │
│                                                              │
│  ┌────────────────────────────────────────────────────────┐  │
│  │ contextweaver — policy layer                           │  │
│  │                                                        │  │
│  │   Router.route(query)            → RouteResult         │  │
│  │     └─ ContextManager.build_route_prompt → ChoiceCards │  │
│  │   ContextManager.build(phase, q) → ContextPack         │  │
│  │   Firewall (in ingest_tool_result) → summarised events │  │
│  │                                                        │  │
│  └────────────────────────────────────────────────────────┘  │
│                       ↕ plain callables / protocol objects   │
│                                                              │
│  Tool execution, LLM calls, transport, auth, streaming       │
└──────────────────────────────────────────────────────────────┘

The runtime hands events to contextweaver and receives back compact RouteResults, ContextPacks, and (when assembled via ContextManager.build_route_prompt() / contextweaver.routing.cards.make_choice_cards()) ChoiceCards. contextweaver never reaches outward.

Interop matrix

RuntimeHook typecontextweaver component usedGuide / exampleStatus
MCP serversAdapter (dict → SelectableItem)adapters.mcp + Router + ContextManagerMCP Integration, examples/mcp_adapter_demo.pyAvailable
A2A peersAdapter (agent card → SelectableItem)adapters.a2a + Router + ContextManagerA2A Integration, examples/a2a_adapter_demo.pyAvailable
FastMCPAdapter (FastMCP tool list → Catalog)adapters.fastmcp + RouterFastMCP cookbook recipe, examples/fastmcp_adapter_demo.pyAvailable
FastMCP CodeModeCustom discovery toolRouterFastMCP CodeMode adapterPlanned (#87)
LlamaIndexAgent subclass / tool callbackContextManager + RouterLlamaIndex IntegrationAvailable
LangChainCallback handler / memory replacementContextManager (+ Router)LangChain + LangGraph Integration, examples/langchain_memory_demo.pyAvailable
LangGraphState nodeContextManager + RouterLangChain + LangGraph IntegrationAvailable
OpenAI Agents SDKFunction wrapper / pre-call hookRouter + FirewallOpenAI ADK IntegrationAvailable
Google ADK / Vertex AITool list filter / pre-call hookRouter + FirewallGoogle ADK IntegrationAvailable
PipecatFrame processorContextManager (async)Pipecat IntegrationAvailable
CrewAIAdapter (BaseToolSelectableItem)adapters.crewai + Router + FirewallCrewAI Integration, examples/crewai_adapter_demo.pyAvailable
Pydantic AIAdapter (ToolSelectableItem, ModelMessage round-trip)adapters.pydantic_ai + Router + ContextManagerPydantic AI Integration, examples/pydantic_ai_adapter_demo.pyAvailable
smolagentsAdapter (ToolSelectableItem, step-log ingest)adapters.smolagents + Router + ContextManagersmolagents Integration, examples/smolagents_adapter_demo.pyAvailable
AgnoAdapter (Function / ToolkitSelectableItem, session ingest)adapters.agno + Router + ContextManagerAgno Integration, examples/agno_adapter_demo.pyAvailable
Mem0 (external memory)EpisodicStore / FactStore backendextras.memory.mem0External MemoryAvailable
Zep / Graphiti (external memory)EpisodicStore / FactStore backendextras.memory.zep (planned)External MemoryPlanned (#195)
LangMem (external memory)EpisodicStore / FactStore backendextras.memory.langmem (planned)External MemoryPlanned (#195)
MCP Proxy / GatewayStandalone serverFull pipelinePlanned (#13, #28, v1.0)

If your runtime is not listed, the bring-your-own-tools cookbook recipe is the canonical pattern — register Python callables as SelectableItems and drive the loop yourself.

Minimal integration patterns

You do not have to adopt every contextweaver feature at once. Each of these patterns is independently useful and composes cleanly with the others.

Just routing — bounded tool shortlists

from contextweaver.routing.catalog import Catalog
from contextweaver.routing.router import Router
from contextweaver.routing.tree import TreeBuilder

catalog = Catalog()
for item in my_tools:
    catalog.register(item)

graph = TreeBuilder().build(catalog.all())
router = Router(graph, items=catalog.all(), top_k=5)
result = router.route("send a reminder email about unpaid invoices")
shortlist_ids = result.candidate_ids   # feed these into your existing loop

Just firewall — keep large tool outputs out of the prompt

from contextweaver.context.manager import ContextManager

mgr = ContextManager()
item, envelope = mgr.ingest_tool_result_sync(
    tool_call_id="tc-001",
    raw_output=large_tool_response_text,
    tool_name="search_database",
    firewall_threshold=2000,
)
# item.text now holds a compact summary;
# the raw bytes live in mgr.artifact_store under item.artifact_ref.handle.

Full pipeline — phase-specific compiled context

from contextweaver.context.manager import ContextManager
from contextweaver.types import ContextItem, ItemKind, Phase

mgr = ContextManager()
mgr.ingest_sync(ContextItem(id="u1", kind=ItemKind.user_turn, text="user query"))
# ... (tool call / tool result ingestion) ...
pack = mgr.build_sync(phase=Phase.answer, query="user query")
prompt = pack.prompt          # send to your LLM
stats = pack.stats            # BuildStats — what was kept, dropped, why

Non-goals

These are deliberate scope boundaries. Use your runtime for them.

  • Tool execution. contextweaver never invokes a tool. Your runtime — or your own code — calls the tool and feeds the raw output back via ingest_tool_result().
  • LLM orchestration. contextweaver does not call models, manage function-calling loops, or stream tokens. You drive the loop; we hand you a budgeted prompt.
  • Transport and authentication. MCP transports, HTTP, gRPC, OAuth, service accounts — all belong to the runtime. contextweaver consumes already-authenticated tool definitions and results.
  • Schema validation. contextweaver preserves args_schema / output_schema on SelectableItem and ResultEnvelope but does not validate them. Use the runtime's validator (or pydantic / jsonschema) before invoking a tool.
  • Persistence. Stores are pluggable, and v0.3 ships only in-memory implementations. Durable stores (SQLite, Redis, S3) are on the roadmap (#41, #42, #174); until then, persist event_log.to_dict() and friends yourself.

See also