> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usekindred.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Use a Coding Agent

> Paste this prompt into Cursor, Claude Code, Codex, or another coding agent to connect Kindred through Langfuse.

Use these prompts when you want Cursor, Claude Code, Codex, or another coding agent to make the smallest working Kindred integration patch.

If your agent is not already traced in Langfuse, run Prompt 1 first. If Kindred can already sync your traces, skip to Prompt 2.

## Prompt 1: Add Langfuse tracing

```text theme={null}
You are integrating this AI agent with Kindred using Langfuse.

Goal:
Make the existing agent produce Langfuse traces Kindred can sync.

Mental model:
Langfuse captures the original run. Kindred syncs that trace. Later, Kindred can replay the same run and compare the original trace against the replay trace to find the first meaningful divergence.

Hard constraints:
- Make the smallest working patch.
- Do not refactor the app.
- Do not create fake agents.
- Do not create eval harnesses.
- Do not create demo-only paths.
- Do not add unrelated tests or features.
- Use the official Langfuse SDK or Langfuse integration for this stack.
- Do not hardcode secrets.

Tasks:

1. Find the real agent entrypoint.

Identify the existing function, route, graph, chain, or handler that runs one user turn. Prefer the production path already used by the app.

2. Add or verify Langfuse instrumentation.

Use the official Langfuse SDK or integration for the detected stack, such as LangGraph, LangChain, OpenAI SDK, Anthropic SDK, Vercel AI SDK, or the app's existing HTTP agent flow.

Ensure Langfuse captures the agent turn and, where supported:
- LLM or generation calls
- tool calls
- tool results
- relevant input and output messages
- generation input with a messages array when the app has chat messages

3. Add required environment variables.

If an env example file exists, add:
- LANGFUSE_PUBLIC_KEY
- LANGFUSE_SECRET_KEY
- LANGFUSE_HOST
- KINDRED_AGENT_ID

4. Add Kindred metadata to normal traces.

Every normal agent turn should include these Langfuse session or metadata fields:
- agent_id: the value of KINDRED_AGENT_ID
- session_id: the stable conversation or session id
- run_id: a unique id for this agent turn

Prefer trace-level propagation for these values, such as Langfuse propagate_attributes in Python, so child observations inherit the same session and metadata.

Reuse existing conversation ids, request ids, thread ids, or run ids where appropriate.

5. Flush Langfuse if needed.

If the app runs in a short-lived serverless function, job, script, or local process, flush Langfuse after the agent turn.

6. Verify the smallest tracing path.

Run the relevant formatter, typecheck, tests, or a local smoke test if this repo supports them.

After patching, report:
- files changed
- env vars to set
- command to run one normal test turn
- how to verify the normal trace appeared in Langfuse
- how to confirm the normal trace includes agent_id, session_id, and run_id
- whether the trace includes LLM/generation, tool, or agent observations

Do the code changes directly. Do not stop at a plan.
```

## Prompt 2: Add replay endpoint

```text theme={null}
You are making this Langfuse-instrumented agent replayable for Kindred.

Goal:
Add or verify a POST /replay endpoint that Kindred can call to rerun a selected agent turn, then run it locally, expose it with ngrok, and report the exact URL to paste into the Kindred console.

Mental model:
Kindred calls POST /replay with the original input and replay metadata. The replay uses the existing agent execution path, creates a new Langfuse trace, and preserves kindred_replay_run_id so Kindred can find that replay trace.

Hard constraints:
- Make the smallest working patch.
- Do not refactor the app.
- Do not create fake agents.
- Do not create eval harnesses.
- Do not create demo-only paths.
- Do not add unrelated tests or features.
- Reuse the existing agent execution path.
- Keep Langfuse instrumentation attached to replay runs.
- Do not hardcode secrets.

Tasks:

1. Find the real agent entrypoint.

Identify the existing function, route, graph, chain, or handler that runs one user turn. Prefer the production path already used by the app.

2. Add or verify POST /replay.

The endpoint must:
- accept JSON
- support either messages or input
- prefer messages when both are present
- call the same agent execution path used for normal turns
- return JSON

Do not implement replay with a mock response or a separate demo agent.

3. Preserve replay metadata.

When a replay request includes these body fields, preserve them in Langfuse metadata for the replay trace:
- kindred_replay_run_id
- kindred_original_session_id
- kindred_include_prior_context
- kindred_turn_trace_id
- is_replay

Also accept these headers and map them into the same metadata:
- X-Kindred-Replay
- X-Kindred-Replay-Run-Id
- X-Kindred-Original-Session-Id
- X-Kindred-Turn-Trace-Id
- X-Kindred-Include-Prior-Context

The replay trace must include kindred_replay_run_id.
Put replay metadata on the Langfuse trace or propagated attributes, not only on an HTTP response, because Kindred finds the replay by polling Langfuse traces for kindred_replay_run_id.

4. Preserve normal Kindred metadata too.

The replay trace should still include:
- agent_id: the value of KINDRED_AGENT_ID
- session_id: a stable replay session id
- run_id: a unique id for this replay turn

5. Return useful replay JSON.

Return the agent result as JSON. Include these fields if available:
- session_id
- run_id
- kindred_replay_run_id
- output or assistant response

6. Flush Langfuse if needed.

If the app runs in a short-lived serverless function, job, script, or local process, flush Langfuse before returning the replay response.

7. Verify the smallest replay path.

Run the relevant formatter, typecheck, tests, or a local smoke test if this repo supports them.

8. Start the local server.

Start the app or agent server locally if dependencies and required environment variables are available.
If the app already has a dev or server command, use it.
If there is no obvious command, identify the command the user should run.

Confirm the local POST /replay endpoint returns JSON before moving on.

9. Expose the replay endpoint with ngrok.

If ngrok is installed, start ngrok for the local server port.
Use the actual local port used by the app.

Example:

ngrok http <PORT>

If ngrok is not installed or cannot run in this environment, say that clearly and give the exact command the user should run.

When ngrok is running, report the public HTTPS replay URL to paste into Kindred as Target URL (replay_url). Include /replay if the endpoint uses that path.

Example:

https://abc123.ngrok-free.app/replay

After patching, report:
- files changed
- command to run the local server
- the replay URL path
- a curl command for POST /replay with is_replay and kindred_replay_run_id
- whether the replay endpoint returned JSON
- how to verify the replay trace includes kindred_replay_run_id
- whether ngrok is running
- the exact ngrok HTTPS replay URL to paste into the Kindred console

Do the code changes directly. Do not stop at a plan.
```

## Check your setup

* Langfuse received one normal trace.
* The normal trace has `agent_id`, `session_id`, and `run_id`.
* Kindred **Sync now** imports the trace.
* `POST /replay` returns JSON.
* A replay creates a new Langfuse trace with `kindred_replay_run_id`.
