bootstrap-existing-agent-with-prefactor-cli
Bootstrap Existing Agent With Prefactor CLI
Set up Prefactor resources for an already-working agent before instrumentation code changes.
Core principle: provision first, instrument second.
Coding Assistant Usage
Apply this skill first when the user asks to:
- "set up Prefactor for this existing agent"
- "create Prefactor environment/agent/instance"
- "use CLI to bootstrap Prefactor"
- "prepare IDs and env vars before instrumentation"
After this skill completes:
- If provider is supported, continue with
skills/instrument-existing-agent-with-prefactor-sdk/SKILL.md. - If provider is unsupported, continue with
skills/create-provider-package-with-core/SKILL.md. - Return a copy/paste block with exported env vars and the selected package.
Inputs You Need
- Prefactor API token (for CLI profile)
- Base URL (optional, defaults to Prefactor cloud)
- Account ID
- Target provider/framework (
langchain,ai,openclaw, or custom) - Human-readable names for environment and agent
- Working directory to store config (recommended: repo root)
CLI Workflow
Before running CLI commands, choose package first, then install required Prefactor package(s).
- Use whichever package manager the project already uses (
bun,npm,pnpm, oryarn). - Install
@prefactor/clifor bootstrap commands.
prefactor command requirement:
- The
prefactorcommand comes from the npm package@prefactor/cli. - If the command is not globally available, run it via the package manager launcher (
bunx @prefactor/cli,npx @prefactor/cli,pnpm dlx @prefactor/cli, oryarn dlx @prefactor/cli). - Use
prefactor helporprefactor <group> helpfor command details.
Examples:
# bun
bun add @prefactor/cli
# npm
npm install @prefactor/cli
# pnpm
pnpm add @prefactor/cli
# yarn
yarn add @prefactor/cli
Run these in order:
prefactor profiles add default [base-url] --api-token <api-token>
prefactor accounts list
prefactor environments create --name <env-name> --account_id <account-id>
prefactor agents create --name <agent-name> --environment_id <environment-id>
prefactor agent_instances register \
--agent_id <agent-id> \
--agent_version_external_identifier <agent-version-id> \
--agent_version_name <agent-version-name> \
--agent_schema_version_external_identifier <schema-version-id> \
--update_current_version
Profile notes:
<profile-name>is any key likedefault,staging, orprod.- Select profile with
--profile <name>. - When using launchers, prefix commands consistently (for example
npx @prefactor/cli profiles add ...).
Config resolution notes:
- CLI config resolution order is:
./prefactor.json~/.prefactor/prefactor.json- if none exists, profile creation writes
./prefactor.json
- Global CLI install does not make config global; command working directory still controls which config file is used.
Collect and persist these IDs from command output:
environment_idagent_idagent_instance_id
Package Selection
Choose package by provider:
- LangChain ->
@prefactor/langchain - AI SDK ->
@prefactor/ai - OpenClaw ->
@prefactor/openclaw - Custom/unsupported provider -> use
skills/create-provider-package-with-core/SKILL.md
When handing off to SDK instrumentation, import helpers from that selected package directly, for example:
import { init, withSpan, shutdown } from '@prefactor/ai';
// or '@prefactor/langchain'
Do not mix adapter init with withSpan/shutdown from @prefactor/core unless an explicit tracer is passed.
This guidance targets adapter-style integrations (@prefactor/ai, @prefactor/langchain) and does not change @prefactor/openclaw plugin runtime behavior.
If you have identified and selected an existing package, use skills/instrument-existing-agent-with-prefactor-sdk/SKILL.md
Runtime Environment Variables
Produce this output for the user after setup:
export PREFACTOR_API_URL="<api-url>"
export PREFACTOR_API_TOKEN="<api-token>"
export PREFACTOR_AGENT_ID="<agent-id>"
Use the created agent_id for PREFACTOR_AGENT_ID.
Verification
- Confirm CLI commands succeeded without HTTP/auth errors.
- Confirm IDs were returned and captured.
- Confirm package selection matches provider.
- Confirm env vars match created resources.
- Confirm
prefactor.jsonis ignored by git (git check-ignore prefactor.json,git status --short).
Common Mistakes
- Instrumenting code before creating Prefactor resources.
- Using account ID where environment ID is required.
- Forgetting to propagate created
agent_idtoPREFACTOR_AGENT_ID. - Picking
@prefactor/coredirectly when a built-in adapter exists. - Running commands from the wrong directory and reading/writing the wrong
prefactor.json. - Committing
prefactor.json(contains API tokens).
More from prefactordev/typescript-sdk
instrument-existing-agent-with-prefactor-sdk
Use when an existing agent already works without Prefactor and you need to add tracing for runs, llm calls, tool calls, and failures with minimal behavior changes.
39prefactor-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.
35report-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