
随着大语言模型(LLM)技术的成熟,企业应用开发正从"云原生"向"AI原生"演进。本文深入解析 ooderAgent 2.3 的AI原生应用开发架构, 重点阐述其独创的"3+1场景架构"——通过云原生协作、知识协作、智能协作三大基础能力,构建面向未来的AI原生业务场景。 文章将从技术原理、架构设计、实现机制三个维度,为开发者提供全面的AI原生应用开发指南。

🔌
result = callAIAPI(input) // 简单的函数调用
🧠
plan = aiOrchestrator.understand(intent) // 智能编排

🎯
用户通过自然语言表达需求,系统自动理解意图并转化为执行计划,无需预设固定流程。
🔄
根据上下文动态选择最优执行路径,而非依赖硬编码的工作流,实现真正的灵活响应。
🧩
业务知识作为系统的一等公民,通过RAG、知识图谱等技术实现知识的自动检索与推理。
📈
系统能够从交互中学习,自动优化决策模型和执行策略,实现自我进化。
ooderAgent 2.3 采用"3+1场景架构",将AI原生应用的复杂性抽象为四个层次: 三层基础能力(云原生协作、知识协作、智能协作)+ 一层业务封装(场景)。

能力维度 | 传统应用 | 云原生应用 | AI原生应用 (ooderAgent 2.3) |
|---|---|---|---|
交互方式 | GUI表单 | API + GUI | 自然语言对话 |
业务逻辑 | 硬编码 | 配置化 | 意图驱动动态生成 |
知识管理 | 外部文档 | 知识库系统 | 内置RAG + 知识图谱 |
决策能力 | 规则引擎 | 规则 + 简单ML | LLM智能决策 |
进化方式 | 版本迭代 | 持续部署 | 持续学习自我优化 |
意图理解:将用户的自然语言输入转化为系统可执行的结构化指令,是AI原生应用的核心能力。

用户表达清晰,系统能高置信度识别目标。例如:"查询本月销售额"
用户表达不完整或有歧义,需要系统主动澄清。例如:"查一下数据"
一句话包含多个独立请求。例如:"查询销售额并导出报表"
@Component
public class IntentUnderstandingEngine {
@Autowired
private LlmProvider llmProvider;
@Autowired
private IntentRepository intentRepository;
public IntentAnalysis analyze(String sceneId, String userInput, Context context) {
// 1. 构建场景感知提示词
String prompt = buildSceneAwarePrompt(sceneId, userInput, context);
// 2. LLM意图分析
LlmResponse response = llmProvider.chat(
LlmRequest.builder()
.systemPrompt(getSystemPrompt(sceneId))
.userMessage(prompt)
.temperature(0.3) // 低温度保证确定性
.build()
);
// 3. 解析意图结构
IntentAnalysis analysis = parseIntent(response.getContent());
// 4. 意图验证与补全
return validateAndEnrich(analysis, sceneId);
}
private String buildSceneAwarePrompt(String sceneId, String input, Context ctx) {
SceneContext scene = sceneRepository.get(sceneId);
return String.format("""
【场景上下文】
场景名称: %s
可用意图: %s
用户角色: %s
历史会话: %s
【用户输入】
%s
请分析用户意图,返回JSON格式:
{
"primaryIntent": "主要意图",
"confidence": 0.95,
"entities": [{"name": "", "value": "", "type": ""}],
"subIntents": [],
"clarificationNeeded": false,
"suggestedResponse": ""
}
""",
scene.getName(),
scene.getAvailableIntents(),
ctx.getUserRole(),
ctx.getRecentHistory(3),
input
);
}
}动态编排:根据用户意图和上下文,实时决定执行路径,而非依赖预定义的固定流程。


能力图谱(Capability Graph)
描述场景中所有可用能力及其关系的图结构,帮助AI理解"能做什么"
执行计划(Execution Plan)
AI生成的具体执行步骤序列,包含步骤顺序和依赖关系
降级策略(Fallback)
当主路径失败时的备选方案,确保系统稳定性
@Service
public class DynamicOrchestrator {
public ExecutionPlan generatePlan(IntentAnalysis intent, SceneContext scene) {
// 1. 获取场景能力图谱
CapabilityGraph graph = capabilityRegistry.getGraph(scene.getId());
// 2. LLM规划执行路径
String planPrompt = buildPlanningPrompt(intent, graph);
LlmResponse planResponse = llmProvider.chat(planPrompt);
// 3. 解析执行计划
RawPlan rawPlan = parsePlan(planResponse.getContent());
// 4. 验证计划可行性
ValidationResult validation = validatePlan(rawPlan, graph);
// 5. 如果验证失败,请求LLM修正
if (!validation.isValid()) {
rawPlan = regeneratePlan(rawPlan, validation.getErrors());
}
// 6. 构建执行计划
return ExecutionPlan.builder()
.steps(rawPlan.getSteps())
.dependencies(resolveDependencies(rawPlan))
.fallbackStrategy(determineFallback(intent))
.build();
}
private String buildPlanningPrompt(IntentAnalysis intent, CapabilityGraph graph) {
return String.format("""
【任务描述】
用户意图: %s
提取实体: %s
【可用能力】
%s
【编排要求】
1. 选择最合适的能力组合
2. 明确步骤依赖关系
3. 考虑异常处理路径
4. 优化执行效率
请生成执行计划,返回JSON格式...
""",
intent.getDescription(),
intent.getEntities(),
graph.toPromptFormat()
);
}
}RAG(检索增强生成):一种将外部知识检索与大语言模型生成相结合的技术,让AI能够基于特定领域的知识回答问题。

@Service
public class SceneRagEngine {
@Autowired
private EmbeddingService embeddingService;
@Autowired
private VectorStore vectorStore;
@Autowired
private KeywordSearchService keywordSearch;
public RagResult retrieve(String sceneId, String query, RetrieveConfig config) {
// 1. 查询预处理
String processedQuery = preprocessQuery(query);
// 2. 生成查询向量
Embedding queryEmbedding = embeddingService.embed(processedQuery);
// 3. 混合检索
CompletableFuture> keywordFuture =
CompletableFuture.supplyAsync(() ->
keywordSearch.search(sceneId, processedQuery, config.getTopK())
);
CompletableFuture> vectorFuture =
CompletableFuture.supplyAsync(() ->
vectorStore.similaritySearch(sceneId, queryEmbedding, config.getTopK())
);
// 4. 合并结果
List merged = mergeResults(
keywordFuture.join(),
vectorFuture.join()
);
// 5. 重排序
List reranked = reranker.rerank(merged, query);
// 6. 过滤与截断
List filtered = filterAndDeduplicate(reranked, config.getThreshold());
// 7. 构建上下文
String context = buildContext(filtered);
return RagResult.builder()
.documents(filtered)
.context(context)
.sources(extractSources(filtered))
.build();
}
private String buildContext(List documents) {
StringBuilder context = new StringBuilder();
for (int i = 0; i < documents.size(); i++) {
Document doc = documents.get(i);
context.append(String.format("""
【参考文档%d】
来源: %s
内容: %s
相关度: %.2f
""",
i + 1,
doc.getSource(),
doc.getContent(),
doc.getScore()
));
}
return context.toString();
}
}@Aspect
@Component
public class SceneSecurityAspect {
@Around("@annotation(SceneSecured)")
public Object enforceSecurity(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
SceneSecured annotation = signature.getMethod().getAnnotation(SceneSecured.class);
String sceneId = getCurrentSceneId();
String userId = getCurrentUserId();
String operation = annotation.operation();
// 1. 身份验证
if (!authenticate(userId)) {
throw new AuthenticationException("身份验证失败");
}
// 2. 权限检查
if (!authorize(sceneId, userId, operation)) {
auditService.logDenied(sceneId, userId, operation);
throw new AuthorizationException("无权执行此操作");
}
// 3. 敏感操作二次确认
if (annotation.sensitive()) {
if (!confirmSensitiveOperation(sceneId, userId, operation)) {
throw new OperationCancelledException("操作已取消");
}
}
// 4. 获取场景密钥
String sceneKey = keyManager.getSceneKey(sceneId, userId);
// 5. 记录审计日志
AuditContext auditContext = auditService.start(sceneId, userId, operation);
try {
// 6. 执行业务逻辑
Object result = joinPoint.proceed();
// 7. 记录成功
auditService.complete(auditContext, result);
return result;
} catch (Exception e) {
// 8. 记录失败
auditService.fail(auditContext, e);
throw e;
}
}
}1
# scene-approval.yaml
scene:
id: intelligent-approval
name: 智能审批场景
version: 2.3.0
# 三层基础能力配置
foundations:
cloudNative:
serviceMesh: true
autoScaling:
minReplicas: 2
maxReplicas: 10
metrics:
- type: requestRate
target: 100
knowledge:
localIndex:
paths:
- /docs/approval-rules
- /docs/approval-history
indexType: hybrid # BM25 + Vector
terminology:
builtin: enterprise-terms.json
custom: approval-terms.yaml
ai:
intentModel: gpt-4
decisionModel: gpt-4
embeddingModel: text-embedding-3
features:
- intent-classification
- auto-routing
- smart-suggestion
- risk-assessment
# 业务工作流定义
workflow:
steps:
- id: intake
name: 申请受理
type: ai-enhanced
actions:
- type: llm
action: intent.classify
- type: knowledge
action: term.map
- type: knowledge
action: form.assist
- id: routing
name: 智能路由
type: decision
actions:
- type: llm
action: decision.route
- type: cloud
action: security.checkPermission
- id: review
name: 审批决策
type: ai-enhanced
actions:
- type: knowledge
action: doc.retrieve
- type: llm
action: decision.support
- type: llm
action: risk.assess
- id: notify
name: 结果通知
type: automated
actions:
- type: llm
action: message.generate
- type: cloud
action: notification.send2
@SceneHandler(sceneId = "intelligent-approval")
public class IntelligentApprovalHandler {
@Autowired
private IntentUnderstandingEngine intentEngine;
@Autowired
private DynamicOrchestrator orchestrator;
@Autowired
private SceneRagEngine ragEngine;
@StepHandler(stepId = "intake")
public StepResult handleIntake(StepContext context) {
String userInput = context.getUserInput();
// 1. 意图理解
IntentAnalysis intent = intentEngine.analyze(
context.getSceneId(),
userInput,
context.getConversationContext()
);
// 2. 如果需要澄清,返回澄清问题
if (intent.needsClarification()) {
return StepResult.clarification(intent.getClarificationQuestion());
}
// 3. 保存意图到上下文
context.setAttribute("intent", intent);
return StepResult.success(intent);
}
@StepHandler(stepId = "review")
public StepResult handleReview(StepContext context) {
IntentAnalysis intent = context.getAttribute("intent");
// 1. 检索相关规则和历史案例
RagResult relevantInfo = ragEngine.retrieve(
context.getSceneId(),
intent.getDescription(),
RetrieveConfig.builder()
.topK(5)
.threshold(0.7)
.build()
);
// 2. LLM辅助决策
DecisionSupport decision = llmProvider.decide(
DecisionRequest.builder()
.intent(intent)
.context(relevantInfo.getContext())
.policies(getApprovalPolicies())
.build()
);
return StepResult.success(decision);
}
}3
# 部署场景
ooder scene deploy -f scene-approval.yaml
# 测试场景
ooder scene test intelligent-approval \
--input "帮我提交一个紧急的出差申请,去上海,3天" \
--verbose
# 查看场景运行状态
ooder scene status intelligent-approval
# 查看执行日志
ooder scene logs intelligent-approval --tail 100
ooderAgent 2.3 的3+1场景架构为AI原生应用开发提供了一个完整的解决方案。 通过将云原生的工程能力、知识库的语义理解能力、AI的智能决策能力融为一体, 开发者可以更专注于业务逻辑本身,而非底层基础设施的搭建。
随着LLM技术的不断进步,AI原生应用将成为企业软件开发的主流范式。 我们期待与更多开发者一起,探索AI原生应用的无限可能。
本文基于 ooderAgent 2.3 技术规范编写
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。