crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[FEATURE] Token-efficient serialization for agent communication to reduce context overhead at scale

Open makroumi opened this issue 7 months ago • 5 comments

Feature Area

Agent capabilities

Is your feature request related to a an existing bug? Please link it here.

NA

Describe the solution you'd like

Native support for pluggable serialization in the Crew execution pipeline, with ULMEN as the first alternative to JSON.

ULMEN is a serialization engine built specifically for LLM agent pipelines.

Benchmarks on NVIDIA Tesla T4 production hardware:

  • 44% fewer tokens vs JSON
  • 3x faster deserialization vs orjson
  • 4.1x smaller wire format
  • $59K saved per 10M agent loops on GPT-4o

Beyond compression, a Semantic Firewall validates agent state transitions before they reach the LLM:

  • Rejects orphaned tool calls
  • Catches invalid step transitions
  • Structured errors instead of silent failures

Implementation would be fully opt-in:

crew = Crew( agents=[researcher, writer], tasks=[research_task, write_task], process=Process.sequential, serializer="ulmen" )

Drop-in Python/Rust. No schema compilation. Pure Python fallback if Rust unavailable.

Reproducible benchmark notebook: github.com/makroumi/ulmen

Describe alternatives you've considered

  • orjson: faster than json but identical token count. Doesn't address context window overhead.

  • MessagePack: reduces wire size but not token count. No semantic validation layer.

  • Manual prompt compression: lossy, requires custom logic per use case, not systematic.

ULMEN is the only approach that simultaneously addresses token count, wire size, speed, AND semantic validation in one drop-in library.

Additional context

CrewAI's sequential and hierarchical process patterns are particularly exposed to this problem because:

  1. Each agent receives full task context as JSON
  2. Tool results serialize back as JSON each turn
  3. Key names repeat identically across every turn
  4. A 5-agent crew compounds the overhead 5x

At 10M crew loops the JSON tax is ~$59K on GPT-4o pricing. Not a rounding error.

Silent tool failures passing through JSON undetected are also a leading cause of crew

Image

hallucinations that are difficult to diagnose.

Live benchmark notebook to verify numbers: github.com/makroumi/ulmen

Willingness to Contribute

Yes, I'd be happy to submit a pull request

makroumi avatar Apr 15 '26 15:04 makroumi

The silent tool failure point is underrated. Most people focus on token cost but undetected failures compounding through a crew is the harder problem to debug.

What was the breaking point that made you build a dedicated library for this instead of patching around it?

JackChen-me avatar Apr 16 '26 11:04 JackChen-me

@JackChen-me The breaking point was watching a multi-agent cluster completely derail because a downstream agent received a truncated JSON payload from an upstream tool failure. The JSON was structurally valid enough for the LLM to parse, but semantically broken. The LLM hallucinated the missing context, and we burned 200k tokens before we caught the loop.

You can't fix that with prompt engineering. You have to fix it at the wire level.

Since this was closed as "not planned," I'm wrapping ULMEN into a standalone adapter (ulmen-crewai). It intercepts the Crew execution pipeline dynamically so you can bypass the JSON bloat without needing core framework support. I'll drop the repository link here once it's published.

makroumi avatar Apr 16 '26 18:04 makroumi

Same hole on our side — tool inputs get Zod validation but outputs are raw strings straight to the LLM. Thinking about adding output schema on the tool definition so malformed results become errors before they hit the conversation.

Does ULMEN validate at the tool output level or the crew message passing layer?

JackChen-me avatar Apr 16 '26 18:04 JackChen-me

@JackChen-me Great question. ULMEN validates at the message passing layer (the payload/wire format level), but because of how the format is structured, it inherently protects the tool output boundary.

Zod is fantastic for application-level schema validation (ensuring a tool returns an int instead of a string). But in a multi-agent cluster, corruption is usually an orchestration problem, not just a type problem.

ULMEN acts as a Wire-Level Firewall. Before a payload is sent to the LLM context window (or persisted to the database), ulmen.validate_agent_payload() runs a strict, all-or-nothing validation over the entire conversation subgraph.

If you look at the ULMEN-AGENT v1 schema, it doesn't just check data types; it enforces referential integrity across the state machine. Specifically, it catches:

  • Orphaned Tool Outputs: The validator enforces that every res (tool result) record has a perfectly matching tool (tool call) record ID upstream in the trace. If a tool output arrives out of nowhere, the payload fails validation.

  • Backward Transitions: It enforces that the step integer is monotonically increasing within a thread_id. An agent cannot accidentally revert the state machine to a previous turn.

  • Invalid Status Enums: It restricts fields like tool.status strictly to [pending, running, done, error].

  • Truncated Payloads: The records: N header strictly enforces that the wire format wasn't cut off mid-transmission (which is what caused my 200k token burn).

Zod validates the shape of the data inside the tool. ULMEN validates the semantic integrity of the entire agent execution graph. By validating at the message passing layer, ULMEN drops broken orchestration states before a single LLM token is billed.

makroumi avatar Apr 16 '26 18:04 makroumi

Got it. The records-count header for catching truncation at the wire level is a clean solve for that failure mode.

JackChen-me avatar Apr 16 '26 18:04 JackChen-me