Claude Fable 5 开发者指南

Anthropic 今天发布了 Claude Fable 5。这是他们第一个向公众开放的 Mythos 级别模型——此前这个层级仅对经过审查的网络安全合作伙伴开放。模型字符串是 claude-fable-5。API 已上线。开发者现在问的问题不再是"它是真的吗?"而是"什么时候该用 Fable 5,我该怎么实际接入它?"

本教程回答了这两个问题。我们从干净的 API 快速入门开始,然后进入 Claude Code 集成,最后构建一个真实的多步骤工作框架,展示 Fable 5 与之前所有 Claude 模型的区别:能够跨阶段自主工作、委派子代理、验证自身输出,并在持续数小时甚至数天的任务中保持连贯性——而不是数秒。

完成本教程后,你将拥有可运行的代码、一个清晰的决策框架来判断 Fable 5 何时值得其相对于 Opus 4.8 的溢价,以及一个如何构建长期智能体工作的思维模型。

前提条件:

  • Anthropic SDK(pip install anthropic
  • 来自 platform.claude.com 的 API 密钥
  • 安装了 Claude Code(npm install -g @anthropic-ai/claude-code)用于第二部分
  • Python 3.10+

1、快速入门:你的第一次 Fable 5 调用

模型 ID 是 claude-fable-5。这是相对于任何现有 Anthropic 集成的唯一改动。你已经知道的每个参数、每个 SDK 方法、每个流式模式都可以继续使用。

import anthropic

client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-fable-5",
    max_tokens=2048,
    messages=[
        {
            "role": "user",
            "content": "Explain the tradeoffs between optimistic and pessimistic locking "
                       "in distributed systems. Give concrete examples with PostgreSQL."
        }
    ]
)
print(response.content[0].text)

没有什么特别的。SDK 处理其余一切。

1.1 理解安全回退机制

Fable 5 配备了分类器,可检测三个风险领域的请求——网络安全利用、生物/化学合成和模型蒸馏——并将这些请求静默路由到 Opus 4.8。当发生回退时你会收到通知。实际上,Anthropic 报告这种情况在不到 5% 的会话中触发,而且只在请求确实进入敏感领域时才会发生。

对于绝大多数开发工作——代码、分析、架构、数据处理、长时间运行的智能体——你直接与 Fable 5 对话,没有任何性能下降。

1.2 流式传输(长输出的正确方式)

Fable 5 为长输出而设计。对于你预期运行超过几秒的任何任务,使用流式传输:

import anthropic

client = anthropic.Anthropic()
with client.messages.stream(
    model="claude-fable-5",
    max_tokens=8192,
    messages=[
        {
            "role": "user",
            "content": (
                "You are a senior software architect. "
                "Produce a complete technical design document for a real-time "
                "collaborative code editor backend. Include: system overview, "
                "data model, API contracts, concurrency strategy, and failure modes."
            )
        }
    ]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

这里的 max_tokens=8192 是有意的。Fable 5 支持高达 128K 输出 token——这是相对于先前模型的真正能力提升。对于生成整个模块、多章节文档或完整迁移脚本等任务,你现在可以在一次生成中请求完整输出,而不需要拼接多个调用。

1.3 系统提示词与扩展思考

对于复杂的推理任务,将强系统提示词与扩展思考配对使用:

response = client.messages.create(
    model="claude-fable-5",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    system=(
        "You are an expert in distributed systems and database internals. "
        "Reason step by step. When you identify a tradeoff, name it explicitly. "
        "When you are uncertain, say so."
    ),
    messages=[
        {
            "role": "user",
            "content": (
                "Our PostgreSQL read replicas are 200-400ms behind primary "
                "during peak load. We use synchronous_commit=on. "
                "Diagnose the most likely causes and rank them by probability. "
                "Then propose three mitigation strategies with estimated impact."
            )
        }
    ]
)

# Extended thinking returns a thinking block followed by the response
for block in response.content:
    if block.type == "thinking":
        print("=== THINKING ===")
        print(block.thinking[:500], "...")  # truncated for brevity
    elif block.type == "text":
        print("=== RESPONSE ===")
        print(block.text)

思考块是 Fable 5 在难题上发挥价值的地方。它在生成可见输出之前分配推理预算,这极大地减少了需要多步推理的任务中的逻辑错误。

2、Claude Code + Fable 5

Claude Code 是 Anthropic 的智能体编码 CLI。它在你的终端中运行,可以直接访问你的文件系统和 shell,并执行持久的智能体循环。将它与 Fable 5 配对改变了你能委托的工作范围。

2.1 将 Claude Code 切换到 Fable 5

# Set the model globally for this session
claude --model claude-fable-5

# Or set it permanently in your project's CLAUDE.md
echo "model: claude-fable-5" >> .claude/settings.json

2.2 实际中的变化

使用 Opus 4.8 时,Claude Code 处理范围明确的任务:修复这个 bug,编写这个函数,重构这个文件。你需要积极监督。

使用 Fable 5 时,可行范围显著扩大。模型跨阶段规划,编写自己的测试,运行测试,阅读失败结果,修复代码,并迭代——而不需要你在每一步之后重定向它。GitHub CPO 描述它"以超越先前基准的自主性和可靠性水平处理复杂、长期的编码任务"。

具体示例——一个你可以在 Claude Code 中交给 Fable 5 然后走开的任务:

claude --model claude-fable-5 \
  "Migrate our user authentication module from JWT to session-based auth.
   Steps:
   1. Audit all current JWT usage across the codebase
   2. Design the session store schema (Redis)
   3. Implement the new session middleware
   4. Update all affected endpoints
   5. Write integration tests covering login, refresh, logout, and token expiry edge cases
   6. Produce a migration checklist for the deployment team

   Do not ask for confirmation between steps. Write tests before marking any step complete."

这个指令集——审计、设计、实现、测试、文档——在早期模型上需要积极监督。Fable 5 将其视为一个单一连贯的任务。

2.3 Fable 5 项目的 CLAUDE.md

每个在智能体模式下使用 Fable 5 的代码库都应该有一个 CLAUDE.md 来约束智能体的行为。模型足够强大,模糊的指令会产生模糊的结果:

# CLAUDE.md

## Model
claude-fable-5

## Behavior rules
- Never modify files outside src/, tests/, and docs/
- Write tests before marking any implementation step complete
- If a step requires a decision with significant architectural consequences,
  write a decision record in docs/decisions/ and continue
- On test failure: fix the implementation first, not the test
- Do not commit to git without explicit instruction

## Code standards
- Python: black formatting, type hints required, docstrings on public functions
- Test framework: pytest
- Coverage threshold: 80% on new code

## What to do when stuck
- If blocked for more than 3 attempts on the same error, write a detailed
  problem description to docs/blocked.md and stop

这就是智能体工程的框架面。模型提供能力;框架提供约束。两者共同定义了"自主"对你的项目的实际含义。

3、何时使用 Fable 5 vs. Opus 4.8

这是最实际的问题,也是最有细微差别的问题。Fable 5 的成本是每百万 token 10/50 美元——是 Opus 4.8 的两倍。这个溢价需要自己挣回来。

3.1 决策框架

核心变量是任务跨度。Fable 5 的优势随着复杂性和持续时间的增加而复利增长。对于短期、定义明确的任务,Opus 4.8 是更好的选择。交叉点大约在以下情况:

  • 超过两个相互依赖的顺序推理步骤
  • 需要阅读和综合多个文件或文档
  • 生成将根据外部标准(测试、规格、真实数据)验证的输出
  • 需要在超过约 10 轮对话中保持连贯状态

3.2 记忆利用信号

Fable 5 一个较少被讨论的优势是它如何使用持久记忆。Anthropic 使用《杀戮尖塔》作为代理进行测量:当获得基于文件的持久记忆访问时,Fable 5 的性能提升是 Opus 4.8 在相同条件下的三倍。它到达最终幕的频率是后者的三倍。

这对开发者工作流的含义是具体的。如果你的智能体将中间结果写入文件并在各步骤中读回,Fable 5 能更有效地利用这些笔记。它将先前的上下文综合到当前决策中,而不是将每一步视为全新的开始。对于多天的自主会话,这是连贯的长期规划与偏离之间的区别。

3.3 成本估算模式

在为任务选择 Fable 5 之前,估算 token 消耗:

import anthropic

client = anthropic.Anthropic()

def estimate_task_cost(task_description: str, expected_output_tokens: int) -> dict:
    input_tokens_estimate = len(task_description) // 4 + 500
    fable_cost = (input_tokens_estimate / 1_000_000 * 10) + (expected_output_tokens / 1_000_000 * 50)
    opus_cost = (input_tokens_estimate / 1_000_000 * 5) + (expected_output_tokens / 1_000_000 * 25)
    return {
        "estimated_input_tokens": input_tokens_estimate,
        "estimated_output_tokens": expected_output_tokens,
        "fable_5_cost_usd": round(fable_cost, 4),
        "opus_48_cost_usd": round(opus_cost, 4),
        "premium_usd": round(fable_cost - opus_cost, 4),
        "recommendation": "fable-5" if expected_output_tokens > 4000 or input_tokens_estimate > 8000 else "opus-4.8"
    }

粗略规则:如果任务生成超过 4,000 个输出 token 或需要在大规模输入上进行深度推理,质量差异证明了成本的合理性。低于该阈值,Opus 4.8 是更好的经济选择。

4、构建真实的多步骤自主智能体

这是模型架构可见的地方。我们将构建一个智能体,它接收一个 GitHub 仓库 URL 并产生完整的技术审计:依赖分析、安全面、架构摘要和优先级修复计划。

import anthropic
from pathlib import Path
from datetime import datetime

client = anthropic.Anthropic()
SCRATCH_DIR = Path("/tmp/audit_workspace")
SCRATCH_DIR.mkdir(exist_ok=True)

SYSTEM_PROMPT = """You are a senior software security and architecture auditor.
You work in stages. At the start of each stage:
1. Read your notes from previous stages
2. Complete the current stage's objective
3. Write a structured summary to the scratch file
4. Clearly state what the next stage should focus on"""

def run_stage(stage_name, instruction, scratch_path, conversation_history):
    scratch_content = scratch_path.read_text() if scratch_path.exists() else "No prior notes."
    stage_prompt = f"## Current Stage: {stage_name}\n## Notes: {scratch_content}\n## Objective: {instruction}"
    conversation_history.append({"role": "user", "content": stage_prompt})
    response = client.messages.create(
        model="claude-fable-5", max_tokens=8192,
        system=SYSTEM_PROMPT, messages=conversation_history)
    result = response.content[0].text
    conversation_history.append({"role": "assistant", "content": result})
    return result

def run_audit(repo_path):
    scratch_path = SCRATCH_DIR / "audit_notes.md"
    conversation_history = []
    results = {}
    stages = [("Dependency Analysis", f"Scan {repo_path}. Identify all dependencies."),
              ("Security Surface Mapping", f"Map the security surface of {repo_path}."),
              ("Architecture Assessment", f"Assess the architecture of {repo_path}."),
              ("Final Report", "Synthesize all stages into a final audit report.")]
    for stage_name, instruction in stages:
        results[stage_name] = run_stage(stage_name, instruction, scratch_path, conversation_history)
    return results

4.1 为什么这适合 Fable 5

三个结构特性使其成为 Fable 5 的合适任务:

阶段依赖性。 每个阶段读取前一个阶段的输出。安全面映射只有在依赖分析足够彻底时才有用。

自验证。 模型被指示在每个阶段后编写结构化笔记。这些笔记成为下一阶段中读取的事实依据。

开放式输出。 最终报告阶段在任务启动时无法预测,完全取决于模型在先前阶段中的发现。

5、多智能体委派模式

Fable 5 支持的最先进模式是真正的子智能体委派:一个协调器将大型任务分解为并行工作流,为每个工作流生成子智能体,并汇总它们的输出。

import anthropic
import concurrent.futures
from dataclasses import dataclass

client = anthropic.Anthropic()

@dataclass
class SubAgentTask:
    name: str
    system_prompt: str
    user_message: str
    max_tokens: int = 4096

def run_sub_agent(task):
    response = client.messages.create(model="claude-fable-5", max_tokens=task.max_tokens,
        system=task.system_prompt, messages=[{"role": "user", "content": task.user_message}])
    return task.name, response.content[0].text

def orchestrated_analysis(codebase_description):
    # Stage 1: Plan workstreams
    # Stage 2: Spawn parallel sub-agents
    # Stage 3: Synthesize outputs
    pass

这种模式——规划、并行化、综合——是需要超越单次模型调用所能处理的智能体系统的架构原语。

6、可能失败的地方

没有诚实的教程会不提及失败模式。

迭代任务中的成本爆炸。 如果你的智能体陷入修正循环——测试失败、尝试修复、再次失败——Fable 5 以每百万输出 token 50 美元的价格累积成本的速度比 Opus 4.8 快。在任何自主循环中构建显式的迭代上限。

合法安全工作上的安全措施误报。 如果你正在构建防御性安全工具——渗透测试框架、漏洞扫描器、红队工具——预期偶尔会回退到 Opus 4.8。

自验证循环不是测试套件。 Fable 5 编写和运行自己的测试令人印象深刻,但它不能替代具有真实覆盖率要求的适当 CI/CD 流水线。

长上下文连贯性在极端情况下会下降。 对于真正运行数天的任务,实现显式的检查点摘要。

提示缓存在这个价格点上很重要。 缓存输入 token 90% 的折扣在每百万 10 美元时是很显著的。构建你的 API 调用以最大化缓存命中。

7、结束语

当任务跨度长、推理链深,或输出将根据模型无法预先预测的外部标准进行验证时,Claude Fable 5 是正确的模型。价格溢价是真实的——Opus 4.8 的两倍——但它专门在多步骤、多阶段、长期工作中自己挣回这个溢价。

本教程中的三个模式覆盖了实际范围:用于困难单轮推理的直接 API 调用加扩展思考。带有约束的 CLAUDE.md 的 Claude Code 用于无人监督的自主编码会话。多智能体协调器用于可分解为并行工作流的任务。

模型字符串是 claude-fable-5。它现在已在 API、AWS、Google Cloud 和 Microsoft Foundry 上可用。订阅计划的免费窗口持续到 6 月 22 日——这是一个合理的窗口,可以在积分模式启动之前运行真实工作负载并对自己的任务进行基准测试。


原文链接: Claude Fable 5 for Developers: From First API Call to Multi-Day Autonomous Agents

汇智网翻译整理,转载请标明出处