instrument-existing-agent-with-prefactor-sdk
Instrument Existing Agent With Prefactor SDK
Instrument a working agent that was built without Prefactor.
Core principle: instrument boundaries, not business logic.
Quick Start
- Bootstrap Prefactor resources with
skills/bootstrap-existing-agent-with-prefactor-cli/SKILL.md. - Install required Prefactor packages with the project's existing package manager (
bun,npm,pnpm, oryarn). - Identify runtime path: built-in adapter (
@prefactor/langchain,@prefactor/ai,@prefactor/openclaw) or custom@prefactor/coreadapter. - Add one top-level run span and child spans around LLM/tool boundaries.
- Preserve context propagation and package-prefixed span types.
- Record error metadata and rethrow original errors.
- Finish spans on success, error, cancel, and stream terminal paths.
- Verify in your project's build/test/typecheck flow.
Prerequisite
More from prefactordev/typescript-sdk
prefactor-skill-selector
Use when choosing which Prefactor SDK skill to load for agent instrumentation or for building a custom provider integration on top of @prefactor/core.
37create-provider-package-with-core
Use when building a custom provider integration on top of @prefactor/core so your app can instrument agent, llm, and tool workflows without relying on a prebuilt adapter package.
35bootstrap-existing-agent-with-prefactor-cli
Use when an existing agent needs Prefactor resources created via the Prefactor CLI before SDK instrumentation is added.
32report-agent-risk-data
Use when an agent is already instrumented with Prefactor and you need to populate data_risk fields on its span types to enable compliance tracking and data governance.
5ai-sdk
Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat".
2caveman
>
1