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
62 changes: 62 additions & 0 deletions packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,66 @@ which OS ran the write. The keys stay valid everywhere else: an AI Config refere
named `aux` parses, and its other fields are unaffected. If you have a skill named for a
device, rename it.

#### Receiving skills from LaunchDarkly

`InMemorySkillStore` is for tests and bring-your-own-content. In production, skill content
arrives through `FDv2SkillStore`, which speaks LaunchDarkly's SDK-facing FDv2 delivery
channel β€” the same `GET /sdk/poll` and `GET /sdk/stream` endpoints the base SDK's FDv2 data
source uses, authenticated with the environment's server-side SDK key.

```python
import os

from launchdarkly_ai_server import FDv2SkillStore, init_client, watch_skills

store = FDv2SkillStore(os.environ["LD_SDK_KEY"]).start()
store.wait_for_skills(timeout=10)
await init_client(options={"skillStore": store})

# Materialize now, and re-materialize whenever delivery changes.
report, watcher = await watch_skills("*", ".claude/skills")
try:
...
finally:
watcher.close()
store.close()
```

**Nothing above the store changes.** The accessors, verification, and `write_skills` see raw
objects through the `SkillStore` interface and cannot tell which store produced them.

**Server-side only.** Skills are for server-side agent runtimes and skill content is
customer-confidential. A mobile key (`mob-…`) or a client-side environment ID raises from the
constructor.

**Streaming is the default, and it is what makes revocation fast.** A `delete-object` reaches
a live stream in seconds; with `mode="poll"` it arrives within one `poll_interval`. Paired
with `watch_skills`, a revoked skill's `SKILL.md` leaves the disk without a restart. During an
outage the store keeps serving the last content it received and `write_skills`' default
`on_unavailable="keep"` leaves managed files alone β€” an outage must not read as "everything
was revoked".

**One network timeout, and its default depends on the mode.** `read_timeout` bounds every
socket operation of a request, connecting included. In `mode="poll"` it bounds the whole
request and defaults to 10 seconds; in `mode="stream"` it bounds each wait for the next bytes
and defaults to 300 seconds, well beyond LaunchDarkly's heartbeat interval.

**The connection also carries your flags.** A client cannot request only the skill payload,
so a skills-enabled environment delivers flag and segment objects on the same connection.
They are skipped, not evaluated β€” this store does no evaluation of any kind β€” and
`diagnostics.objects_ignored` counts them.

> **Beta caveats, worth knowing before you deploy.** Payload signing does not exist on this
> channel yet, so delivery is TLS-only and the content hash establishes self-consistency, not
> origin authenticity. The FDv2 protocol is opt-in per account: without it the endpoints
> return HTTP 403, which the store reports as a fatal error explaining what to do. `ld-relay`
> does not speak the FDv2 endpoints, so relay-only deployments cannot receive skills.

**If every skill comes back empty, check `diagnostics.hashless_objects`.** Verification
withholds any delivered object without a `contentHash`, so a nonzero count means skills are
being withheld rather than that the environment has none. The store also logs an error per
hashless object naming the reason. There is deliberately no fallback that skips verification.

**Total path length is yours to bound, not the SDK's.** The 255-byte bound above is per
*component*; the root is your path, so `<root>` + `<key>` + `/SKILL.md` can still exceed
Windows' 260-character `MAX_PATH` with a perfectly legal key. Choose a short managed root on
Expand All @@ -460,7 +520,9 @@ Windows.
| `write_skills(skills, root, *, prune=True, timeout=10.0, on_unavailable="keep")` | Materialize skills under `root`, returning a `ReconcileReport`. `prune` removes formerly-managed skills no longer requested. `on_unavailable="raise"` raises instead of reporting when content cannot be retrieved. Raises `ValueError` for an unusable root, a negative `timeout`, or an unrecognised `on_unavailable`. **Performs synchronous filesystem I/O β€” see the note below.** |
| `SkillStore` | The structural interface content arrives through: `get_object(kind, key, version=None)`, `all_objects(kind)`, optional `add_listener(kind, fn)` / `remove_listener(kind, fn)`. |
| `InMemorySkillStore(objects=None)` | A dict-backed store with `put(raw)`, for local development and testing. Holds several versions of a key. |
| `FDv2SkillStore(sdk_key, *, base_uri=…, mode="stream", …)` | The delivery transport: a store fed by LaunchDarkly over the SDK-facing FDv2 channel. `start()`, `wait_for_skills(timeout)`, `close()`, `diagnostics`, `failed`; also a context manager. **Server-side only** β€” a mobile key or client-side environment ID raises. See *Receiving skills from LaunchDarkly* above. |
| `watch_skills(skills, root, …)` | `write_skills` plus a re-reconcile on every delivery change. Returns `(initial report, SkillWatcher)`; close the watcher when done. Revocation then takes effect within `debounce` of arriving rather than at the next restart. |
| `StoreDiagnostics` | What the transport has seen: `payloads_transferred`, `skill_objects_received`, `objects_ignored`, `objects_revoked`, `hashless_objects`, `connection_failures`, `last_error`. |

Configure the store with `init_client(options={"skillStore": store})`. With none configured,
the accessors raise `RuntimeError` explaining what to do and `write_skills` reports the
Expand Down
25 changes: 20 additions & 5 deletions packages/client/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ No other `launchdarkly-ai-*` package may define or duplicate these. They import
| `src/launchdarkly_ai_server/types_validation.py` | `parse_ai_config` β€” validates flag variation shape; `is_valid_skill_key` / `is_valid_skill_version` / `skill_key_rejection_reason` (the canonical key-grammar explanation every layer quotes) |
| `src/launchdarkly_ai_server/skills.py` | Agent Skills, retrieval half β€” `skill_refs`, `get_skill`/`get_skills`/`all_skills`, `InMemorySkillStore`, and the store/telemetry injection points `_set_store` / `_set_emitter_for_testing` |
| `src/launchdarkly_ai_server/skills_core.py` | Shared skills internals β€” the `SkillStore` seam, module state, the telemetry seam and its three recorders, integrity verification, and store resolution. Imported by both `skills.py` and the materialization layer; imports neither |
| `src/launchdarkly_ai_server/skills_fdv2.py` | Agent Skills, delivery protocol β€” the wire-key/`version` translation, the held object set, and the pure `_ProtocolReader` that commits a payload's events at `payload-transferred`. Sits **below** the store interface; nothing in the feature imports it |
| `src/launchdarkly_ai_server/skills_fdv2.py` | Agent Skills, delivery transport β€” the FDv2 protocol, the wire-key/`version` translation, the held object set, and `FDv2SkillStore`. Sits **below** the store interface; imports `skills_core` only, and nothing imports it |
| `src/launchdarkly_ai_server/skills_watch.py` | Agent Skills, eager re-reconcile β€” `watch_skills` / `SkillWatcher`, wiring the store's change listener to `write_skills`. Sits **above** `skills_fs` and modifies none of it |
| `src/launchdarkly_ai_server/skills_fs.py` | Agent Skills, materialization half β€” `write_skills`, request resolution, the manifest format and on-disk filenames, per-skill reconcile, and pruning |
| `src/launchdarkly_ai_server/safe_fs.py` | Descriptor-pinned filesystem primitives β€” `atomic_write`, `unlink_file`, `pinned_directory`, `open_directory_nofollow`, `open_or_create_directory`, `SymlinkRefused`, and the `*at()` capability probe. Owns the descriptor-vs-path platform split; knows nothing about skills |
Expand Down Expand Up @@ -221,10 +221,12 @@ of skills, and the `"*"` reconcile, since `<root>/<key>/SKILL.md` is a single pa

### The delivery transport, and the one field that will bite you

`skills_fdv2.py` translates LaunchDarkly's FDv2 delivery protocol into raw objects in the
shape `skills_core.SkillStore` documents. It lives below the store interface; **nothing above
that interface knows it exists**. If a transport change ever seems to require editing an
accessor, verification, or `write_skills`, the adapter boundary is wrong.
`FDv2SkillStore` speaks LaunchDarkly's SDK-facing FDv2 channel (`GET /sdk/poll`,
`GET /sdk/stream`, server-side SDK key in `Authorization`, `basis` + `mv` params,
`If-None-Match`/304). It lives below the store interface and produces raw objects in the
shape `skills_core.SkillStore` documents; **nothing above that interface knows it exists**. If a transport
change ever seems to require editing an accessor, verification, or `write_skills`, the adapter
boundary is wrong.

**The skill's version is in the object's `key`. `version` is the payload's.** Each version
of a skill is its own object on the wire, identified as `<key>:<version>`:
Expand Down Expand Up @@ -285,6 +287,19 @@ such skill" β€” and would let a prune delete the last known-good copy on disk. N
a hash from the delivered content: that certifies the content against itself and verifies
nothing.

**There is one network timeout, not two.** `urllib`'s `timeout` is the socket timeout for the
whole operation, so connect, headers and each read share it, and the module cannot bound the
connect separately without a custom connection class it should not carry. `read_timeout` is
therefore the only knob, and its default is per mode (`DEFAULT_POLL_TIMEOUT` for a whole poll
request, `DEFAULT_STREAM_READ_TIMEOUT` for the gap between reads on a stream). Do not add a
parameter that the standard library cannot honour; `TestTimeouts` measures the bound against a
socket that accepts and never answers.

**`close` interrupts the socket, it does not just set a flag.** The delivery thread spends its
life blocked in a read that no flag can reach, and closing a response from another thread does
not unblock CPython's buffered reader. `_interrupt_read` shuts the socket down underneath it.
Without that, every shutdown of a *healthy* stream blocks for the full join timeout.

### The reported outcome vocabulary, and the `Resolution` mapping

`get_skill` returns `Skill | None`; `get_skill_result` returns a frozen `SkillOutcome`
Expand Down
5 changes: 4 additions & 1 deletion packages/client/src/launchdarkly_ai_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
skill_refs,
)
from .skills_core import SkillStore
from .skills_fdv2 import FDv2SkillStore, StoreDiagnostics
from .skills_fs import (
MANIFEST_FILENAME,
MANIFEST_VERSION,
Expand Down Expand Up @@ -238,7 +239,9 @@
"write_skills",
"SkillStore",
"InMemorySkillStore",
# skills β€” the eager re-reconcile
# skills β€” the FDv2 delivery transport, and the eager re-reconcile it enables
"FDv2SkillStore",
"StoreDiagnostics",
"watch_skills",
"SkillWatcher",
# skills β€” the three closed-set unions a typed consumer needs to name
Expand Down
13 changes: 11 additions & 2 deletions packages/client/src/launchdarkly_ai_server/skills_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,18 @@

NO_STORE_MESSAGE = (
"No skill store is configured, so skill content cannot be retrieved. Configure "
'one with init_client(options={"skillStore": store}) β€” InMemorySkillStore is '
"available for local development and testing."
'one with init_client(options={"skillStore": store}) β€” FDv2SkillStore receives '
"content from LaunchDarkly, and InMemorySkillStore is available for local "
"development and testing."
)
"""
The first thing a user sees when no store is configured, so it names both stores.

``FDv2SkillStore`` comes first because it is the answer in production, and a
message that offered only ``InMemorySkillStore`` would point a deployment at the
development store. Callers match on "skill store"; keep that phrase if the
wording changes.
"""


# ---------------------------------------------------------------------------
Expand Down
Loading
Loading