lucid-agent-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreating Agents with Agents
创建Lucid Agent
This skill teaches you how to create Lucid agents with JavaScript handler code.
本技能将教你如何使用JavaScript处理程序代码创建Lucid Agent。
When to Use
适用场景
Use this skill when creating Lucid agents with inline JavaScript handlers. Agents are hosted on the Lucid platform and can be invoked immediately after creation. No generate API - you write the JS handler code yourself. No self-hosting required.
当你需要创建带有内嵌JavaScript处理程序的Lucid Agent时,可使用本技能。Agent将托管在Lucid平台上,创建完成后即可立即调用。无需使用生成API——你可以自行编写JS处理程序代码,且无需自行托管。
Three Options for Creating Agents
创建Agent的三种方式
Option 1: MCP Tool with Server Wallet (SIWE)
方式一:搭配服务器钱包(SIWE)的MCP工具
Use the MCP tool with Sign In With Ethereum (SIWE):
create_lucid_agentbash
undefined使用 MCP工具结合Sign In With Ethereum(SIWE):
create_lucid_agentbash
undefinedFirst, ensure you're authenticated via SIWE in your MCP client
首先,确保你已在MCP客户端中通过SIWE完成身份验证
Your server wallet will be used for setup payment and authentication
你的服务器钱包将用于设置支付和身份验证
Then use the MCP tool
然后使用MCP工具
create_lucid_agent({
slug: "my-agent",
name: "My Agent",
description: "Agent description",
entrypoints: [{
key: "chat",
description: "Chat endpoint",
handlerType: "js",
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };"
},
price: "10000" // 0.01 USDC
}]
})
The MCP tool automatically handles:
- Setup payment (if agent has paid entrypoints)
- SIWE authentication with your server wallet
- x402 payment signature generation
- Agent creation with PAYMENT-SIGNATURE headercreate_lucid_agent({
slug: "my-agent",
name: "My Agent",
description: "Agent description",
entrypoints: [{
key: "chat",
description: "Chat endpoint",
handlerType: "js",
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };"
},
price: "10000" // 0.01 USDC
}]
})
MCP工具会自动处理以下内容:
- 设置支付(若Agent包含付费入口点)
- 使用服务器钱包完成SIWE身份验证
- 生成x402支付签名
- 携带PAYMENT-SIGNATURE头创建AgentOption 2: SDK as Signer (Your Own Wallet)
方式二:作为签名者的SDK(使用个人钱包)
Use the Lucid Agents SDK with your own wallet:
typescript
import { createX402Payment } from '@lucid-agents/payments';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
const account = privateKeyToAccount(`0x${WALLET_PRIVATE_KEY}`);
// Step 1: Setup payment (for paid agents)
const setupPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents/setup-payment',
description: 'Agent setup payment',
mimeType: 'application/json',
},
amount: '10000', // 0.01 USDC setup fee
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // USDC
payTo: '0xPlatformWallet', // Platform wallet
});
await fetch('https://api.daydreams.systems/api/agents/setup-payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(setupPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
network: 'eip155:84532',
facilitatorUrl: 'https://facilitator.daydreams.systems',
}),
});
// Step 2: Create agent with wallet auth
const createPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents',
description: 'Agent creation',
mimeType: 'application/json',
},
amount: '0', // Free for auth
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
payTo: account.address,
});
const response = await fetch('https://api.daydreams.systems/api/agents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(createPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
name: 'My Agent',
description: 'Agent description',
entrypoints: [{
key: 'chat',
description: 'Chat endpoint',
handlerType: 'js',
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };",
},
price: '10000',
}],
}),
});
const agent = await response.json();使用Lucid Agents SDK搭配你自己的钱包:
typescript
import { createX402Payment } from '@lucid-agents/payments';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
const account = privateKeyToAccount(`0x${WALLET_PRIVATE_KEY}`);
// 步骤1:设置支付(针对付费Agent)
const setupPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents/setup-payment',
description: 'Agent setup payment',
mimeType: 'application/json',
},
amount: '10000', // 0.01 USDC 安装费用
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // USDC
payTo: '0xPlatformWallet', // 平台钱包
});
await fetch('https://api.daydreams.systems/api/agents/setup-payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(setupPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
network: 'eip155:84532',
facilitatorUrl: 'https://facilitator.daydreams.systems',
}),
});
// 步骤2:使用钱包身份验证创建Agent
const createPayment = await createX402Payment({
account,
chain: baseSepolia,
resource: {
url: 'https://api.daydreams.systems/api/agents',
description: 'Agent creation',
mimeType: 'application/json',
},
amount: '0', // 身份验证免费
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
payTo: account.address,
});
const response = await fetch('https://api.daydreams.systems/api/agents', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'PAYMENT-SIGNATURE': btoa(JSON.stringify(createPayment)),
},
body: JSON.stringify({
slug: 'my-agent',
name: 'My Agent',
description: 'Agent description',
entrypoints: [{
key: 'chat',
description: 'Chat endpoint',
handlerType: 'js',
handlerConfig: {
code: "return { message: 'Hello from ' + input.name };",
},
price: '10000',
}],
}),
});
const agent = await response.json();Option 3: Viem with Custom Signing
方式三:基于Viem的自定义签名
Write your own signing logic using viem directly. See and in the lucid-client repo for complete examples.
scripts/create-agent-with-payment-auth.tsscripts/test-setup-payment-x402.ts直接使用viem编写你自己的签名逻辑。完整示例可查看lucid-client仓库中的和文件。
scripts/create-agent-with-payment-auth.tsscripts/test-setup-payment-x402.tsJS Handler Code Contract
JS处理程序代码约定
Execution Environment
执行环境
- Code runs as in a VM sandbox
(async () => { ${code} })() - Globals available:
- : The request body’s
inputfield (the entrypoint payload). Clients must POSTinput; that{ "input": <payload> }is what handlers see as<payload>.input - : Standard console object for logging
console - : Only available if
fetchis sethandlerConfig.network.allowedHosts
- Not available: ,
require,import, Node.js APIs, or any other Node modulesprocess
- 代码将在VM沙箱中以的形式运行
(async () => { ${code} })() - 可用全局变量:
- : 请求体中的
input字段(即入口点负载)。客户端必须以input的格式发送POST请求;{ "input": <payload> }即为处理程序中<payload>变量的内容。input - : 标准控制台对象,用于日志输出
console - : 仅当设置了
fetch时可用handlerConfig.network.allowedHosts
- 不可用内容: 、
require、import、Node.js API或任何其他Node模块process
Return Value
返回值
- Return any JSON-serializable value
- That return value becomes the field in the response
output - The platform automatically sets for JS handlers
usage: { total_tokens: 0 }
- 可返回任何可JSON序列化的值
- 返回值将作为响应中的字段
output - 平台会自动为JS处理程序设置
usage: { total_tokens: 0 }
Timeout
超时设置
- Default timeout: 1000 ms (1 second)
- Override via (must be positive integer)
handlerConfig.timeoutMs
- 默认超时时间: 1000毫秒(1秒)
- 可通过覆盖默认值(必须为正整数)
handlerConfig.timeoutMs
Fetch / Network Access
网络访问(Fetch)
When your handler needs to make outbound HTTP requests:
- Set to an array of allowed hosts
handlerConfig.network.allowedHosts - Use to allow any host (not recommended for security)
["*"] - Use specific hosts: or wildcards:
["api.example.com"]["*.example.com"] - Optional: Set for network request timeout
handlerConfig.network.timeoutMs
Important: If is not set, will not be available in the handler code.
allowedHostsfetch当你的处理程序需要发起外部HTTP请求时:
- 将设置为允许访问的主机数组
handlerConfig.network.allowedHosts - 使用允许访问所有主机(出于安全考虑不推荐)
["*"] - 指定具体主机:或使用通配符:
["api.example.com"]["*.example.com"] - 可选:设置配置网络请求超时时间
handlerConfig.network.timeoutMs
重要提示: 若未设置,处理程序代码中将无法使用。
allowedHostsfetchCommon mistakes
常见错误
- Do not use . Only
ctxexists in the sandbox. Useinput(e.g.input), notinput.text.ctx.input - Do not return . Return only the output value. The platform sets
{ output, usage }andoutputautomatically.usage
- 不要使用。沙箱中仅存在
ctx变量。请使用input(例如input),而非input.text。ctx.input - 不要返回。只需返回输出值即可。平台会自动设置
{ output, usage }和output字段。usage
Examples
示例
Simple echo handler:
javascript
return { echoed: input };Echo a specific field:
javascript
return { text: input.text };Handler with fetch:
javascript
const res = await fetch(`https://api.example.com/data?q=${encodeURIComponent(input.q)}`);
const data = await res.json();
return data;Handler with timeout override:
javascript
// This handler might take longer, so we override the timeout
// Note: timeoutMs is set in handlerConfig, not in the code itself
return await someSlowOperation(input);简单回显处理程序:
javascript
return { echoed: input };回显指定字段:
javascript
return { text: input.text };包含Fetch的处理程序:
javascript
const res = await fetch(`https://api.example.com/data?q=${encodeURIComponent(input.q)}`);
const data = await res.json();
return data;自定义超时的处理程序:
javascript
// 该处理程序可能耗时较长,因此我们覆盖默认超时时间
// 注意:timeoutMs需在handlerConfig中设置,而非代码内部
return await someSlowOperation(input);Creating Agents with create_lucid_agent
MCP Tool
create_lucid_agent使用create_lucid_agent
MCP工具创建Agent
create_lucid_agentPrerequisites
前提条件
- You must be connected via xgate MCP (Cursor/Claude)
- The user must have configured their server wallet (via SIWE)
- The server wallet will be used for setup-payment and payment-as-auth
- 你必须通过xgate MCP(Cursor/Claude)连接
- 用户必须已配置服务器钱包(通过SIWE)
- 服务器钱包将用于设置支付和支付式身份验证
Tool Inputs
工具输入参数
The tool accepts:
create_lucid_agent- (string, required): URL-friendly unique identifier (lowercase alphanumeric with hyphens, 1-64 chars)
slug - (string, required): Human-readable name (1-128 chars)
name - (string, optional): Human-readable description (max 1024 chars, defaults to "")
description - (array, required, min 1): Array of entrypoint objects:
entrypoints- (string, required, 1-64 chars): Unique entrypoint identifier
key - (string, optional, max 512 chars): Optional description
description - (string, required): Must be
handlerType"js" - (object, required):
handlerConfig- (string, required): JavaScript handler code (max 100KB)
code - (number, optional, positive): Override default 1000ms timeout
timeoutMs - (object, optional):
network- (array of strings, optional): Allowed hosts for fetch
allowedHosts - (number, optional, positive): Network request timeout
timeoutMs
- (object, optional): Valid JSON Schema object for input validation
inputSchema - (object, optional): Valid JSON Schema object for output validation
outputSchema - (string, optional): Price in smallest unit (e.g., "1000" = 0.001 USDC if 6 decimals)
price - Note: Entrypoint-level field (for payment network) is not accepted. All agents use Ethereum mainnet.
network
- (object, optional): ERC-8004 identity configuration:
identityConfig- (number, optional): Chain ID for ERC-8004 registry (defaults to Ethereum mainnet: 1)
chainId - (string, optional): RPC URL for blockchain connection
rpcUrl - (string, optional): ERC-8004 registry contract address
registryAddress - (boolean, optional): Whether to automatically register identity if not found
autoRegister - (array of strings, optional): Trust models to advertise
trustModels - (object, optional): Custom trust config overrides
trustOverrides
Important:
- Do not include - the backend sets it automatically (defaults to "1.0.0")
version - Do not provide or see the Lucid API base URL - that is MCP config only
- Entrypoint-level fields are not accepted - all agents use Base network
network
create_lucid_agent- (字符串,必填):URL友好的唯一标识符(小写字母数字加连字符,长度1-64字符)
slug - (字符串,必填):人类可读的名称(长度1-128字符)
name - (字符串,可选):人类可读的描述(最大1024字符,默认为空)
description - (数组,必填,最少1个):入口点对象数组:
entrypoints- (字符串,必填,1-64字符):唯一的入口点标识符
key - (字符串,可选,最大512字符):可选描述
description - (字符串,必填):必须为
handlerType"js" - (对象,必填):
handlerConfig- (字符串,必填):JavaScript处理程序代码(最大100KB)
code - (数字,可选,正整数):覆盖默认1000毫秒超时时间
timeoutMs - (对象,可选):
network- (字符串数组,可选):允许fetch访问的主机列表
allowedHosts - (数字,可选,正整数):网络请求超时时间
timeoutMs
- (对象,可选):用于输入验证的合法JSON Schema对象
inputSchema - (对象,可选):用于输出验证的合法JSON Schema对象
outputSchema - (字符串,可选):最小单位计价(例如,若USDC有6位小数,则"1000"代表0.001 USDC)
price - 注意:入口点级别的字段(用于支付网络)不被接受。所有Agent均使用以太坊主网。
network
- (对象,可选):ERC-8004身份配置:
identityConfig- (数字,可选):ERC-8004注册表的链ID(默认为以太坊主网:1)
chainId - (字符串,可选):区块链连接的RPC URL
rpcUrl - (字符串,可选):ERC-8004注册表合约地址
registryAddress - (布尔值,可选):若未找到身份,是否自动注册
autoRegister - (字符串数组,可选):要声明的信任模型
trustModels - (对象,可选):自定义信任配置覆盖
trustOverrides
重要提示:
- 无需包含字段——后端会自动设置(默认为"1.0.0")
version - 无需提供或查看Lucid API基础URL——这属于MCP配置内容
- 入口点级别的字段不被接受——所有Agent均使用Base网络
network
PaymentsConfig for Paid Agents
付费Agent的PaymentsConfig配置
When any entrypoint has a , the agent must have . The tool builds this automatically:
pricepaymentsConfig- : Creator's server wallet address (receives invoker payments)
payTo - :
network(Ethereum mainnet)"ethereum" - :
facilitatorUrl(hardcoded)"https://facilitator.daydreams.systems"
Conflict: If you create an agent with paid entrypoints but without , the agent will be created but invocations won't charge users. The tool automatically adds when any entrypoint has a price, so this conflict shouldn't occur when using the tool correctly.
paymentsConfigpaymentsConfigSetup Fee: For agents with paid entrypoints, a one-time setup fee is paid from the server wallet (USDC). The tool handles this automatically via the setup-payment flow.
当任何入口点设置了时,Agent必须包含。工具会自动生成该配置:
pricepaymentsConfig- : 创建者的服务器钱包地址(接收调用者支付的费用)
payTo - :
network(以太坊主网)"ethereum" - :
facilitatorUrl(硬编码值)"https://facilitator.daydreams.systems"
冲突说明: 若你创建了带有付费入口点但未设置的Agent,Agent将被创建,但调用时不会向用户收费。当使用工具正确创建时,工具会在存在付费入口点时自动添加,因此不会出现此冲突。
paymentsConfigpaymentsConfig安装费用: 对于带有付费入口点的Agent,需从服务器钱包支付一次性安装费用(USDC)。工具会通过安装支付流程自动处理此操作。
IdentityConfig (Optional)
IdentityConfig(可选)
You can pass for ERC-8004 identity:
identityConfig- The tool forwards it to the create payload
- Important: Auto-registration at create time requires an agent wallet ()
walletsConfig.agent - The MCP tool does not set
walletsConfig.agent - So when creating via MCP, is stored and can be used later:
identityConfig- Add agent wallet in the dashboard
- Retry identity registration via the dashboard
你可以传入用于ERC-8004身份配置:
identityConfig- 工具会将其转发到创建请求的负载中
- 重要提示: 创建时自动注册身份需要Agent钱包()
walletsConfig.agent - MCP工具不会设置
walletsConfig.agent - 因此通过MCP创建时,会被存储,后续可通过以下方式使用:
identityConfig- 在控制台中添加Agent钱包
- 通过控制台重试身份注册
Flow
流程
-
Setup-payment (only if any entrypoint has):
price- Tool calls setup-payment endpoint
- Receives 402 with PAYMENT-REQUIRED header
- Signs payment with server wallet
- Retries with PAYMENT-SIGNATURE header
- Continues when payment is verified
-
Create:
- Tool calls create endpoint with agent definition
- Sends same PAYMENT-SIGNATURE for payment-as-auth
- Agent is created and immediately invokable
-
Return:
- Tool returns agent object with ,
id,slug,name,description, and other fieldsinvokeUrl
- Tool returns agent object with
-
安装支付(仅当存在付费入口点时):
- 工具调用安装支付端点
- 收到带有PAYMENT-REQUIRED头的402响应
- 使用服务器钱包签署支付信息
- 携带PAYMENT-SIGNATURE头重试请求
- 支付验证通过后继续执行
-
创建Agent:
- 工具携带Agent定义调用创建端点
- 发送相同的PAYMENT-SIGNATURE用于支付式身份验证
- Agent创建完成后可立即调用
-
返回结果:
- 工具返回包含、
id、slug、name、description及其他字段的Agent对象invokeUrl
- 工具返回包含
Invoking created agents
调用已创建的Agent
POST to (or ). Request body must wrap the entrypoint payload in :
invokeUrlPOST /agents/{agentId}/entrypoints/{key}/invokeinputjson
{ "input": { "text": "Hello" } }Optional: , . The handler receives the value as the global.
sessionIdmetadatainputinput向(或)发送POST请求。请求体必须将入口点负载包裹在中:
invokeUrlPOST /agents/{agentId}/entrypoints/{key}/invokeinputjson
{ "input": { "text": "Hello" } }可选参数: 、。处理程序会将值作为全局变量接收。
sessionIdmetadatainputinputError Handling
错误处理
The tool handles various error scenarios:
- 400 (Validation error): "Validation failed: {details}"
- 409 (Slug exists): "Agent slug '{slug}' already exists. Please try a different slug."
- 402 (Payment failed): "Payment failed: {details}. Please ensure your server wallet has sufficient USDC."
- Insufficient funds: "Insufficient funds in server wallet. Please add USDC to your server wallet and try again."
- Lucid API down: "Lucid API is currently unavailable. Please try again later."
- Network timeout: "Request timed out. Please try again."
- Invalid JS code: "Invalid JavaScript code: {error details}"
- Invalid input schema: "Invalid input: {validation error}"
工具会处理多种错误场景:
- 400(验证错误): "验证失败:{详细信息}"
- 409(Slug已存在): "Agent slug '{slug}'已存在,请尝试其他slug。"
- 402(支付失败): "支付失败:{详细信息}。请确保你的服务器钱包中有足够的USDC。"
- 余额不足: "服务器钱包余额不足,请为服务器钱包充值USDC后重试。"
- Lucid API不可用: "Lucid API当前不可用,请稍后重试。"
- 网络超时: "请求超时,请稍后重试。"
- 无效JS代码: "无效的JavaScript代码:{错误详情}"
- 无效输入Schema: "无效输入:{验证错误}"
Example Usage
示例用法
javascript
// Create a simple echo agent
await create_lucid_agent({
slug: "echo-agent",
name: "Echo Agent",
description: "Echoes input back",
entrypoints: [
{
key: "echo",
description: "Echo the input",
handlerType: "js",
handlerConfig: {
code: "return { echoed: input };"
}
}
]
});
// Create a paid agent with fetch
await create_lucid_agent({
slug: "weather-agent",
name: "Weather Agent",
description: "Fetches weather data",
entrypoints: [
{
key: "get-weather",
description: "Get weather by city",
handlerType: "js",
handlerConfig: {
code: `
const res = await fetch(\`https://api.weather.com/data?city=\${encodeURIComponent(input.city)}\`);
const data = await res.json();
return data;
`,
network: {
allowedHosts: ["api.weather.com"]
}
},
price: "1000" // 0.001 USDC
}
]
});
// Create agent with identity config
await create_lucid_agent({
slug: "identity-agent",
name: "Identity Agent",
description: "Agent with ERC-8004 identity",
entrypoints: [
{
key: "process",
handlerType: "js",
handlerConfig: {
code: "return { result: input };"
}
}
],
identityConfig: {
chainId: 1, // Ethereum mainnet
autoRegister: true,
trustModels: ["feedback", "inference-validation"]
}
});javascript
// 创建一个简单的回显Agent
await create_lucid_agent({
slug: "echo-agent",
name: "Echo Agent",
description: "Echoes input back",
entrypoints: [
{
key: "echo",
description: "Echo the input",
handlerType: "js",
handlerConfig: {
code: "return { echoed: input };"
}
}
]
});
// 创建一个支持网络请求的付费Agent
await create_lucid_agent({
slug: "weather-agent",
name: "Weather Agent",
description: "Fetches weather data",
entrypoints: [
{
key: "get-weather",
description: "Get weather by city",
handlerType: "js",
handlerConfig: {
code: `
const res = await fetch(\`https://api.weather.com/data?city=\${encodeURIComponent(input.city)}\`);
const data = await res.json();
return data;
`,
network: {
allowedHosts: ["api.weather.com"]
}
},
price: "1000" // 0.001 USDC
}
]
});
// 创建带有身份配置的Agent
await create_lucid_agent({
slug: "identity-agent",
name: "Identity Agent",
description: "Agent with ERC-8004 identity",
entrypoints: [
{
key: "process",
handlerType: "js",
handlerConfig: {
code: "return { result: input };"
}
}
],
identityConfig: {
chainId: 1, // 以太坊主网
autoRegister: true,
trustModels: ["feedback", "inference-validation"]
}
});Code Contract Documentation
代码约定文档
For more details on the JS handler code contract, see:
- Runtime implementation:
packages/hono-runtime/src/runtime/workers/js-worker.ts - Handler implementation:
packages/hono-runtime/src/handlers/js.ts - OpenAPI schema: (SerializedEntrypointSchema)
packages/hono-runtime/src/openapi/schemas.ts
如需了解JS处理程序代码约定的更多细节,请查看:
- 运行时实现:
packages/hono-runtime/src/runtime/workers/js-worker.ts - 处理程序实现:
packages/hono-runtime/src/handlers/js.ts - OpenAPI Schema:(SerializedEntrypointSchema)
packages/hono-runtime/src/openapi/schemas.ts
Guide for Humans and Agents
人类与Agent操作指南
See GUIDE.md for the complete end-to-end flow: setup AI → xgate MCP + server wallet (SIWE) → install skill → prompt agent → create_lucid_agent → hosted agent.
完整的端到端流程请查看GUIDE.md:设置AI → xgate MCP + 服务器钱包(SIWE)→ 安装技能 → 提示Agent → create_lucid_agent → 托管Agent。