Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build: deps

dev-build: deps
@echo "$(OK_COLOR)==> Building the application for Linux...$(NO_COLOR)"
@GOOS=linux go build -v -ldflags="-s -w -X main.Version=$(or $(tag),dev-$(shell git describe --tags --abbrev=0))" -o "$(BUILD_DIR)/$(NAME)" "$(BUILD_SRC)"
@GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc go build -v -ldflags="-s -w -X main.Version=$(or $(tag),dev-$(shell git describe --tags --abbrev=0))" -o "$(BUILD_DIR)/$(NAME)" "$(BUILD_SRC)"

clean:
@rm -rf ./bin
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Kdeps is loaded with features to streamline AI app development:
- 🔄 Use [reusable AI agents](https://kdeps.com/getting-started/resources/remix.html) for flexible workflows.
- 🖥️ Run [shell scripts](https://kdeps.com/getting-started/resources/exec.html) seamlessly.
- 🌍 Make [API calls](https://kdeps.com/getting-started/resources/client.html) directly from configuration.
- 💾 Manage state with [memory operations](https://kdeps.com/getting-started/resources/memory.html) to store, retrieve, and clear persistent data.
- 📊 Generate [structured outputs](https://kdeps.com/getting-started/resources/llm.html#chat-block) from LLMs.
- 📦 Install [Ubuntu packages](https://kdeps.com/getting-started/configuration/workflow.html#ubuntu-packages) via configuration.
- 📜 Define [Ubuntu repositories or PPAs](https://kdeps.com/getting-started/configuration/workflow.html#ubuntu-repositories).
Expand Down
6 changes: 6 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export default defineConfig({
text: "Data Folder",
link: "/getting-started/resources/global-functions#data-folder-functions",
},
{
text: "Memory Operations",
link: "/getting-started/resources/global-functions#memory-operation-functions",
},
{
text: "JSON Document Parser",
link: "/getting-started/resources/global-functions#document-json-parsers",
Expand Down Expand Up @@ -211,6 +215,8 @@ export default defineConfig({
text: "Preflight Validations",
link: "/getting-started/resources/validations",
},
{ text: "Memory Operations", link: "/getting-started/resources/memory" },
{ text: "Expr Block", link: "/getting-started/resources/expr" },
{ text: "Data Folder", link: "/getting-started/resources/data" },
{ text: "File Uploads", link: "/getting-started/tutorials/files" },
{
Expand Down
45 changes: 45 additions & 0 deletions docs/getting-started/resources/expr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
outline: deep
---

# Expr Block

The `expr` is resource block for evaluating standard PKL expressions. It is primarily used to execute
expressions that produce side effects, such as updating resources or triggering actions, but also supports
general-purpose evaluation of any valid PKL expression, making it a versatile tool for inline logic and scripting within
a configuration.

## Overview of the `expr` Block

The `expr` block is designed to evaluate PKL expressions in a straightforward manner. Its key uses include:

- **Side-Effecting Operations**: Executing functions like `memory.setItem` that modify resources or state without
returning significant values.

- **Inline Scripting**: Evaluating arbitrary PKL expressions to implement logic, assignments, or procedural tasks
directly within a configuration.

The `expr` block simplifies the execution of side-effecting operations that does not makes sense to output it's results.

## Syntax and Usage

The `expr` block is defined as follows:

```apl
expr {
// Valid PKL expression(s)
}
```

Each expression within the block is evaluated in sequence, allowing multiple expressions to form a procedural sequence if needed.

The `expr` block is well-suited for operations that update state, such as setting memory items.

```apl
expr {
"@(memory.setItem("status", "active"))"
}
```

In this example, the memory store is updated to indicate an active status. The `memory.setItem` function is executed as
a side effect, and no return value is required. This also applies to `memory.clear()`.
12 changes: 12 additions & 0 deletions docs/getting-started/resources/global-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ Below is a list of the global functions available for each resource:
| request.path() | Retrieves the URI path of the API request. |
| request.method() | Retrieves the HTTP method (e.g., GET, POST) of the API request. |

## Memory Operation Functions

| **Function** | **Description** |
|:-------------------------------|:----------------------------------------------------------|
| memory.getItem("key") | Fetches the value of key from persistent AI Agent memory |
| memory.setItem("key", "value") | Stores the value of key to the persistent AI Agent memory |
| memory.clear() | Clears all persistent memory (CAUTION!) |

> *Note:* The `setItem` and `clear` are side-effecting functions—it performs an action but doesn't return a
> meaningful value. That is why it is recommended to placed them inside an `expr` block: to ensure the expression is
> evaluated for its effect.

## Data Folder Functions

| **Function** | **Description** |
Expand Down
78 changes: 78 additions & 0 deletions docs/getting-started/resources/memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
outline: deep
---

# Memory Operations

Memory operations provide a way to store, retrieve, and clear key-value pairs in a persistent memory store. These
operations are useful for managing state or caching data across different executions or sessions.

The memory operations include `getItem`, `setItem`, and `clear`, which allow you to interact with the memory store
efficiently.

## Memory Operation Functions

Below are the available memory operation functions, their purposes, and how to use them.

### `getItem(id: String): String`

Retrieves the textual content of a memory item by its identifier.

- **Parameters**:
- `id`: The identifier of the memory item.
- **Returns**: The textual content of the memory entry, or an empty string if not found.

#### Example: Retrieving a Stored Value

```apl
local taskContext = "@(memory.getItem("task_123_context"))"
```

In this example, the `getItem` function retrieves the `task_123_context` record item.
> **Note:** Because Apple PKL uses late binding, the taskContext expression won’t be evaluated until it is actually
> accessed—for example, when included in a response output or passed into an LLM prompt.

### `setItem(id: String, value: String): String`

Sets or updates a memory item with a new value.

- **Parameters**:
- `id`: The identifier of the memory item.
- `value`: The value to store.
- **Returns**: The set value as confirmation.

#### Example: Storing a Value

```apl
expr {
taskId = "task_123"
result = "completed_successfully"
"@(memory.setItem(taskId, result))"
}
```

In this example, `memory.setItem` stores the value `"completed_successfully"` under the key `"task_123"` in memory.

We use the `exp`r block because `setItem` is a side-effecting function—it performs an action but doesn't return a
meaningful value. That is why it's placed inside an `expr` block: to ensure the expression is evaluated for its effect
rather than for a result that would otherwise be ignored.

### `clear(): String`

Clears all memory items in the store.

- **Returns**: A confirmation message.

#### Example: Resetting All Stored Data

```apl
clear()
```

This example clears all memory items, resetting the memory store to an empty state. A confirmation message is returned.

## Notes

- The `getItem` and `setItem` functions operate on string-based key-value pairs.
- The `clear` function removes all stored items, so use it cautiously to avoid unintended data loss.
- Memory operations are synchronous and return immediately with the result or confirmation.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Kdeps is loaded with features to streamline AI app development:
- 🔄 Use [reusable AI agents](/getting-started/resources/remix.md) for flexible workflows.
- 🖥️ Run [shell scripts](/getting-started/resources/exec.md) seamlessly.
- 🌍 Make [API calls](/getting-started/resources/client.md) directly from configuration.
- 💾 Manage state with [memory operations](/getting-started/resources/memory.md) to store, retrieve, and clear persistent data.
- 📊 Generate [structured outputs](/getting-started/resources/llm.md#chat-block) from LLMs.
- 📦 Install [Ubuntu packages](/getting-started/configuration/workflow.md#ubuntu-packages) via configuration.
- 📜 Define [Ubuntu repositories or PPAs](/getting-started/configuration/workflow.md#ubuntu-repositories).
Expand Down
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ require (
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/kdeps/kartographer v0.0.0-20240808015651-b2afd5d97715
github.com/kdeps/schema v0.2.20
github.com/kdeps/schema v0.2.23
github.com/kr/pretty v0.3.1
github.com/mattn/go-sqlite3 v1.14.28
github.com/spf13/afero v1.14.0
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
Expand All @@ -39,11 +40,11 @@ require (
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/catppuccin/go v0.3.0 // indirect
github.com/charmbracelet/bubbles v0.21.0 // indirect
github.com/charmbracelet/bubbletea v1.3.4 // indirect
github.com/charmbracelet/bubbletea v1.3.5 // indirect
github.com/charmbracelet/colorprofile v0.3.1 // indirect
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/ansi v0.9.2 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20250424195755-e256bf9b4ee5 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20250505150409-97991a1f17d1 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/cucumber/gherkin/go/v26 v26.2.0 // indirect
Expand Down Expand Up @@ -104,13 +105,13 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
golang.org/x/arch v0.16.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/arch v0.17.0 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
Expand Down
Loading
Loading