Skip to content

northseadl/norix-skills / llm-agent-dev

llm-agent-dev

Unverified

LLM Agent engineering: pattern selection (12-mode matrix), data simulation, convergence iteration. Covers intent routing, function calling, ReAct, MCP, prompt chaining, guardrails, evaluation.

FileKindSize
SKILL.mdskill md17.6 KB
agents/openai.yamlconfig198 B
evals/evals.jsonconfig4.7 KB
references/convergence/iteration-protocol.mdmarkdown8.0 KB
references/eval-loop.mdmarkdown9.4 KB
references/feedback-protocol.mdmarkdown6.0 KB
references/intent-patterns.mdmarkdown5.8 KB
references/paradigms/context-engineering.mdmarkdown6.0 KB
references/paradigms/decision-tree.mdmarkdown2.7 KB
references/paradigms/memory-architecture.mdmarkdown4.0 KB
references/paradigms/observability.mdmarkdown4.5 KB
references/paradigms/pattern-matrix.mdmarkdown3.3 KB
references/paradigms/performance-benchmarking.mdmarkdown15.2 KB
references/paradigms/prompt-patterns.mdmarkdown5.0 KB
references/paradigms/safety-guardrails.mdmarkdown5.5 KB
references/paradigms/tool-design.mdmarkdown2.5 KB
references/patterns/01-crex-rule-router.mdmarkdown6.8 KB
references/patterns/02-slot-filling.mdmarkdown7.1 KB
references/patterns/03-function-calling.mdmarkdown3.9 KB
references/patterns/04-workflow-agent.mdmarkdown5.0 KB
references/patterns/05-react-agent.mdmarkdown3.4 KB
references/patterns/06-router-expert.mdmarkdown3.2 KB
references/patterns/07-mcp-tool-protocol.mdmarkdown5.0 KB
references/patterns/08-handoff-delegation.mdmarkdown4.7 KB
references/patterns/09-prompt-chaining.mdmarkdown3.0 KB
references/patterns/10-parallelizing.mdmarkdown3.2 KB
references/patterns/11-orchestrator-worker.mdmarkdown4.8 KB
references/patterns/12-evaluator-optimizer.mdmarkdown5.5 KB
references/scenarios/coding-assistant.mdmarkdown2.0 KB
references/scenarios/content-generation.mdmarkdown2.7 KB
references/scenarios/customer-service.mdmarkdown2.6 KB
references/scenarios/ecommerce-shopping.mdmarkdown4.2 KB
references/scenarios/food-ordering.mdmarkdown3.1 KB
references/scenarios/knowledge-qa.mdmarkdown2.6 KB
references/simulation/data-generation.mdmarkdown8.1 KB
references/skill-templates.mdmarkdown8.0 KB

references/patterns/03-function-calling.md

View on GitHub
# 模式 ③ Function Calling

> LLM 根据用户输入生成结构化函数调用,系统执行并返回结果
> 延迟 500-2000ms · 可预测性 ★★★★☆ · 适合工具调用密集场景

## 适用场景

- 计算器、单位换算
- 数据查询("查一下最近一周的销售额")
- API 调用委托(天气/汇率/运费等外部服务)
- 灵活工具调用(意图无法穷举但工具集有限)

## 不适用信号

- 意图可穷举且执行路径固定 → ① CREX(更快更省)
- 需要多步骤串联多个工具 → ⑤ ReAct
- 工具执行有审批要求 → ④ Workflow

## 与 CREX 的关系

Function Calling 可作为 CREX 的 **Layer 3 高级分类模式**——
当规则和缓存都失败时,让 LLM 从工具列表中选择要调用的函数。

也可以独立使用:直接让 LLM 决定调用哪个函数(不经过 CREX 的意图路由)。

## 实现

### 工具定义

```typescript
interface ToolDefinition {
  name: string;
  description: string;
  parameters: {
    type: 'object';
    properties: Record<string, { type: string; description: string; enum?: string[] }>;
    required: string[];
  };
}

const tools: ToolDefinition[] = [
  {
    name: 'query_order',
    description: '查询用户的订单信息',
    parameters: {
      type: 'object',
      properties: {
        orderId: { type: 'string', description: '订单号,可选' },
        status: { type: 'string', description: '订单状态筛选', enum: ['pending', 'shipped', 'completed'] },
      },
      required: [],
    },
  },
  {
    name: 'calculate_shipping',
    description: '计算运费',
    parameters: {
      type: 'object',
      properties: {
        destination: { type: 'string', description: '目的地城市' },
        weight: { type: 'number', description: '重量(kg)' },
      },
      required: ['destination', 'weight'],
    },
  },
];
```

### 调用流程

```typescript
async function handleWithFunctionCalling(
  input: string,
  context: AgentContext,
  toolExecutors: Map<string, (args: any, ctx: AgentContext) => Promise<any>>
): Promise<SkillResponse> {

  // 1. LLM 决定调用哪个函数
  const response = await llm.chat({
    model: 'haiku',    // 轻量模型足够
    messages: [
      { role: 'system', content: 'You are a helpful assistant. Use tools when needed.' },
      { role: 'user', content: input },
    ],
    tools,
    tool_choice: 'auto',
  });

  // 2. 无工具调用 → 直接返回文本
  if (!response.tool_calls?.length) {
    return { type: 'text', content: response.content, actions: [], followUp: null };
  }

  // 3. 执行工具调用
  const call = response.tool_calls[0];
  const executor = toolExecutors.get(call.function.name);
  if (!executor) {
    return { type: 'error', content: `未知工具: ${call.function.name}`, actions: [], followUp: null };
  }

  const args = JSON.parse(call.function.arguments);
  const result = await executor(args, context);

  // 4. 将结果格式化为 SkillResponse
  return formatToolResult(call.function.name, result);
}
```

### 关键约束 (Structured Output)

```typescript
// 使用 strict mode 防止 LLM 幻觉字段
const response = await llm.chat({
  tools,
  tool_choice: 'auto',
  // OpenAI strict mode — 确保参数严格匹配 schema
  // Claude: 自动严格匹配
});
```

**注意事项**:
- 工具列表建议 5-15 个,太多会降低选择准确率
- 每个工具的 description 要精准,这是 LLM 选择的主要依据
- required 参数缺失时 LLM 可能会编造值 → 需做后校验

## 与 CREX 混合使用

```typescript
class HybridClassifier {
  async classify(input: string): Promise<IntentResult> {
    // 优先走 CREX(快速+免费)
    const crexResult = await this.crexClassifier.classify(input);
    if (crexResult.confidence > 0.8) return crexResult;

    // CREX 不确定时退到 Function Calling
    return this.functionCallingClassifier.classify(input);
  }
}
```
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall