[ CrewAI integration guide ]

CrewAI Context Compression with Source Provenance

Install the Maha CrewAI adapter, compile over-budget research inputs, and preserve a source-linked Context Pack for downstream agent work.

Published August 8, 2026 · Maha Strategies LLC

Published cohort

250

Independently annotated QASPER questions

Mean reduction

74.4%

Fixed-budget MCRB-1 result

Complete evidence

62.8%

Not a guarantee for a new workload

Install the maintained adapter

pip install 'maha-sdk[crewai]'

The optional extra installs CrewAI support without forcing the framework into the base SDK. The adapter exposes maha_compress_context, maha_verify_claim, and maha_credit_balance. Payment is not autonomous: depleted prepaid credits raise a typed error and require human authorization.

Give the researcher a bounded compression tool

import os
from crewai import Agent, Crew, Task
from maha_sdk import MahaClient
from maha_sdk.crewai import maha_tools

client = MahaClient(api_key=os.environ["MAHA_API_KEY"])
researcher = Agent(
    role="Evidence researcher",
    goal="Answer from source-linked passages within a fixed token budget",
    backstory="Cite retained source passages and state missing evidence.",
    tools=maha_tools(client),
)

task = Task(
    description=(
        "Use maha_compress_context on the supplied documents with a 4000-token "
        "budget. Report the retained evidence and do not invent missing sources."
    ),
    expected_output="A concise answer with source and passage references.",
    agent=researcher,
)

result = Crew(agents=[researcher], tasks=[task]).kickoff(inputs={
    "documents": documents,
})

Production boundary

The current CrewAI tool returns the compiled context string for agent ergonomics. If your workflow must programmatically validate every passage hash or reject unrecognized citations, call MahaClient.compress() directly and retain the full Context Pack object before giving pack.context to the agent.

MCRB-1 measured 62.8% complete evidence-set retention at 74.4% mean reduction. That result describes the frozen benchmark cohort; measure your own documents before setting an automated acceptance threshold.