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
76 changes: 76 additions & 0 deletions .agents/skills/agent-toolkit-components/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
name: agent-toolkit-components
description: Connect agent code to the components of an installed Intel® Agent Toolkit. Use when someone says "connect my agent to the toolkit", "give my LangGraph agent a key", "use Redis or pgvector for memory", "run code in a sandbox", "deploy my agent in its own namespace", or reports connection resets, 401s, WRONGPASS, vector dimension errors or sandbox SDK timeouts. Covers the LiteLLM endpoint and per-agent virtual keys, Redis Stack and pgvector memory, Agent Sandbox code execution (Python SDK, ServiceAccount token, RBAC, Kata microVMs), OpenShell policy sandboxes, KubeRay, Langfuse tracing and OpenTelemetry, for LangGraph, CrewAI, the OpenAI SDK or custom agents.
---

# Use the Intel® Agent Toolkit components from agent code

This file is a summary. The exact steps, commands and fixes are in the `references/` file that each table row points to: open that file before you answer.

## 1. See what is installed

```bash
kubectl get ns litellm redis pgvector agent-sandbox-system openshell-system ray-system langfuse --ignore-not-found
```

A component that was never installed has no namespace. One switched off after install keeps running until it is torn down. The switches live in `env/<env>/config.agent-toolkit.yaml`; see the agent-toolkit-configuration skill. `kubectl` must point at the cluster (`export KUBECONFIG=<root>/env/<env>/kubeconfig.yaml`; see `AGENTS.md`).

## 2. Pick endpoints and credentials

| Service | In-cluster endpoint | Credential: Secret (namespace) → key |
|---|---|---|
| LiteLLM (OpenAI API) | `http://litellm.litellm.svc.cluster.local:4000/v1` | Mint a virtual key with `litellm-master-key` (litellm) → `master_key` |
| Redis Stack | `redis-stack-server.redis.svc.cluster.local:6379` | `redis-stack-server-credentials` (redis) → `REDIS_URL` |
| pgvector | `pgvector.pgvector.svc.cluster.local:5432`, db `agentdb` | `pgvector-credentials` (pgvector) → `DATABASE_URL`, `POSTGRES_DSN` |
| Agent Sandbox router | `http://sandbox-router-svc.agent-sandbox-system.svc.cluster.local:8080` | A ServiceAccount token, checked by TokenReview: the pod's own token, or `kubectl create token <sa> -n <ns>` |
| OpenShell gateway | `openshell.openshell-system.svc.cluster.local:8080` (mTLS, through the CLI) | `openshell-client-tls` (openshell-system), full admin |
| Ray | `ray://ray-cluster-head-svc.ray-system.svc.cluster.local:10001` | Dashboard: `ray-dashboard-auth` (ray-system) |
| Langfuse | `http://langfuse-web.langfuse.svc.cluster.local:3000` | `langfuse-api-keys` (litellm) → `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY` |
| OpenTelemetry | `opentelemetry-collector.monitoring.svc.cluster.local:4317` (gRPC), `:4318` (HTTP) | none |

Read a value into a variable, never to the screen: `VAL=$(kubectl get secret <name> -n <ns> -o jsonpath='{.data.<key>}' | base64 -d)`. To see which keys a Secret has: `kubectl get secret <name> -n <ns> -o go-template='{{range $k,$v := .data}}{{$k}}{{"\n"}}{{end}}'`.

## 3. Put the agent where it can reach them

The toolkit services are in an Istio ambient mesh with STRICT mTLS, and LiteLLM admits only listed namespaces. A pod outside the mesh, or one the policy does not allow, gets a **connection reset** and no error message. Follow `references/namespace-onboarding.md`:
1. label the namespace `istio.io/dataplane-mode=ambient`;
2. add it to `litellm_allowed_namespaces`;
3. copy the Secrets;
4. add sandbox RBAC if needed.

## 4. Wire each service

Steps marked **(changes the cluster)** in the references create or change objects. Show the user the command and get an OK first.

| Service | Reference |
|---|---|
| LiteLLM: keys, URLs, model names, guardrail responses | `references/litellm.md` |
| Redis and pgvector: URLs, schema, the 1536-dimension tables | `references/memory.md` |
| Agent Sandbox and Kata: SDK code, RBAC, router authentication, isolation | `references/sandbox.md` |
| OpenShell: CLI, sandboxes, allowed binaries | `references/openshell.md` |
| KubeRay, Langfuse, OpenTelemetry | `references/ray-and-tracing.md` |

## Rules

- One virtual key per agent, limited to its models, with a budget. Never give agent code the master key.
- Mount credentials from Secrets (`secretKeyRef`). Never paste them into code, chat or logs.
- Tearing a component down and installing it again makes new credentials: Redis and pgvector passwords, OpenShell certificates and key, and the Ray dashboard password. Re-read or re-copy them afterwards. A plain re-run of install keeps them, and LiteLLM virtual keys survive both.
- Code inside an Agent Sandbox reaches only the public internet. It cannot reach LiteLLM, Redis, pgvector, cluster DNS or the Kubernetes API, by design. Pass data in and out through the SDK.
- Behind a proxy, set `NO_PROXY=.svc,.cluster.local,localhost,127.0.0.1` in agent pods.
- Use model names from `GET /v1/models`, not from examples.

## Fast answers

| Symptom | Cause | Fix |
|---|---|---|
| Connection reset to any toolkit service | Namespace not in the mesh, or not allowed by LiteLLM | `references/namespace-onboarding.md` |
| LiteLLM 400, 401, 403 or 429 about the key | Read `error.type` in the body: `budget_exceeded`, `expired_key`, `key_model_access_denied`, `auth_error` or `token_not_found_in_db`. The status code for each differs between LiteLLM versions. | Check the key with `/key/info`; `references/litellm.md` |
| LiteLLM 500 `Blocked by the content-safety guardrail: ...` | Guardrail decision (or the guard is down) | Read the reason; agent-toolkit-troubleshoot skill, GRD-1 |
| `WRONGPASS invalid username-password pair` | An old password (Redis was reinstalled), or a client that sends an empty username | Use the current `REDIS_URL` |
| `expected 1536 dimensions, not N` | The pre-created pgvector tables are 1536-d | Create a table with your dimension |
| Sandbox SDK `SandboxWarmPoolNotFoundError`, or 403 `... in the namespace "default"` | Wrong namespace (the SDK default is `default`) or wrong warm pool name | `namespace="agent-sandbox-system"`, `warmpool="python-pool"` |
| Sandbox SDK 403 `cannot create resource "sandboxclaims"` | No RBAC for the pod's ServiceAccount | Role in `references/sandbox.md` |
| `SandboxRequestError` with `status_code` 401 | No ServiceAccount token, an expired one, or one made with `--audience` | `extra_headers={"Authorization": f"Bearer {token}"}` with the pod's token; `references/sandbox.md` |
| OpenShell `policy_denied` | The calling program is not in the provider's `binaries` | `references/openshell.md` |

Anything else: use the agent-toolkit-troubleshoot skill.
92 changes: 92 additions & 0 deletions .agents/skills/agent-toolkit-components/references/litellm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# LiteLLM: the agents' model endpoint

LiteLLM is the OpenAI-compatible gateway in front of every model. It provides virtual keys, budgets, the content-safety guardrail, and a Langfuse trace for every call.

## Endpoints

| From | Base URL |
|---|---|
| A pod in an allowed namespace (`namespace-onboarding.md`) | `http://litellm.litellm.svc.cluster.local:4000/v1` |
| Outside the cluster, `routing_mode: subdomain` (default) | `https://litellm.<base_domain_name>/v1` |
| Outside the cluster, `routing_mode: path` (main track) | `https://<base_domain_name>/litellm/v1` |
| A laptop without DNS | `kubectl port-forward -n litellm svc/litellm 4000:4000`, then `http://localhost:4000/v1` |

The non-secret config map `litellm-credentials` in `litellm` names this install's API host (`api_url` or `hostname`, depending on the version) and admin UI (`ui_url`, the full address): `kubectl get cm litellm-credentials -n litellm -o jsonpath='{.data}'`.

Path mode with the toolkit default `litellm_public_paths: []` publishes no API route at all on the main track: the gateway gets one route per listed path. If `https://<base_domain_name>/litellm/v1/models` redirects to a sign-in page, set `litellm_public_paths` to the API paths (agent-toolkit-configuration skill).

From outside, trust the gateway CA when TLS is self-signed: `env/<env>/logs/toolkit-manager-ca.crt` under the Toolkit Manager root. Pass it to curl with `--cacert`, or to Python with `REQUESTS_CA_BUNDLE` / `SSL_CERT_FILE`.

## Keys

- **Master key**: Secret `litellm-master-key`, key `master_key`, namespace `litellm`. Admin only, for minting and managing keys. Never put it in agent code or config.
- **Virtual key**: one per agent, limited to the models it needs, with a budget and an expiry.

Mint a virtual key and store it as Secret `<agent>-litellm` in the agent's namespace **(changes the cluster)**. The keys go into variables and are never printed or written to a file:

```bash
MK=$(kubectl get secret litellm-master-key -n litellm -o jsonpath='{.data.master_key}' | base64 -d)
KEY=$(curl -s --cacert env/<env>/logs/toolkit-manager-ca.crt "https://litellm.<base_domain_name>/key/generate" \
-H "Authorization: Bearer $MK" -H 'Content-Type: application/json' \
-d '{"key_alias":"<agent>","models":["<model>"],"max_budget":10,"duration":"30d"}' | jq -ej .key) &&
printf %s "$KEY" | kubectl create secret generic <agent>-litellm -n <agent-ns> --from-file=OPENAI_API_KEY=/dev/stdin
unset MK KEY
```

`jq -e` makes a failed call stop before the Secret is created (the response has no `key`; repeat the call with `jq .error` to see why). Keep `-j`: it leaves out the trailing newline, which would end up in the key.

Or through a port-forward, with `http://localhost:4000/key/generate`. This works even when `litellm_public_paths` limits what the external host publishes.

Mount the Secret's `OPENAI_API_KEY` in the agent pod. Manage keys (updates and deletes change the cluster) with `GET /key/list?return_full_object=true`, `GET /key/info?key=<key>`, `POST /key/update` and `POST /key/delete` (`{"keys": [...]}` or `{"key_aliases": [...]}`). Keys and spend live in the platform PostgreSQL, so they survive a toolkit teardown.

Admin UI: on the main track `https://litellm-ui.<base_domain_name>/ui/` (path mode: `https://<base_domain_name>/litellm/ui/`), with Keycloak sign-in. On the release track `https://litellm.<base_domain_name>/ui/`, user `admin`, password = master key. The trailing slash is required.

## Model names

Always take names from the live list rather than from docs:

```bash
KEY=$(kubectl get secret <agent>-litellm -n <agent-ns> -o jsonpath='{.data.OPENAI_API_KEY}' | base64 -d)
curl -s http://localhost:4000/v1/models -H "Authorization: Bearer $KEY" | jq -r '.data[].id'
```

Usually present with the toolkit defaults:

| Name | What |
|---|---|
| `qwen2-5-coder-14b` | The default chat model (`llm_services_autodeploy_models`) |
| `hybrid-router` | Picks a model per request by cost and latency (`hybrid_router_enabled`) |
| `vllm-sr/auto` | vLLM Semantic Router, only with `vllm_sr_enabled: true` |
| `qwen3guard` | The guard model. It is used by the guardrail; agents should not call it. |

More models: `./model-manager deploy <name>` from the Toolkit Manager root (catalog: `env/<env>/models.yaml`) **(changes the cluster)**. Embedding models serve `/v1/embeddings`. None is deployed by default.

## Client configuration

The OpenAI SDK, LangChain `ChatOpenAI`, CrewAI and LangGraph all read:

```bash
export OPENAI_BASE_URL=http://litellm.litellm.svc.cluster.local:4000/v1
export OPENAI_API_KEY=<virtual key>
export NO_PROXY=.svc,.cluster.local,localhost,127.0.0.1 # when the pod has proxy variables
```

- Set the client timeout to at least 180 s. CPU inference under load is slow.
- Requests from one client IP are rate-limited at the external gateway (600 a minute). In-cluster calls do not pass that gateway.
- Every request, embeddings included, is screened by the guardrail when it is on. A block is HTTP 500 with a message starting `Custom code guardrail execution failed: Blocked by the content-safety guardrail:`. Handle it as "refused", not as a crash. The reasons are listed in the agent-toolkit-troubleshoot skill (`references/inference.md`, GRD-1).
- Tag traces for Langfuse with LiteLLM metadata, for example `extra_body={"metadata": {"trace_user_id": "<agent>", "session_id": "<id>"}}` in the OpenAI Python SDK.

## Reading errors

Classify a LiteLLM error by `error.type` and `error.message` in the JSON body, not by the status code alone. The codes differ between LiteLLM versions; for example, an over-budget key is 400 on the release track and 429 on the main track.

| `error.type` or message | Meaning |
|---|---|
| `budget_exceeded` | The key's budget is spent |
| `expired_key` | The key has expired |
| `key_model_access_denied` (or `team_model_access_denied`) | The key may not use this model |
| `auth_error` (no key sent) or `token_not_found_in_db` (unknown or deleted key) | Missing or invalid key |
| `Invalid model name passed in model=...` (400) | Not a registered name; check `/v1/models` |
| 500 with the guardrail prefix | Guardrail decision |
| 429 with no LiteLLM error body | The external gateway's rate limit (600 a minute per client IP) |
| Other 500, 503, 504 | Model or gateway problem (agent-toolkit-troubleshoot skill) |
88 changes: 88 additions & 0 deletions .agents/skills/agent-toolkit-components/references/memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Redis Stack and pgvector from agent code

Both services are inside the Istio ambient mesh with STRICT mTLS. A client pod must run in an ambient namespace (`namespace-onboarding.md`), otherwise the connection is reset. They have no external endpoint. From a laptop, use `kubectl port-forward`.

## Redis Stack: short-term memory

Use it for session and chat state, LangGraph checkpoints, semantic caches and RediSearch vector indexes. It is open-source Redis 8.10.3 with search and JSON built in (toolkit revisions before #43, including the ones Toolkit Manager `release-1.2` and `release-2.0` pin, install Redis Stack 7.4): one replica, password required, no TLS (the mesh encrypts traffic).

| | Value |
|---|---|
| Host | `redis-stack-server.redis.svc.cluster.local:6379` |
| Secret | `redis-stack-server-credentials` in ns `redis` |
| Keys | `REDIS_URL`, `REDIS_PASSWORD` |
| URL form | `redis://default:<password>@redis-stack-server.redis.svc.cluster.local:6379` |
| Storage | 10Gi PVC `db-redis-stack-server-0` (`redis_stack_persistence_size`, fixed after the first install) |

```bash
export REDIS_URL=$(kubectl get secret redis-stack-server-credentials -n redis -o jsonpath='{.data.REDIS_URL}' | base64 -d) # holds the password; do not echo
```

```python
import os, redis
r = redis.Redis.from_url(os.environ["REDIS_URL"])
r.ping()
```

The same `REDIS_URL` works for LangGraph's Redis checkpointer and for RedisVL or LangChain `RedisVectorStore`.

- Use the URL as stored (`redis://default:<password>@...`). `WRONGPASS invalid username-password pair` usually means an old password after Redis was reinstalled; some clients also fail when the username is empty.
- A namespace other than `redis` (`redis_stack_namespace`) changes the host. Set it before the first install.

## pgvector: long-term memory and RAG store

PostgreSQL 16 with the `vector` extension.

| | Value |
|---|---|
| Host | `pgvector.pgvector.svc.cluster.local:5432` |
| Database / user | `agentdb` / `agentuser` (`pgvector_database`, `pgvector_username`) |
| Secret | `pgvector-credentials` in ns `pgvector` |
| Keys | `DATABASE_URL` (URL), `POSTGRES_DSN` (libpq `key=value`), `host`, `port`, `database`, `username`, `password` |
| Storage | 20Gi PVC `data-pgvector-0` (`pgvector_storage_size`, fixed after the first install) |

```bash
DATABASE_URL=$(kubectl get secret pgvector-credentials -n pgvector -o jsonpath='{.data.DATABASE_URL}' | base64 -d) # holds the password; do not echo
```

- `psycopg.connect(os.environ["POSTGRES_DSN"])` works as is.
- SQLAlchemy and LangChain `PGVector` need the scheme `postgresql+psycopg://`. Replace the `postgresql://` prefix of `DATABASE_URL`.
- `agentuser` is the database superuser; there is no separate `postgres` role.
- Do not change `pgvector_database` or `pgvector_username` after the first install. The database was initialised with the old names, and validation then fails with `FATAL: role "<new>" does not exist`.

### Tables created at install

| Table | Purpose | Notable columns |
|---|---|---|
| `agent_memory` | Long-term memory | `agent_id`, `user_id`, `session_id`, `content`, `embedding VECTOR(1536)`, `metadata JSONB` |
| `agent_events` | Audit and event log | `event_type`, `payload JSONB`, `duration_ms` |
| `agent_cache` | Semantic cache | `cache_key` (unique), `embedding VECTOR(1536)`, `value JSONB`, `hit_count`, `expires_at` |

The embedding columns are fixed at **1536 dimensions** with HNSW cosine indexes. An embedding model with another size fails with `expected 1536 dimensions, not N`. Create your own table with the right dimension (for example `VECTOR(768)` for a 768-dimension model), or alter the column before storing data.

## Embeddings

Embeddings through LiteLLM need an embedding model deployed in the inference layer. None is deployed by default. Deploy one with `./model-manager deploy <name>` from the Toolkit Manager root **(changes the cluster)**, then use the name that `GET /v1/models` returns. If `/v1/embeddings` then fails with HTTP 400, see LLM-3 in the agent-toolkit-troubleshoot skill (`references/inference.md`): some versions register embedding models in LiteLLM in a way that breaks this call.

## Wiring credentials into an agent pod

The Secrets live in the service namespaces. Copy them into the agent namespace **(changes the cluster)**, or sync them with your secret manager, then reference them:

```yaml
env:
- name: REDIS_URL
valueFrom: {secretKeyRef: {name: redis-stack-server-credentials, key: REDIS_URL}}
- name: DATABASE_URL
valueFrom: {secretKeyRef: {name: pgvector-credentials, key: DATABASE_URL}}
```

Tearing down and reinstalling Redis or pgvector deletes the data and generates **new passwords**. Copy the Secrets again afterwards.

## Inspect

```bash
kubectl get pods,pvc,svc -n redis
kubectl logs -n redis redis-stack-server-0
kubectl get pods,pvc -n pgvector
kubectl logs -n pgvector pgvector-0
```
Loading
Loading