Skip to main content
The Context Facade provides an Eloquent-like fluent API for managing agent contexts, chat histories, and storage operations. It offers two distinct approaches for accessing context data, each suited for different use cases.

Access Methods

The Context Facade provides two entry points, each returning a different manager type:

Context::of()

Full agent access with configuration and callbacks receiving agent instances

Context::named()

Lightweight access using just an agent name string, ideal for admin tools

Choosing the Right Approach

It is recommended to use named() for lightweight access, since it does not require initializing agent instances, works directly with context and drivers - can be more efficient for most of the cases. Use of() only when you need full agent functionality or access to agent-defined configuration.

Using Context::of()

The of() method (aliased as agent()) creates a ContextManager that requires a full agent class. This approach initializes a temporary agent instance internally, giving you access to agent configuration and the ability to work with agent instances in callbacks.
Use of() when you need full agent functionality, want to interact with agents, or when agent configuration matters.

Filter Methods

All filter methods are chainable and create immutable instances (the original instance remains unchanged).

Chaining Multiple Filters

Filters can be chained for complex queries (all filters are AND-ed together):

Query Methods

Iteration Methods

With of(), callbacks receive both the identity and the agent instance:

Action Methods


Using Context::named()

The named() method creates a NamedContextManager using just an agent name string. This lightweight approach doesn’t initialize any agent class—it only works with identities and requires explicit driver configuration.
Use named() for administrative tasks, cleanup scripts, operations outside agent context, or when you don’t need agent functionality.

Driver Configuration

Since named() doesn’t have access to agent configuration, you must specify drivers explicitly:
If withDrivers() is not called, the facade will attempt to use the default drivers from your config/laragent.php configuration.

Filter Methods

The same filter methods are available, but callbacks only receive identities:

Query Methods

After you get needed identity, you can initialize agent instances with it using fromIdentity() method: supportAgent::fromIdentity($identity).

Iteration Methods

With named(), callbacks only receive the identity (no agent instance):

Action Methods

Action methods return counts instead of being chainable:

Additional Methods


Filter Immutability

Filters create new instances, leaving the original unchanged. This allows building reusable query bases:

Common Use Cases

Method Reference

Filter Methods (Both Managers)

Query Methods (Both Managers)

ContextManager Only

NamedContextManager Only