Commit d9b09684 by Jon Committed by GitHub

feat: Add new PI agent features and update dependencies (#6762)

parent a50a9b92
......@@ -45,6 +45,7 @@ import type { PlanAgentParamsType } from './sub/plan/constants';
import type { AppFormEditFormType } from '@fastgpt/global/core/app/formEdit/type';
import { getLogger, LogCategories } from '../../../../../common/logger';
import { env } from '../../../../../env';
import { dispatchPiAgent } from './piAgent';
export type DispatchAgentModuleProps = ModuleDispatchProps<{
[NodeInputKeyEnum.history]?: ChatItemMiniType[];
......@@ -77,6 +78,11 @@ type Response = DispatchNodeResultType<{
*/
export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise<Response> => {
// pi-agent-core engine: bypass Plan+Step orchestration
if (env.AGENT_ENGINE === 'pi') {
return dispatchPiAgent(props);
}
const MAX_PLAN_ITERATIONS = 10; // 最大规划轮次
let {
......
import { getLLMModel } from '../../../../../ai/model';
type Model = import('@mariozechner/pi-ai').Model<'openai-completions'>;
const aiProxyBaseUrl = process.env.AIPROXY_API_ENDPOINT
? `${process.env.AIPROXY_API_ENDPOINT}/v1`
: undefined;
const defaultBaseUrl = aiProxyBaseUrl || process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
const defaultApiKey = process.env.AIPROXY_API_TOKEN || process.env.CHAT_API_KEY || '';
export function buildPiModel(modelNameOrId?: string, useVision?: boolean): Model {
const cfg = getLLMModel(modelNameOrId);
// requestUrl is the full endpoint (e.g. https://api.deepseek.com/chat/completions).
// pi-ai's openai-completions provider appends /chat/completions automatically,
// so we strip it to get baseUrl.
const rawUrl = cfg?.requestUrl ?? '';
const baseUrl = rawUrl ? rawUrl.replace(/\/chat\/completions$/, '') : defaultBaseUrl;
const apiKey = cfg?.requestAuth || defaultApiKey;
return {
id: cfg?.model ?? 'gpt-4o',
name: cfg?.name ?? cfg?.model ?? 'gpt-4o',
api: 'openai-completions',
provider: 'openai',
baseUrl,
reasoning: cfg?.reasoning ?? false,
input: useVision ? ['text', 'image'] : ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: cfg?.maxContext ?? 128000,
maxTokens: Math.min(cfg?.maxResponse ?? 4096, (cfg?.maxContext ?? 128000) - 2048),
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined,
// Most non-OpenAI endpoints don't support the "developer" role or "store" field.
// Use "max_tokens" instead of OpenAI-specific "max_completion_tokens" for wider
// compatibility with vLLM and other OpenAI-compatible servers.
compat: {
supportsDeveloperRole: false,
supportsStore: false,
maxTokensField: 'max_tokens'
}
};
}
export function getModelApiKey(modelNameOrId?: string): string {
const cfg = getLLMModel(modelNameOrId);
return cfg?.requestAuth || defaultApiKey;
}
......@@ -115,7 +115,10 @@ export const env = createEnv({
// Beta features
// Whether the Skill feature is enabled (frontend entries + backend runtime)
SHOW_SKILL: BoolSchema.default(false)
SHOW_SKILL: BoolSchema.default(false),
// Agent engine selection: 'default' uses the built-in Plan+Step engine, 'pi' uses pi-agent-core
AGENT_ENGINE: z.enum(['default', 'pi']).default('default')
},
emptyStringAsUndefined: true,
runtimeEnv: process.env,
......
......@@ -8,6 +8,8 @@
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.7.2",
"@mariozechner/pi-agent-core": "^0.67.3",
"@mariozechner/pi-ai": "^0.67.3",
"@fastgpt-sdk/sandbox-adapter": "^0.0.36",
"@fastgpt-sdk/otel": "catalog:",
"@fastgpt-sdk/storage": "catalog:",
......
......@@ -192,6 +192,8 @@ MAX_HTML_TRANSFORM_CHARS=
# ==================== Beta features ====================
# 是否展示 Skill 功能入口
SHOW_SKILL=false
# Agent 引擎选择:default(Plan+Step 编排)| pi(pi-agent-core 引擎)
AGENT_ENGINE=default
# ==================== 对话日志推送(可选) ====================
# 日志服务地址
......
......@@ -176,7 +176,9 @@ const nextConfig: NextConfig = {
'bullmq',
'@zilliz/milvus2-sdk-node',
'tiktoken',
'@opentelemetry/api-logs'
'@opentelemetry/api-logs',
'@mariozechner/pi-agent-core',
'@mariozechner/pi-ai'
],
// 优化大库的 barrel exports tree-shaking
experimental: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment