Skip to content
Open
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
104 changes: 104 additions & 0 deletions src/app/docs/kagent/concepts/agent-memory/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: "Agent Memory"
pageOrder: 5
description: "Enable vector-backed long-term memory for agents to learn from past interactions."
---

export const metadata = {
title: "Agent Memory",
description: "Enable vector-backed long-term memory for agents to learn from past interactions.",
author: "kagent.dev"
};

# Agent Memory

kagent provides long-term memory for agents using vector similarity search. Agents can automatically save and retrieve relevant context across conversations.

## Overview

Memory in kagent is:
- **Vector-backed** — Uses embedding models to encode memories as 768-dimensional vectors
- **Searchable** — Retrieves relevant memories via cosine similarity
- **Automatic** — Extracts and saves memories periodically without explicit user action
- **Time-bounded** — Memories expire after a configurable TTL (default 15 days)

## Supported Storage Backends

| Backend | Description |
|---------|-------------|
| **pgvector** (PostgreSQL) | Full-featured vector search using the pgvector extension |
| **Turso/libSQL** (SQLite) | Lightweight alternative using SQLite-compatible storage |

## Configuration

### Enable Memory on an Agent

```yaml
apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
name: memory-agent
spec:
type: Declarative
declarative:
modelConfig: default-model-config
systemMessage: "You are a helpful assistant with long-term memory."
memory:
enabled: true
embeddingProvider:
type: OpenAI
model: text-embedding-3-small
```

### Memory with Separate Embedding Provider

```yaml
memory:
enabled: true
embeddingProvider:
type: OpenAI
model: text-embedding-3-small
secretRef:
name: openai-embedding-key
```

## How Memory Works

### Automatic Save Cycle

1. The agent processes user messages normally
2. Every 5th user message, the agent automatically extracts key information
3. Extracted memories are summarized and encoded as embedding vectors
4. Vectors are stored in the database with metadata and timestamps

### Memory Retrieval (Prefetch)

Before generating a response, the agent:
1. Encodes the current user message as an embedding vector
2. Searches stored memories by cosine similarity
3. Injects the most relevant memories into the agent's context

### Memory Tools

When memory is enabled, three tools are injected into the agent:

| Tool | Description |
|------|-------------|
| `save_memory` | Explicitly save a piece of information |
| `load_memory` | Search for relevant memories by query |
| `prefetch_memory` | Automatically run before response generation |

## Memory Management via API

```
GET /api/memories/{agentId} # List memories
DELETE /api/memories/{agentId} # Clear all memories
DELETE /api/memories/{agentId}/{id} # Delete specific memory
```

## Technical Details

- Embedding vectors are normalized to 768 dimensions
- Background TTL pruning runs periodically (default retention: 15 days)
- Memory is per-agent — each agent has its own isolated memory store
- Memories include timestamps and source session references
57 changes: 57 additions & 0 deletions src/app/docs/kagent/concepts/context-management/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "Context Management"
pageOrder: 9
description: "Automatically summarize older messages to stay within LLM context windows during long conversations."
---

export const metadata = {
title: "Context Management",
description: "Automatically summarize older messages to stay within LLM context windows during long conversations.",
author: "kagent.dev"
};

# Context Management

Long conversations can exceed LLM context windows. kagent provides **event compaction** to automatically summarize older messages, preserving key information while reducing token count.

## Configuration

```yaml
apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
name: long-conversation-agent
spec:
type: Declarative
declarative:
modelConfig: default-model-config
systemMessage: "You are a helpful agent for extended sessions."
context:
eventsCompaction:
enabled: true
```

## How It Works

1. As the conversation progresses, events accumulate in the session history
2. When the history approaches the model's context limit, compaction triggers
3. Older events are summarized while preserving:
- Key decisions and outcomes
- Important tool results
- Critical context from earlier in the conversation
4. The agent continues with the compacted history seamlessly

## When to Use

Enable event compaction when:
- Agents handle long-running conversations (debugging sessions, investigations)
- Agents call many tools that generate large outputs
- You want to support extended interactions without hitting context limits

You may not need it for:
- Short, single-turn interactions
- Agents with small tool sets that generate compact outputs

## Context Caching Note

Prompt caching (a separate optimization that caches the prompt prefix for faster responses) is **not** configured at the agent level. Most LLM providers enable prompt caching by default.
137 changes: 137 additions & 0 deletions src/app/docs/kagent/concepts/git-based-skills/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
title: "Git-Based Skills"
pageOrder: 8
description: "Load markdown knowledge documents from Git repositories to guide agent behavior."
---

export const metadata = {
title: "Git-Based Skills",
description: "Load markdown knowledge documents from Git repositories to guide agent behavior.",
author: "kagent.dev"
};

# Git-Based Skills

Skills are markdown-based knowledge documents that agents load at startup. They provide domain-specific instructions, best practices, and procedures that guide agent behavior.

kagent supports two sources for skills:
- **OCI images** — Container images containing skill files (original approach)
- **Git repositories** — Clone skills directly from Git repos

## Skill File Format

Each skill is a directory containing a `SKILL.md` file with YAML frontmatter:

```markdown
---
name: kubernetes-troubleshooting
description: Guide for diagnosing and fixing common Kubernetes issues
---

# Kubernetes Troubleshooting

## Pod Crash Loops

When a pod is in CrashLoopBackOff:

1. Check logs: `kubectl logs <pod> --previous`
2. Check events: `kubectl describe pod <pod>`
3. Verify resource limits...
```

## Git Repository Configuration

### Basic Example

```yaml
apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
name: my-agent
spec:
type: Declarative
declarative:
modelConfig: default-model-config
systemMessage: "You are a helpful agent."
skills:
gitRefs:
- url: https://github.com/myorg/agent-skills.git
ref: main
```

### With Subdirectory

```yaml
skills:
gitRefs:
- url: https://github.com/myorg/monorepo.git
ref: main
path: skills/kubernetes
```

### Multiple Sources

Combine Git and OCI skills:

```yaml
skills:
refs:
- image: ghcr.io/myorg/k8s-skills:latest
gitRefs:
- url: https://github.com/myorg/skills-repo.git
ref: main
- url: https://github.com/myorg/another-repo.git
ref: develop
path: agent-skills
```

## Authentication

### HTTPS Token Auth

```yaml
apiVersion: v1
kind: Secret
metadata:
name: git-credentials
type: Opaque
stringData:
token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

```yaml
skills:
gitAuthSecretRef:
name: git-credentials
gitRefs:
- url: https://github.com/myorg/private-skills.git
ref: main
```

### SSH Key Auth

```yaml
skills:
gitAuthSecretRef:
name: git-ssh-key
gitRefs:
- url: git@github.com:myorg/private-skills.git
ref: main
```

> A single `gitAuthSecretRef` applies to all Git repositories in the agent. All repos must use the same authentication method.

## How It Works

Under the hood, kagent uses a lightweight init container (~30MB) containing Git and krane tools:

1. Before the agent pod starts, the `skills-init` container runs
2. It clones each Git repository to the skills volume
3. It also pulls any OCI skill images
4. The agent runtime discovers skills from the mounted volume at startup

## Skill Discovery at Runtime

Once loaded, skills are available through the built-in `SkillsTool`:
- **List skills:** The agent calls the tool with no arguments to see available skills
- **Load skill:** The agent calls the tool with a skill name to get the full content
Loading