Sergei Pestrikov
02/24/2026, 11:29 AMval stringKey: AIAgentStorageKey<String> = createStorageKey("my_key")
val intKey: AIAgentStorageKey<Int> = createStorageKey("my_key")
// If data class:
storage.set(stringKey, "hello") // stores "hello"
val value: Int? = storage.get(intKey) // returns "hello" cast to Int? → ClassCastException at use site
> In our case it is cumbersome because we have all the subgraphs in different files and the storage keys are created dynamically.
For this use case it's indeed cumbersome. One solution might be to introduce a key registry (cached factory) to manage shared keys between subgraphs from different files. Let me know if it's not an option (I've added an example of the registry AIAgentStorageKeys at the end of this commit).
> However when I debug into it I see different instances of the "context" for every subgraph so the storage is also different. Is this intended?
True, AIAgentSubgraph.execute() creates a copy of the context via context.replace(context.copy(...)). However, context.storage points to the same storage instance in the copy. I've added some tests in a separate branch to demonstrate that.
> Should I always use the parentcontext? Should we use the root context in this case even though it is internal?
parentcontext and root context are not needed for this case. Copied contexts should share the same underlying storage instance.
One more thing: the documentation about AIAgentStorageKey states that "Each key has a name property which is a string identifier that uniquely represents the storage key." That's misleading, sorry about that, the name property in the current implementation doesn't affect key uniqueness. We'll fix the documentation.Chrylo
02/26/2026, 5:42 PMChrylo
02/27/2026, 9:19 AMSergei Pestrikov
02/27/2026, 6:24 PMSo we are restoring conversations, llm messages and stored node outputs for multiple users.A new feature called "ChatMemory" has been merged yesterday into the develop branch. It will allow to run persistent/stateful agents by "agent.run(input, sessionId)" where "sessionId" is a string identifier of a conversation or a user. Let us know if the feature can be useful for your use cases.
Vadim Briliantov
02/27/2026, 7:34 PM