InMemory.layer keeps conversations and attached-subagent reservations in one
application Scope. It is useful for trying an agent, local sessions, and work that
can end with the process. No storage package is required.
import{
importAgentRuntime
AgentRuntime,
importInMemory
InMemory }from"@yielded/agent";
import{
importEffect
Effect }from"effect";
import{
constplanner:Definition<String,Struct<{
readonlyitinerary:$Array<String>;
}>,"Plan a trip with one itinerary entry per day.",Toolkit<{}>,undefined,undefined,undefined>&{
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Provides dependencies to an effect using layers or a context. A layer already
built by an enclosing provide or runtime is reused. Sibling provide calls
build their own copies. Use options.local to build a fresh layer subtree.
Run agents and attached subagents with in-memory conversation history.
Provide once around the parent program and all child handler Layers so siblings
share history and one reservation ledger. Reuse a Thread ID to continue a conversation.
Each parent Run releases its reservation pool after its attached children finish cleanup.
Conversations have no per-Thread history quota; individual messages and total host memory are bounded.
Use scoped for disposable request workflows within this shared store.
Each independent Layer build owns fresh state; state is released when its Scope closes.
Process loss loses history and active execution; this Layer provides no crash recovery.
Models, tool handlers, and provider clients remain application-supplied. Default
IDs need no Layer; enclosing ID and context-preparation overrides are preserved.
For storage-backed history, provide PersistentHistory.layer and a shared
SubagentReservationsMemoryLive instead. Durable hosts own their own assembly.
layer));
Supply the agent’s model and tool services around this program. The
runnable planner
contains the complete setup.
Provide the Layer once around the conversation, or acquire it in one
ManagedRuntime shared by your request handlers. Rebuilding it creates separate
state. Save the returned Thread ID for follow-ups; omitting it starts a new Thread.
Complete history updates remain available if a later step fails or is interrupted.
Closing the Scope or losing the process discards everything. No interrupted Run
can recover after process loss.
Built-in conversation limit
Maximum
Threads per store
256
Encoded content per message
4 MiB
Encoded content across the store
64 MiB
These bounds protect individual messages and host memory; a Thread has no quota on message count
or total content. Exceeding one fails with ThreadLimitExceeded.
@yielded/agent-storage-memory implements canonical Thread, Submission, and settlement
ports for tests and custom runtimes. Its ledger is explicitly non-durable. These
ports are separate from the conversation store supplied by InMemory.layer and
must share one storage owner when composed.