docs: update docs page
This commit is contained in:
@@ -6,8 +6,6 @@ export default function CustomTools() {
|
|||||||
<div>
|
<div>
|
||||||
<h1 className="text-4xl font-bold mb-6">自定义工具</h1>
|
<h1 className="text-4xl font-bold mb-6">自定义工具</h1>
|
||||||
|
|
||||||
<BetaNotice />
|
|
||||||
|
|
||||||
<p className="text-xl text-foreground/80 mb-8 leading-relaxed">
|
<p className="text-xl text-foreground/80 mb-8 leading-relaxed">
|
||||||
通过注册自定义工具,扩展 AI Agent 的能力边界。使用 Zod 定义严格的输入接口,让 AI
|
通过注册自定义工具,扩展 AI Agent 的能力边界。使用 Zod 定义严格的输入接口,让 AI
|
||||||
安全调用你的业务逻辑。
|
安全调用你的业务逻辑。
|
||||||
@@ -21,92 +19,40 @@ export default function CustomTools() {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
code={`import { z } from 'zod'
|
code={`import zod from 'zod'
|
||||||
import { pageAgent } from 'page-agent'
|
import { PageAgent, tool } from 'page-agent'
|
||||||
|
|
||||||
// 定义输入 schema
|
// override internal tool
|
||||||
const CreateUserSchema = z.object({
|
const customTools = {
|
||||||
name: z.string().min(1, '姓名不能为空'),
|
ask_user: tool({
|
||||||
email: z.string().email('邮箱格式不正确'),
|
description:
|
||||||
role: z.enum(['admin', 'user', 'guest']).default('user')
|
'Ask the user or parent model a question and wait for their answer. Use this if you need more information or clarification.',
|
||||||
})
|
inputSchema: zod.object({
|
||||||
|
question: zod.string(),
|
||||||
|
}),
|
||||||
|
execute: async function (this: PageAgent, input) {
|
||||||
|
const answer = await do_some_thing(input.question)
|
||||||
|
return "✅ Received user answer: " + answer
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 注册工具
|
// remove internal tool
|
||||||
pageAgent.registerTool({
|
const customTools = {
|
||||||
name: 'createUser',
|
ask_user: null // never ask user questions
|
||||||
description: '创建新用户账户',
|
}
|
||||||
input: CreateUserSchema,
|
|
||||||
execute: async (params) => {
|
const pageAgent = new PageAgent({customTools})
|
||||||
// 执行业务逻辑
|
`}
|
||||||
const response = await fetch('/api/users', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(params)
|
|
||||||
})
|
|
||||||
return await response.json()
|
|
||||||
}
|
|
||||||
})`}
|
|
||||||
language="javascript"
|
language="javascript"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
|
||||||
<h2 className="text-2xl font-bold mb-4">属性详解</h2>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg">
|
|
||||||
<h3 className="text-lg font-semibold text-blue-900 dark:text-blue-300 mb-2">
|
|
||||||
📝 name (必需)
|
|
||||||
</h3>
|
|
||||||
<p className="text-foreground/80 mb-2">工具的唯一标识符,AI 通过此名称调用工具。</p>
|
|
||||||
<div className="bg-white dark:bg-gray-800 rounded p-3 text-sm">
|
|
||||||
<code>name: 'searchProducts' // 驼峰命名,语义清晰</code>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4 bg-green-50 dark:bg-green-900/20 rounded-lg">
|
|
||||||
<h3 className="text-lg font-semibold text-green-900 dark:text-green-300 mb-2">
|
|
||||||
💬 description (必需)
|
|
||||||
</h3>
|
|
||||||
<p className="text-foreground/80 mb-2">详细描述工具功能,帮助 AI 理解使用场景。</p>
|
|
||||||
<div className="bg-white dark:bg-gray-800 rounded p-3 text-sm">
|
|
||||||
<code>description: '根据关键词搜索商品,支持价格区间和分类筛选'</code>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4 bg-purple-50 dark:bg-purple-900/20 rounded-lg">
|
|
||||||
<h3 className="text-lg font-semibold text-purple-900 dark:text-purple-300 mb-2">
|
|
||||||
🔧 input (必需)
|
|
||||||
</h3>
|
|
||||||
<p className="text-foreground/80 mb-2">Zod schema 定义输入参数的类型和验证规则。</p>
|
|
||||||
<div className="bg-white dark:bg-gray-800 rounded p-3 text-sm">
|
|
||||||
<code>{`input: z.object({
|
|
||||||
keyword: z.string().min(1),
|
|
||||||
priceRange: z.object({
|
|
||||||
min: z.number().optional(),
|
|
||||||
max: z.number().optional()
|
|
||||||
}).optional()
|
|
||||||
})`}</code>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="p-4 bg-orange-50 dark:bg-orange-900/20 rounded-lg">
|
|
||||||
<h3 className="text-lg font-semibold text-orange-900 dark:text-orange-300 mb-2">
|
|
||||||
⚡ execute (必需)
|
|
||||||
</h3>
|
|
||||||
<p className="text-foreground/80 mb-2">异步函数,接收验证后的参数并执行具体逻辑。</p>
|
|
||||||
<div className="bg-white dark:bg-gray-800 rounded p-3 text-sm">
|
|
||||||
<code>{`execute: async (params) => {
|
|
||||||
// params 已通过 Zod 验证
|
|
||||||
const result = await businessLogic(params)
|
|
||||||
return result // 返回结果给 AI
|
|
||||||
}`}</code>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2 className="text-2xl font-bold mb-4">页面过滤器</h2>
|
<h2 className="text-2xl font-bold mb-4">页面过滤器</h2>
|
||||||
|
|
||||||
|
<BetaNotice />
|
||||||
|
|
||||||
<p className="text-foreground/80 mb-4">
|
<p className="text-foreground/80 mb-4">
|
||||||
通过 <code className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">pageFilter</code>{' '}
|
通过 <code className="bg-gray-200 dark:bg-gray-700 px-2 py-1 rounded">pageFilter</code>{' '}
|
||||||
属性控制工具在哪些页面可见,提升安全性和用户体验。
|
属性控制工具在哪些页面可见,提升安全性和用户体验。
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ export default function ModelIntegration() {
|
|||||||
<div>
|
<div>
|
||||||
<h1 className="text-4xl font-bold mb-6">模型接入</h1>
|
<h1 className="text-4xl font-bold mb-6">模型接入</h1>
|
||||||
|
|
||||||
<BetaNotice />
|
|
||||||
|
|
||||||
<p className="text-xl text-gray-600 dark:text-gray-300 mb-6 leading-relaxed">
|
<p className="text-xl text-gray-600 dark:text-gray-300 mb-6 leading-relaxed">
|
||||||
当前支持符合 OpenAI 接口规范且支持 tool call 的模型,包括公有云服务和私有部署方案。
|
当前支持符合 OpenAI 接口规范且支持 tool call 的模型,包括公有云服务和私有部署方案。
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ export default function QuickStart() {
|
|||||||
<div>
|
<div>
|
||||||
<h1 className="text-4xl font-bold mb-6">Quick Start</h1>
|
<h1 className="text-4xl font-bold mb-6">Quick Start</h1>
|
||||||
|
|
||||||
<BetaNotice />
|
|
||||||
|
|
||||||
<p className=" mb-6 leading-relaxed">几分钟内完成 page-agent 的集成。</p>
|
<p className=" mb-6 leading-relaxed">几分钟内完成 page-agent 的集成。</p>
|
||||||
|
|
||||||
<h2 className="text-2xl font-bold mb-3">安装步骤</h2>
|
<h2 className="text-2xl font-bold mb-3">安装步骤</h2>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export interface UIConfig {
|
|||||||
* }),
|
* }),
|
||||||
* execute: async function (this: PageAgent, input) {
|
* execute: async function (this: PageAgent, input) {
|
||||||
* const answer = await do_some_thing(input.question)
|
* const answer = await do_some_thing(input.question)
|
||||||
* return `✅ Received user answer: ${answer}` + (await getSystemInfo())
|
* return `✅ Received user answer: ${answer}`
|
||||||
* },
|
* },
|
||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
|
|||||||
Reference in New Issue
Block a user