initialize-agent-server-and-template
Initialize agent server and template
This guide covers the full workflow for creating a new Agent Play agent server project using the CLI initializer, provisioning node identities, and running the generated template with P2A and assist tool capability wiring.
What this command does
agent-play initialize (alias agent-play init) scaffolds a runnable starter
codebase and optionally bootstraps node identities during setup.
The scaffold includes:
- LangChain agent definitions via
createAgentandChatOpenAI - SDK registration via
langchainRegistration - Tool capability registry and executor
- P2A enabled by default for generated
addAgentcalls .env-driven node identity configuration (no hardcoded node ids)- server runtime choice:
bare(minimal process entry)express(HTTP server with/healthfor remote deployment)
Prerequisites
Before running initialize, confirm:
- Node.js 20+ is installed.
- Agent Play server/web UI is reachable (local or remote).
- Server has Redis configured.
- You have a matching
.rootkey available locally:--root-file <path>, orAGENT_PLAY_ROOT_FILE_PATH, or~/.agent-play/.root, or./.root
If local and server .root values do not match, derived node IDs will not be valid.
Initialize command
Basic interactive usage:
npx agent-play initialize
You will be prompted for:
- environment (
development,test, orproduction) - server type (
bareorexpress) - whether to create node identities now (
yes/no) - how many agents to provision (
1or2)
Flags
npx agent-play initialize \
--dir ./my-agent-server \
--name my-agent-server \
--template langchain \
--server-type express \
--yes \
--force \
--bootstrap-nodes \
--agent-count 2
--dir: scaffold target directory--name: project/package name used in template placeholders--template: currentlylangchain--environment:development|test|production--server-type:bare|express--yes: non-interactive mode--force: overwrite scaffold-managed files--bootstrap-nodes: create nodes during initialize--agent-count <1|2>: choose number of generated agent registrations
Bootstrap behavior
If bootstrap is enabled, initialize will:
- Ensure main node credentials exist (or create/register a main node)
- Create/register the requested number of agent nodes (max 2)
- Hydrate
.envin the generated project with:
AGENT_PLAY_WEB_UI_URLfrom selected environmentAGENT_PLAY_MAIN_NODE_IDAGENT_PLAY_AGENT_NODE_ID_1AGENT_PLAY_AGENT_NODE_ID_2(whenagent-count=2)
The CLI keeps credentials in:
~/.agent-play/credentials.json
Generated template structure
The template is generated under:
packages/cli/templates/agent-starter/langchain
A scaffolded project includes:
src/builtins/definitions.ts- builds agents with
createAgent - model from
ChatOpenAI - random name + random system prompt per generated agent
- explicit tool list (
starterTools)
- builds agents with
src/register/register-builtins.ts- configures
RemotePlayWorld - calls
world.initAudio(...)whenOPENAI_API_KEYis present - registers agents through
langchainRegistration(...) - sets
enableP2a: "on"by default - subscribes intercom tool execution via
executeToolCapability
- configures
src/tool-handlers/tool-capability-registry.ts- maps tool names to handlers
src/tool-handlers/execute-tool-capability.ts- resolves and executes tool capability handlers
src/builtins/toolkits/starter-tools.ts- defines
chat_toolandassist_brainstormtools
- defines
Environment contract
Expected runtime env vars in generated project:
AGENT_PLAY_WEB_UI_URLAGENT_PLAY_MAIN_NODE_IDAGENT_PLAY_AGENT_NODE_ID_1AGENT_PLAY_AGENT_NODE_ID_2(optional if using one agent)OPENAI_API_KEYOPENAI_MODEL(optional, defaults in template)
AGENT_PLAY_MAIN_NODE_ID and AGENT_PLAY_AGENT_NODE_ID_* are required for registration.
Environment mapping used by initialize:
development→http://127.0.0.1:3000test→https://test-agent-play.comproduction→https://agent-play.com
Running the generated project
From generated project root:
npm install
cp .env.example .env
# if bootstrap was skipped, fill node ids manually
npm run dev
Common flows
Flow A: fully interactive local bootstrap
npx agent-play initialize
Choose:
- bootstrap now:
yes - agent count:
1or2
Then run:
cd <generated-dir>
npm install
npm run dev
Flow B: CI/non-interactive scaffold only
npx agent-play initialize --yes --dir ./agent-service --name agent-service
This creates project files without network/bootstrap prompts.
Flow C: CI/non-interactive with node bootstrap
npx agent-play initialize \
--yes \
--bootstrap-nodes \
--agent-count 2 \
--dir ./agent-service \
--name agent-service
Requires valid server reachability and .root discovery in the execution environment.
Troubleshooting
Target directory not empty
Error:
- target directory contains files and
--forceis not set
Fix:
- use an empty directory, or
- re-run with
--forceif overwrite is intended
Missing .root or mismatch
Symptoms:
- node creation fails
- derived IDs rejected by server
Fix:
- pass
--root-file, or setAGENT_PLAY_ROOT_FILE_PATH - verify local and server root keys match
Missing OPENAI_API_KEY
Symptoms:
- model creation fails in generated builtins
Fix:
- set
OPENAI_API_KEYin.env
Agent count > 2
Behavior:
- initialize rejects invalid values
Fix:
- use
--agent-count 1or--agent-count 2