DEV Community

Miodrag Vilotijević
Miodrag Vilotijević

Posted on • Originally published at jigjoy.ai

Structured Context, Context Memory, Context Item Generators, and the Agentic Environment

Mozaik started as a multi-provider library. With version 3.0.0, we are evolving it into a full TypeScript framework for building non-blocking AI agents.

This release introduces an event-based architecture designed around inversion of control. Instead of forcing developers into rigid, sequential pipelines, Mozaik enables humans, agents, observers, and tools to collaborate inside a shared agentic environment. Participants can emit, observe, and react to typed context items in real time, making multi-agent orchestration more flexible, composable, and concurrent.

Structured Context

Mozaik 3 introduces a structured, multi-provider context model compatible with the OpenResponses specification.

Instead of treating prompts as plain strings, Mozaik models context as typed items, including:

  • SystemMessageItem
  • DeveloperMessageItem
  • UserMessageItem
  • FunctionCallItem
  • FunctionCallOutputItem
  • ReasoningItem
  • ModelMessageItem

These context items help developers provide clearer, more precise instructions to language models. For example, combining system, developer, and user messages gives the model a better-organized context than placing everything into a single user message.

This structure also makes model interactions easier to inspect, store, replay, and adapt across providers.

Context Memory

Mozaik now models context as an aggregate of ordered context items through ModelContext.

This gives developers a structured foundation for both short-term working memory and long-term persistence. The framework includes a repository interface, allowing context to be saved and retrieved through different storage backends.

Mozaik provides an in-memory implementation for working memory, while developers can implement their own repositories for file systems, databases, or other persistence layers.

This approach keeps memory explicit, portable, and provider-independent.

Context Item Generators

Mozaik 3 introduces asynchronous context item generators for key parts of the framework, including input handling, inference, and function call execution.

Instead of relying on blocking await chains, runners can produce context items over time through async iterables. This enables items to be generated and delivered in real time while giving developers control over when and how those streams are consumed.

Mozaik provides default implementations for function call execution and OpenAI inference. Developers can also create their own implementations, which is especially useful for testing, mocking runners, customizing tool execution, or adding support for additional model providers.

Agentic Environment

The main goal of Mozaik 3 is to enable AI agents to collaborate in a non-blocking way.

We believe that truly agentic systems should not be limited to sequential chains. In many real-world use cases, agents need to observe, react, and contribute concurrently.

To support this, Mozaik introduces the Participant abstraction and the AgenticEnvironment.

Participants join the same environment and react to typed context items as they arrive.

Participants, including humans and agents, join the same environment and subscribe to context items generated by other participants. When one participant emits a context item, other participants can observe it, react to it, ignore it, or use it to update their own internal context.

or example, a human can send a UserMessageItem into the environment. One or more agents can react by running inference, producing model messages, requesting function calls, or incorporating the new item into their own context. Other agents can observe those outputs and respond with their own contributions.

This enables agents to work in parallel and remain aware of what other participants are doing during inference.

Default Participants

To make multi-agent development faster, Mozaik 3 also includes default participant implementations:

BaseAgentParticipant
BaseHumanParticipant

These base classes provide common capabilities for generating, receiving, and reacting to context items, so developers can set up multi-agent systems with less boilerplate while still keeping full control over the architecture.

A Foundation for Multi-Agent Systems

Mozaik 3 moves beyond simple provider abstraction.

It introduces a framework-level architecture for building reactive, non-blocking, context-aware AI systems. By combining structured context, explicit memory, async context item generation, and a shared agentic environment, Mozaik gives developers the building blocks for more flexible and scalable multi-agent applications.

With version 3.0.0, Mozaik becomes a foundation for building agents that do not just run in sequence, but collaborate through shared context in real time.

Star on GitHub: https://github.com/jigjoy-ai/mozaik

Top comments (0)