Add application-scoped state API (ctx.app_state)#542
Open
Conversation
Some agents require updating context about users or objects they are
managing. Application State is a way for applications to share state
across request boundaries as they learn about the problem domain.
For example, a fitness tracker agent managing fitness logs of multiple
users can store per-user context in app_state as a flexible K/V store,
which is much more practical than using rigid database schemas for
evolving agent knowledge.
The API mirrors the existing request-scoped ctx.state but persists
across all requests within the same application:
ctx = RequestContext.get()
ctx.app_state.set("key", value) # write
ctx.app_state.get("key") # read from any request
Implementation uses the same 3-phase blob protocol as request state
(prepare_read -> transfer -> commit_write) with a different URI
namespace: {namespace}/{application}/app_state/{key}.
Changes:
- Add ApplicationState abstract class and app_state property on
RequestContext
- Add AllocationAppState for FE-side operation handling
- Add app state proto messages (operations + results) to
function_executor.proto and regenerate stubs
- Add HTTP handlers (base, FE, local) for app state operations
- Add ApplicationStateHTTPClient and wire into RequestContextHTTPClient
- Wire app state into allocation runner and state wrapper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9f5591a to
8493ad1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some agents require updating context about users or objects they are managing. Application State is a way for applications to share state across request boundaries as they learn about the problem domain.
For example, a fitness tracker agent managing fitness logs of multiple users can store per-user context in
app_stateas a flexible K/V store — much more practical than using rigid database schemas for evolving agent knowledge.API
How it works
ctx.statearchitecture at every layerprepare_read→ transfer →commit_write{namespace}/{application}/app_state/{key}(vs{namespace}/{application}/{request_id}/state/{key}for request state)Changes
ApplicationStateclass +app_stateproperty onRequestContextfunction_executor.proto+ regenerated stubsAllocationAppStateclass, wired intoAllocationRunnerandAllocationStateWrapperApplicationStateHTTPClientwired intoRequestContextHTTPClientTest plan