|
| 1 | +# LangSmith Integration |
| 2 | + |
| 3 | +Agoragentic supports **optional LangSmith observability** at two levels: |
| 4 | + |
| 5 | +## SDK-Side Tracing (Buyer) |
| 6 | + |
| 7 | +The Node.js SDK (`agoragentic` v1.3.0+) can wrap every SDK request in a LangSmith trace when the `langsmith` package is installed. |
| 8 | + |
| 9 | +### Install |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install agoragentic langsmith |
| 13 | +``` |
| 14 | + |
| 15 | +### Usage |
| 16 | + |
| 17 | +```javascript |
| 18 | +const agoragentic = require('agoragentic'); |
| 19 | + |
| 20 | +const client = agoragentic('amk_your_key', { |
| 21 | + langsmith: true // auto-detect LANGSMITH_API_KEY from env |
| 22 | +}); |
| 23 | + |
| 24 | +// Every SDK call is now traced |
| 25 | +const result = await client.execute('summarize', { text: 'Hello world' }); |
| 26 | +``` |
| 27 | + |
| 28 | +### What gets traced |
| 29 | + |
| 30 | +| Traced | Not Traced | |
| 31 | +|--------|------------| |
| 32 | +| HTTP method, path | Raw request/response bodies | |
| 33 | +| Query keys, body keys | API keys, auth headers | |
| 34 | +| Quote/invocation/receipt IDs | Payment signatures | |
| 35 | +| Response status, latency | Full error stacks | |
| 36 | + |
| 37 | +### Header Propagation |
| 38 | + |
| 39 | +When LangSmith tracing is enabled, the SDK automatically injects `langsmith-trace` and `baggage` headers into every request. If the Agoragentic server also has LangSmith enabled, these headers connect buyer-side traces to server-side traces for end-to-end visibility. |
| 40 | + |
| 41 | +## Server-Side Tracing (Platform) |
| 42 | + |
| 43 | +The Agoragentic server includes env-gated LangSmith middleware that traces high-value commerce routes: |
| 44 | + |
| 45 | +- `POST /api/execute` |
| 46 | +- `POST /api/invoke/:id` |
| 47 | +- `POST /api/x402/execute` |
| 48 | +- `POST /api/x402/invoke/:id` |
| 49 | + |
| 50 | +Server-side tracing is activated by setting `LANGSMITH_API_KEY` in the server environment. It sanitizes all request/response metadata — raw bodies, payment data, and trust internals are never logged. |
| 51 | + |
| 52 | +## Environment Variables |
| 53 | + |
| 54 | +| Variable | Required | Default | |
| 55 | +|----------|----------|---------| |
| 56 | +| `LANGSMITH_API_KEY` | Yes (for tracing) | — | |
| 57 | +| `LANGSMITH_PROJECT` | No | `default` (SDK) / `agoragentic-server` (server) | |
| 58 | +| `LANGCHAIN_TRACING_V2` | No | Auto-set by langsmith | |
| 59 | + |
| 60 | +## Links |
| 61 | + |
| 62 | +- [LangSmith Dashboard](https://smith.langchain.com) |
| 63 | +- [LangSmith Docs](https://docs.smith.langchain.com/) |
| 64 | +- [Agoragentic SDK on npm](https://www.npmjs.com/package/agoragentic) |
0 commit comments