Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/docs/development/memory/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ For more details, see [Sensory & Short-term Memory]({{< ref "docs/development/me
* **Characteristics**:
* The lifecycle of the stored data can across multiple runs.
* Complete original data retrieval.
* Supports optional automatic expiration and cleanup.

For more details, see [Sensory & Short-Term Memory]({{< ref "docs/development/memory/sensory_and_short_term_memory" >}}).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ public static void secondAction(Event event, RunnerContext ctx) throws Exception
{{< /tab >}}

{{< /tabs >}}

## Auto-Cleanup Behavior

### Sensory Memory

Sensory Memory is automatically cleared by the framework after each agent run completes. This cleanup happens:

- **When**: After the agent run finishes processing all events trigger by one input event.
Expand All @@ -263,4 +266,56 @@ Sensory Memory is automatically cleared by the framework after each agent run co

{{< hint info >}}
During execution, sensory memory data is checkpointed by Flink for fault tolerance. However, once the run completes, all sensory memory is cleared and will not be available in subsequent runs.
{{< /hint >}}
{{< /hint >}}

### Short-Term Memory

Short-term memory can be configured with a time-to-live (TTL) so that older state expires automatically. This is useful for agents that may run for a long time: if the agent only needs recent memories, expiring historical data directly keeps the stored state focused on the latest context and avoids retaining stale information.

Set `short-term-memory.state-ttl.ms` to a value greater than 0 in milliseconds to enable TTL. You can also configure how the TTL is refreshed and whether expired state can be returned before Flink cleans it up:

- `short-term-memory.state-ttl.update-type`: controls whether TTL is refreshed on create/write or on read/write.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the prose ("older state expires automatically… expiring historical data") and the two examples use ON_READ_AND_WRITE, the default — under which a read also resets the TTL clock. So an old entry that's still being read periodically won't expire. A reader skimming the intro might take "older" to mean by creation time. Would it be worth one clarifying sentence here — that with ON_READ_AND_WRITE "age" is measured from last access, and ON_CREATE_AND_WRITE is the one that expires by write/creation time? It's okay with me if you'd rather keep it brief.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 'controls whether TTL is refreshed on create/write or on read/write.' already sufficiently explains the above situation, so I don't intend to provide any additional supplements. Thank you for such a prompt reply.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the literals themselves, along with a single line of additional explanation, are sufficient; therefore, I agree with keeping it brief.

- `short-term-memory.state-ttl.visibility`: controls whether expired memory is never returned or may be returned if it has not been cleaned up yet.

{{< tabs "Short-Term Memory TTL Configuration" >}}

{{< tab "Python" >}}
```python
from flink_agents.api.core_options import (
AgentExecutionOptions,
ShortTermMemoryTtlUpdate,
ShortTermMemoryTtlVisibility,
)
from flink_agents.api.execution_environment import AgentsExecutionEnvironment

agents_env = AgentsExecutionEnvironment.get_execution_environment(env=env)
agents_config = agents_env.get_config()

agents_config.set(AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_MS, 60_000)
agents_config.set(
AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_UPDATE_TYPE,
ShortTermMemoryTtlUpdate.ON_READ_AND_WRITE,
)
agents_config.set(
AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_VISIBILITY,
ShortTermMemoryTtlVisibility.NEVER_RETURN_EXPIRED,
)
```
{{< /tab >}}

{{< tab "Java" >}}
```java
AgentsExecutionEnvironment agentsEnv = AgentsExecutionEnvironment.getExecutionEnvironment(env);
AgentConfiguration agentsConfig = (AgentConfiguration) agentsEnv.getConfig();

agentsConfig.set(AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_MS, 60_000L);
agentsConfig.set(
AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_UPDATE_TYPE,
ShortTermMemoryTtlUpdate.ON_READ_AND_WRITE);
agentsConfig.set(
AgentExecutionOptions.SHORT_TERM_MEMORY_STATE_TTL_VISIBILITY,
ShortTermMemoryTtlVisibility.NEVER_RETURN_EXPIRED);
```
{{< /tab >}}

{{< /tabs >}}
4 changes: 3 additions & 1 deletion docs/content/docs/operations/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ Here is the list of all built-in core configuration options.
| `event-log.standard.max-string-length` | 2000 | int | At `STANDARD` level, strings in the event payload longer than this are truncated. Has no effect at `VERBOSE`. |
| `event-log.standard.max-array-elements` | 20 | int | At `STANDARD` level, arrays in the event payload with more than this many elements are truncated. Has no effect at `VERBOSE`. |
| `event-log.standard.max-depth` | 5 | int | At `STANDARD` level, objects nested deeper than this are summarized. Has no effect at `VERBOSE`. |

| `short-term-memory.state-ttl.ms` | 0 | long | Time-to-live for short-term memory state in milliseconds. Set to a value greater than 0 to enable TTL; 0 disables it. |
| `short-term-memory.state-ttl.update-type` | `ON_READ_AND_WRITE` | ShortTermMemoryTtlUpdate | Update policy for short-term memory TTL. Only applies when `short-term-memory.state-ttl.ms` is greater than 0. Valid values: `ON_CREATE_AND_WRITE`, `ON_READ_AND_WRITE`. |
| `short-term-memory.state-ttl.visibility` | `NEVER_RETURN_EXPIRED` | ShortTermMemoryTtlVisibility | Visibility policy for expired short-term memory state. Only applies when `short-term-memory.state-ttl.ms` is greater than 0. Valid values: `NEVER_RETURN_EXPIRED`, `RETURN_EXPIRED_IF_NOT_CLEANED_UP`. |

### Action State Store

Expand Down
Loading