feat(ai): add chart auto mode preference

This commit is contained in:
digua committed 2026-06-10 00:15:25 +08:00
1 parent 84a3b13017
commit 1290ae6569
20 files changed
+225 -57

No files matched your search

+12 -8
View File
@@ -16,6 +16,7 @@ import {
resolveChartRuntimeForRequest,
} from '@openchatlab/node-runtime'
import { getChatOverview, normalizeBuiltinToolNames } from '@openchatlab/core'
import type { ChartAutoMode } from '@openchatlab/shared-types'
import type { DataSnapshot } from '@openchatlab/node-runtime'
import type { AgentStreamRequest } from '@openchatlab/http-routes'
import { AGENT_TOOL_REGISTRY } from '@openchatlab/tools'
@@ -75,6 +76,7 @@ export function createCliRunAgentStream(
assistantId,
skillId,
enableAutoSkill,
chartAutoMode,
compressionConfig,
ownerInfo,
mentionedMembers,
@@ -99,17 +101,18 @@ export function createCliRunAgentStream(
const maxToolResultTokens = Math.floor(contextWindow * (maxToolResultPercent / 100))
const db = (dbManager as any).open?.(sessionId)
const resolvedChartAutoMode: ChartAutoMode = chartAutoMode ?? 'suggest'
const chartRuntime = resolveChartRuntimeForRequest({
skillId,
userMessage,
locale,
assistantAllowedTools,
enableAutoDetection: enableAutoSkill === true,
enableAnalyticalAutoDetection: enableAutoSkill === true,
chartAutoMode: resolvedChartAutoMode,
})
const isChartCapability = chartRuntime.isChartCapability
const autoSkillAllowedTools =
!skillId && enableAutoSkill
!skillId && enableAutoSkill && resolvedChartAutoMode !== 'explicit'
? getAllowedBuiltinToolsForChartAutoSkill(assistantAllowedTools)
: assistantAllowedTools
const allowedToolSet = getAllowedToolSet(
@@ -135,11 +138,9 @@ export function createCliRunAgentStream(
const def = skillMgr.getSkillConfig(skillId)
if (def) resolvedSkillDef = { name: def.name, prompt: def.prompt }
} else if (enableAutoSkill) {
const menu = buildSkillMenuWithBuiltinChart(
skillMgr.getSkillMenu(chatType ?? 'group', toolNames),
locale,
toolNames
)
const baseMenu = skillMgr.getSkillMenu(chatType ?? 'group', toolNames)
const menu =
resolvedChartAutoMode === 'aggressive' ? buildSkillMenuWithBuiltinChart(baseMenu, locale, toolNames) : baseMenu
if (menu) resolvedSkillMenu = menu
}
@@ -150,7 +151,9 @@ export function createCliRunAgentStream(
coreToolNames: new Set<string>(CHART_CAPABILITY_CORE_TOOLS),
locale,
getSkillConfig: (id) =>
getSkillConfigWithBuiltinChart(id, locale, (skillConfigId) => skillMgr.getSkillConfig(skillConfigId)),
resolvedChartAutoMode === 'aggressive'
? getSkillConfigWithBuiltinChart(id, locale, (skillConfigId) => skillMgr.getSkillConfig(skillConfigId))
: skillMgr.getSkillConfig(id),
})
agentTools.push(activateSkillTool as any)
}
@@ -192,6 +195,7 @@ export function createCliRunAgentStream(
mentionedMembers,
dataSnapshot,
thinkingLevel,
chartAutoMode: resolvedChartAutoMode,
})
}
}
+12 -3
View File
@@ -19,6 +19,7 @@ import {
createCompressionLlmAdapter,
AgentEventHandler,
formatAIError,
shouldUseChartCapabilityForMessage,
getChartPlannerCapabilityForMessage,
initTokenizer,
type AgentStreamChunk,
@@ -31,6 +32,7 @@ import {
type OwnerInfo,
type MentionedMember,
} from '@openchatlab/node-runtime'
import type { ChartAutoMode } from '@openchatlab/shared-types'
import { getDefaultAssistantConfig, buildPiModel } from './llm-config'
import { getServerAiLogger } from './logger'
@@ -56,6 +58,7 @@ export interface RunAgentOptions {
mentionedMembers?: MentionedMember[]
dataSnapshot?: DataSnapshot
thinkingLevel?: string
chartAutoMode?: ChartAutoMode
}
export async function runServerAgent(options: RunAgentOptions): Promise<void> {
@@ -78,6 +81,7 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
mentionedMembers,
dataSnapshot,
thinkingLevel,
chartAutoMode = 'suggest',
} = options
const aiLogger = getServerAiLogger()
@@ -168,6 +172,10 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
const steerMessage = t('ai.agent.answerWithoutTools')
let cachedMessages: PiMessage[] = []
const effectiveTools =
chartAutoMode === 'explicit' && !shouldUseChartCapabilityForMessage(userMessage)
? tools.filter((tool) => tool.name !== 'render_chart')
: tools
try {
const routeInput = {
@@ -175,12 +183,13 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
chatType,
locale,
dataSnapshot,
availableTools: tools.map((tool) => tool.name),
availableTools: effectiveTools.map((tool) => tool.name),
availableCapabilities: [
getChartPlannerCapabilityForMessage({
userMessage,
locale,
availableTools: tools.map((tool) => tool.name),
availableTools: effectiveTools.map((tool) => tool.name),
chartAutoMode,
}),
].filter((capability) => capability !== null),
skillSummary: skillDef?.name ?? (skillMenu ? 'auto_skill_menu' : undefined),
@@ -239,7 +248,7 @@ export async function runServerAgent(options: RunAgentOptions): Promise<void> {
piModel,
apiKey: llmConfig.apiKey,
systemPrompt: effectiveSystemPrompt,
tools,
tools: effectiveTools,
history,
userMessage,
maxToolRounds: DEFAULT_MAX_TOOL_ROUNDS,
+1
View File
@@ -256,6 +256,7 @@ export async function runChatTurn(
chatType: 'group',
locale: options.locale ?? 'zh-CN',
enableAutoSkill: true,
chartAutoMode: 'suggest',
},
(chunk: AgentStreamChunk) => {
if (options.includeEvents) {