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-site/static/search-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,7 @@
{"objectID":"304f3b3f1d3d11c91945e49e4ae3f60d2b9a826b87a3948f18fd137a16b38c45","title":"Disable or override","url":"/docs/features/observability#disable-or-override","content":"Every field is optional. publicKey, secretKey, baseUrl, environment and release fall back to the variables above; the others have the defaults below. The type is NeurolinkLangfuseConfig.\n\n| Field | Meaning |\n| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| enabled | false turns Langfuse off although keys are set (from untyped config, the strings \"false\", \"0\", \"off\" and \"no\" do too); any other value, or leaving it out, leaves it on.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Disable or override","lvl3":""}},
{"objectID":"d5c2e109ca689299bbc1e1068341dfd6ba1294b1ee3c11cebe6489977865892e","title":"Per-call context","url":"/docs/features/observability#per-call-context","content":"Pass context on generate, stream and decide. The values are attached to every span the call creates, including tool calls and fallback attempts, so one call is one trace.\n\n| Field | Recorded as |\n| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |\n| userId | Trace user |\n| sessionId | Trace session |\n| tags | Trace tags |\n| traceName | Trace name |\n| conversationId | Metadata key conversationId |\n| requestId | Metadata key requestId |\n| metadata | Metadata; values up to 200 characters are on every observation, longer values and arrays are recorded in full on the trace only |\n| observationName | Name of the root observation of this call; default generate or stream; not propagated to child observations or used as the trace name |","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Per-call context","lvl3":""}},
{"objectID":"d262ba0787c1b57c76e303845fc9c6f447a3a2f747a880270f15c61fcc1863bb","title":"setLangfuseContext","url":"/docs/features/observability#setlangfusecontext","content":"Wrap your own code to attach the same attributes to everything inside it, including spans you create yourself.\n\nsetLangfuseContext(params: NeurolinkTraceContext, fn) returns whatever fn returns. It is a thin wrapper over Langfuse's propagateAttributes.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"setLangfuseContext","lvl3":""}},
{"objectID":"ebe52665a13e8e28856b65cd1d82bb2709538cb3fdd9b2ab6e54cd7061a8fb0d","title":"Langfuse prompts","url":"/docs/features/observability#langfuse-prompts","content":"getLangfusePrompt(name, options) fetches a text prompt from Langfuse Prompt Management with the keys and host tracing uses (observability.langfuse, then LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_BASE_URL). Pass the result as prompt to setLangfuseContext and Langfuse links the generations inside to that prompt version.\n\n| Option | Default | Effect |\n| ------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| label | production | Deployment label to fetch |\n| fallback | required | Text returned when the prompt cannot be fetched as a text prompt |\n| cacheTtlMs | 60000 | How long a prompt is served from the cache before it is refreshed in the background; the call that fetches an entry sets it for every caller of that name and label |\n| timeoutMs | 2000 | How long one fetch waits for Langfuse |\n\nIt never throws. Prompts are cached per project, host, name and label, up to 500 entries (the least recently fetched is dropped first), and each call gets its own copy; concurrent callers share one request, and an expired entry is returned at once while it refreshes.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Langfuse prompts","lvl3":""}},
{"objectID":"542eff7388511fe18f61b3de966dff32a0a0ccfa5c95df170298790e0233739d","title":"Naming","url":"/docs/features/observability#naming","content":"The observations below (generate, stream, decide, attempts, steps and tools) carry no product name in their span names, attribute keys or metadata keys. Names never carry per-execution values: the model and provider are fields, the step number is metadata. The product name remains in the plain spans listed under Other spans and in the proxy root's neurolink.user_id, neurolink.session_id and neurolink.conversation_id attributes.\n\n| Observation | Name | Langfuse type | Parent |\n| -------------------------- | ------------------------------------- | ------------- | ---------------------- |\n| generate / stream call | generate / stream | agent | none (trace root) |\n| Fallback attempt | generate.attempt / stream.attempt | span | root |\n| Agent loop step | step (step_index metadata) | span | the attempt span |\n| One model request | generate / stream | generation | its step |\n| Tool execution | the tool's name, e.g. get_weather | tool | the step that ran it |\n| decide | decide | generation | caller or root |\n\nA model request is named after the API the caller used (NeuroLink.generate or provider.generate gives generate, NeuroLink.stream or provider.stream gives stream). Its model is the observation's model field (the model the provider reported, falling back to the requested one) and the provider id is the provider metadata key.\n\nThe trace name is context.traceName when given, otherwise the operation name (generate, stream). An outer setLangfuseContext takes precedence over per-call context for user, session and trace name.\n\nEmbeddings, transcribe, TTS and media tracing are not yet recorded. The root also sets trace-level input and output; a generate or stream nested inside another turn does not.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Naming","lvl3":""}},
{"objectID":"bec7707961c02d5123e4dceed9e13f5f5311e2f47783dd81fc290b467f50ff7a","title":"Other spans","url":"/docs/features/observability#other-spans","content":"Spans from the RAG, workflow, file, memory, context and evaluation code are exported as plain span records with their name, timing, status and their own attributes. They keep their neurolink.* names: neurolink.rag.search, neurolink.rag.rerank, neurolink.rag.chunk, neurolink.workflow.* (run, run.streaming, response.condition, judge.score, ensemble.execute, layers.execute), neurolink.file.process, neurolink.file.video.process, neurolink.context.compact, neurolink.memory.summarize and neurolink.evaluation.ragas.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Other spans","lvl3":""}},
{"objectID":"ceb0e84f71b6a9deb6a57e236efa009236e933eb892ad569d59e36ba873292f3","title":"Steps and chat format","url":"/docs/features/observability#steps-and-chat-format","content":"Each iteration of the agent loop gets one step span with its one-based index in the step_index metadata. It parents that iteration's generation and the tool observations the model requested in it, so a multi-tool turn reads as step 1 (call, tools), step 2 (call, tools), and so on.\n\nGeneration input is a chat message array with the system message first. Generation output is an assistant message array: content, plus reasoning and tool_calls ({ id, type: \"function\", function: { name, arguments } }) when present. Langfuse renders both as a conversation.\n\nGeneration details:\nUsage includes input, output, total, cache read, cache creation and reasoning tokens, whatever naming the provider uses.\nCost is computed from NeuroLink's pricing table and recorded as costDetails.total.\nModel parameters are temperature, max tokens, top-p and thinking level.\nTime to first token is recorded as the generation's completion start time for streams.\nLevel is WARNING for a length or content-filter finish, an aborted call, an early break out of a stream, or an empty output, and ERROR when the call throws.\nStreams end their spans when the stream finishes, is abandoned or is aborted.","hierarchy":{"lvl0":"Features","lvl1":"Observability Guide","lvl2":"Steps and chat format","lvl3":""}},
Expand Down
4 changes: 4 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,9 @@ console.log(result.content);
- [AiMetricInstruments](type-aliases/AiMetricInstruments.md)
- [ObservabilityConfig](type-aliases/ObservabilityConfig.md)
- [NeurolinkTraceContext](type-aliases/NeurolinkTraceContext.md)
- [LangfusePromptRef](type-aliases/LangfusePromptRef.md)
- [LangfusePromptOptions](type-aliases/LangfusePromptOptions.md)
- [LangfusePrompt](type-aliases/LangfusePrompt.md)
- [RetryPolicy](type-aliases/RetryPolicy.md)
- [Sampler](type-aliases/Sampler.md)
- [SpanProcessor](type-aliases/SpanProcessor.md)
Expand Down Expand Up @@ -4117,6 +4120,7 @@ console.log(result.content);
- [isOpenTelemetryInitialized](functions/isOpenTelemetryInitialized.md)
- [getLangfuseHealthStatus](functions/getLangfuseHealthStatus.md)
- [setLangfuseContext](functions/setLangfuseContext.md)
- [getLangfusePrompt](functions/getLangfusePrompt.md)
- [createSkillStore](functions/createSkillStore.md)
- [createSkillTools](functions/createSkillTools.md)
- [isStandardRecord](functions/isStandardRecord.md)
Expand Down
44 changes: 44 additions & 0 deletions docs/api/functions/getLangfusePrompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[**NeuroLink API Reference**](../README.md)

---

[NeuroLink API Reference](../README.md) / getLangfusePrompt

# Function: getLangfusePrompt()

> **getLangfusePrompt**(`name`, `options`): `Promise`\<[`LangfusePrompt`](../type-aliases/LangfusePrompt.md)\>

## Parameters

### name

`string`

{string} - Prompt name in Langfuse.

### options

[`LangfusePromptOptions`](../type-aliases/LangfusePromptOptions.md)

{LangfusePromptOptions} - Label, fallback text, cache TTL and request timeout.

## Returns

`Promise`\<[`LangfusePrompt`](../type-aliases/LangfusePrompt.md)\>

The prompt, or `{ name, text: fallback, label, isFallback: true }`; never rejects.

## Description

Fetches a text prompt from Langfuse with the keys and host NeuroLink's tracing was started with, falling back to `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY` and `LANGFUSE_BASE_URL`. Prompts are cached per project, host, name and label: within `cacheTtlMs` no request is made, and an expired entry is returned at once while one background request refreshes it. Concurrent callers share one request. Missing keys, an error, a timeout, a missing prompt or a chat prompt return the fallback, after a warning for all but missing keys; a failed request is not repeated within `cacheTtlMs`, and a prompt fetched before stays in use. `text` is returned as stored, with `{{variable}}` placeholders not filled in. The fetch ignores `langfuse: false` and `LANGFUSE_ENABLED`, so a caller with its own switch checks it first.

## Example

```ts
const prompt = await getLangfusePrompt("support-agent", {
fallback: "You are a helpful agent.",
});
await setLangfuseContext({ prompt }, () =>
neurolink.generate({ input: { text: "hi" }, systemPrompt: prompt.text }),
);
```
4 changes: 2 additions & 2 deletions docs/api/functions/setLangfuseContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

[`NeurolinkTraceContext`](../type-aliases/NeurolinkTraceContext.md)

{NeurolinkTraceContext} - User, session, trace name, tags and metadata for the trace.
{NeurolinkTraceContext} - User, session, trace name, tags, metadata and prompt for the trace.

### fn

Expand All @@ -36,7 +36,7 @@ Whatever `fn` returns.

## Description

Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.
Runs `fn` with trace attributes propagated to every span it creates. `conversationId` and `requestId` become metadata; empty values are dropped. `prompt` adds the trace tag `prompt:<name>@<version>` (`@fallback` for a fallback, no suffix without a version) and `promptName`, `promptVersion` and `promptLabel` metadata, and links generations to the prompt version unless it is a fallback; it replaces an enclosing prompt's tag, metadata and link. Metadata values of up to 200 characters once stringified are on every observation; longer values and arrays are recorded in full on the trace only, written by the trace root.

## Example

Expand Down
25 changes: 25 additions & 0 deletions docs/api/type-aliases/LangfusePrompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[**NeuroLink API Reference**](../README.md)

---

[NeuroLink API Reference](../README.md) / LangfusePrompt

# Type Alias: LangfusePrompt

> **LangfusePrompt** = [`LangfusePromptRef`](LangfusePromptRef.md) & `object`

## Type Declaration

### text

> **text**: `string`

Prompt text to send to the model.

### isFallback

> **isFallback**: `boolean`

## Description

A text prompt resolved by `getLangfusePrompt`. `isFallback` is `true` when `text` is the caller's fallback, which carries no `version`.
45 changes: 45 additions & 0 deletions docs/api/type-aliases/LangfusePromptOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[**NeuroLink API Reference**](../README.md)

---

[NeuroLink API Reference](../README.md) / LangfusePromptOptions

# Type Alias: LangfusePromptOptions

> **LangfusePromptOptions** = `object`

## Description

Options for `getLangfusePrompt`.

## Properties

### label?

> `optional` **label?**: `string`

Deployment label to fetch; Langfuse serves `production` when omitted.

---

### fallback

> **fallback**: `string`

Text returned when the prompt cannot be fetched as a text prompt.

---

### cacheTtlMs?

> `optional` **cacheTtlMs?**: `number`

Milliseconds before a cached prompt is refreshed in the background; defaults to 60000. The call that fetches an entry sets it for every caller of that name and label.

---

### timeoutMs?

> `optional` **timeoutMs?**: `number`

Milliseconds a fetch, body included, waits for Langfuse; defaults to 2000.
45 changes: 45 additions & 0 deletions docs/api/type-aliases/LangfusePromptRef.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[**NeuroLink API Reference**](../README.md)

---

[NeuroLink API Reference](../README.md) / LangfusePromptRef

# Type Alias: LangfusePromptRef

> **LangfusePromptRef** = `object`

## Description

A Langfuse prompt version a trace was produced with. Generations are linked to it when it has a `version` and is not a fallback.

## Properties

### name

> **name**: `string`

Prompt name in Langfuse.

---

### version?

> `optional` **version?**: `number`

Prompt version; generations are linked only when it is set.

---

### label?

> `optional` **label?**: `string`

Deployment label the version was fetched by.

---

### isFallback?

> `optional` **isFallback?**: `boolean`

Whether the prompt text is a local fallback rather than a Langfuse version.
8 changes: 8 additions & 0 deletions docs/api/type-aliases/NeurolinkTraceContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ Trace metadata; values up to 200 characters once stringified are on every observ
> `optional` **observationName?**: `string` \| `null`

Name of the root observation of this `generate` or `stream` call; not propagated to child observations and not the trace name.

---

### prompt?

> `optional` **prompt?**: [`LangfusePromptRef`](LangfusePromptRef.md)

Langfuse prompt the call ran with, such as a `getLangfusePrompt` result; recorded as a `prompt:` trace tag and `promptName`, `promptVersion` and `promptLabel` metadata, replacing an enclosing prompt's tag and metadata.
Loading
Loading