Files
metona-ai-desktop/apis/agnes-ai-api-docs-20260625.html
T
thzxx e4c0259afc feat: Agnes上下文512K→1M + Ollama支持配置num_ctx
Agnes AI:
- adapter注释和API文档更新: 上下文512K→1M (官方已升级)

Ollama num_ctx 支持:
- MetonaGenerationParams 新增 contextLength 字段
- OllamaAdapter.toNativeRequest 发送 options.num_ctx
- AgentLoopEngine 从 config 读取并传递到请求参数
- database.service 新增 ollama.numCtx 默认配置(null=由模型决定)
- SettingsModal LLM设置: Ollama 选中时显示上下文长度输入框
- main.ts 启动时从 configService 读取 ollama.numCtx

数据流:
Settings → configService → main.ts → AgentLoopEngine.config
→ MetonaRequest.params → OllamaAdapter → options.num_ctx
2026-06-27 21:57:05 +08:00

1102 lines
51 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agnes-2.0-Flash API 完整接口文档 | 20260625</title>
<style>
:root {
--bg: #0f1117;
--bg-card: #1a1d27;
--bg-code: #12141c;
--bg-nav: #141620;
--text: #e1e4ed;
--text-dim: #8b8fa7;
--accent: #a855f7;
--accent2: #c084fc;
--green: #34d399;
--orange: #fb923c;
--red: #f87171;
--cyan: #22d3ee;
--border: #2a2d3a;
--get: #34d399;
--post: #a855f7;
--delete: #f87171;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.7;
display: flex;
}
/* === SIDEBAR === */
.sidebar {
position: fixed;
top: 0; left: 0;
width: 280px;
height: 100vh;
background: var(--bg-nav);
border-right: 1px solid var(--border);
overflow-y: auto;
z-index: 100;
padding: 24px 0;
}
.sidebar-logo {
padding: 0 20px 20px;
border-bottom: 1px solid var(--border);
margin-bottom: 16px;
}
.sidebar-logo h2 {
font-size: 20px;
background: linear-gradient(135deg, var(--accent), var(--accent2));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
display: flex;
align-items: center;
gap: 8px;
}
.sidebar-logo .badge {
font-size: 11px;
background: var(--accent);
color: #fff;
padding: 2px 8px;
border-radius: 10px;
-webkit-text-fill-color: #fff;
}
.sidebar-section {
padding: 8px 20px;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 1.2px;
color: var(--text-dim);
font-weight: 600;
}
.sidebar a {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 20px;
color: var(--text-dim);
text-decoration: none;
font-size: 13.5px;
transition: all 0.15s;
}
.sidebar a:hover, .sidebar a.active {
color: var(--text);
background: rgba(168, 85, 247, 0.06);
}
.sidebar a .method {
font-size: 10px;
font-weight: 700;
padding: 1px 6px;
border-radius: 3px;
min-width: 42px;
text-align: center;
font-family: 'SF Mono', 'Fira Code', monospace;
}
.method-get { background: rgba(52,211,153,0.15); color: var(--get); }
.method-post { background: rgba(168,85,247,0.15); color: var(--post); }
.method-delete { background: rgba(248,113,113,0.15); color: var(--delete); }
/* === MAIN === */
.main {
margin-left: 280px;
flex: 1;
min-height: 100vh;
}
.hero {
background: linear-gradient(135deg, rgba(168,85,247,0.08), rgba(192,132,252,0.08));
border-bottom: 1px solid var(--border);
padding: 60px 60px 50px;
}
.hero h1 {
font-size: 36px;
font-weight: 800;
background: linear-gradient(135deg, var(--accent), var(--accent2));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 12px;
}
.hero p {
color: var(--text-dim);
font-size: 16px;
max-width: 680px;
}
.hero p a { color: var(--accent); text-decoration: none; }
.hero p a:hover { text-decoration: underline; }
.hero-meta {
display: flex;
gap: 24px;
margin-top: 20px;
flex-wrap: wrap;
}
.hero-meta span {
font-size: 13px;
color: var(--text-dim);
display: flex;
align-items: center;
gap: 6px;
}
.hero-meta .dot {
width: 6px; height: 6px;
border-radius: 50%;
display: inline-block;
}
.dot-green { background: var(--green); }
.dot-blue { background: var(--accent); }
.dot-orange { background: var(--orange); }
.content {
padding: 40px 60px 100px;
max-width: 1000px;
}
/* === SECTION === */
.api-section {
margin-bottom: 60px;
scroll-margin-top: 20px;
}
.api-section h2 {
font-size: 24px;
font-weight: 700;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 12px;
}
.api-section .desc {
color: var(--text-dim);
font-size: 15px;
margin-bottom: 24px;
}
.api-section .desc code {
color: var(--cyan);
background: var(--bg-code);
padding: 2px 6px;
border-radius: 4px;
font-size: 13px;
}
/* === ENDPOINT BAR === */
.endpoint-bar {
display: flex;
align-items: center;
gap: 12px;
background: var(--bg-code);
border: 1px solid var(--border);
border-radius: 10px;
padding: 12px 18px;
margin-bottom: 24px;
font-family: 'SF Mono', 'Fira Code', monospace;
font-size: 14px;
}
.endpoint-bar .http-method {
font-weight: 700;
padding: 4px 10px;
border-radius: 5px;
font-size: 12px;
}
.endpoint-bar .url {
color: var(--text);
}
/* === PARAMS TABLE === */
.params-title {
font-size: 14px;
font-weight: 600;
color: var(--accent);
margin-bottom: 10px;
margin-top: 28px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
table.params {
width: 100%;
border-collapse: collapse;
margin-bottom: 28px;
font-size: 13.5px;
}
table.params th {
text-align: left;
padding: 10px 14px;
background: var(--bg-card);
border-bottom: 1px solid var(--border);
color: var(--text-dim);
font-weight: 600;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
table.params td {
padding: 10px 14px;
border-bottom: 1px solid rgba(42,45,58,0.5);
vertical-align: top;
}
table.params tr:last-child td { border-bottom: none; }
.param-name {
font-family: 'SF Mono', 'Fira Code', monospace;
color: var(--cyan);
font-weight: 600;
font-size: 13px;
}
.param-type {
font-family: 'SF Mono', 'Fira Code', monospace;
color: var(--accent2);
font-size: 12px;
}
.param-required {
color: var(--red);
font-size: 11px;
font-weight: 600;
}
.param-optional {
color: var(--text-dim);
font-size: 11px;
}
.param-default {
color: var(--text-dim);
font-size: 12px;
}
/* === CODE BLOCK === */
.code-tabs {
display: flex;
gap: 0;
border-bottom: 1px solid var(--border);
margin-bottom: 0;
flex-wrap: wrap;
}
.code-tab {
padding: 10px 20px;
font-size: 13px;
font-weight: 600;
color: var(--text-dim);
cursor: pointer;
border-bottom: 2px solid transparent;
transition: all 0.15s;
background: transparent;
border-top: none;
border-left: none;
border-right: none;
}
.code-tab:hover { color: var(--text); }
.code-tab.active {
color: var(--accent);
border-bottom-color: var(--accent);
}
.code-block {
background: var(--bg-code);
border: 1px solid var(--border);
border-top: none;
border-radius: 0 0 10px 10px;
padding: 20px;
overflow-x: auto;
margin-bottom: 24px;
}
.code-block pre {
margin: 0;
font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
font-size: 13px;
line-height: 1.65;
color: var(--text);
}
.code-panel { display: none; }
.code-panel.active { display: block; }
/* Syntax colors */
.hl-kw { color: var(--accent2); }
.hl-str { color: var(--green); }
.hl-num { color: var(--orange); }
.hl-cm { color: var(--text-dim); font-style: italic; }
.hl-fn { color: var(--accent); }
.hl-prop { color: var(--cyan); }
.hl-type { color: #fbbf24; }
/* === RESPONSE === */
.response-title {
font-size: 14px;
font-weight: 600;
color: var(--green);
margin-bottom: 10px;
margin-top: 28px;
}
.response-block {
background: var(--bg-code);
border: 1px solid var(--border);
border-radius: 10px;
padding: 20px;
overflow-x: auto;
margin-bottom: 28px;
}
.response-block pre {
margin: 0;
font-family: 'SF Mono', 'Fira Code', monospace;
font-size: 13px;
line-height: 1.65;
color: var(--text);
}
/* === DIVIDER === */
.section-divider {
border: none;
height: 1px;
background: var(--border);
margin: 60px 0;
}
/* === OVERVIEW TABLE === */
.overview-table {
width: 100%;
border-collapse: collapse;
margin: 24px 0 40px;
font-size: 13.5px;
}
.overview-table th {
text-align: left;
padding: 12px 16px;
background: var(--bg-card);
border-bottom: 2px solid var(--border);
color: var(--text-dim);
font-weight: 600;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.overview-table td {
padding: 10px 16px;
border-bottom: 1px solid rgba(42,45,58,0.5);
}
.overview-table a { color: var(--accent); text-decoration: none; }
.overview-table a:hover { text-decoration: underline; }
/* === PRICING TABLE === */
.pricing-table {
width: 100%;
border-collapse: collapse;
margin: 24px 0;
font-size: 13.5px;
}
.pricing-table th {
text-align: left;
padding: 12px 16px;
background: var(--bg-card);
border-bottom: 2px solid var(--border);
color: var(--text-dim);
font-weight: 600;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.pricing-table td {
padding: 10px 16px;
border-bottom: 1px solid rgba(42,45,58,0.5);
}
.pricing-table tr:last-child td { border-bottom: none; }
.pricing-table .strike { text-decoration: line-through; color: var(--text-dim); }
.pricing-table .special { color: var(--green); font-weight: 700; }
/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
/* === NOTE BOX === */
.note-box {
background: rgba(168, 85, 247, 0.06);
border-left: 3px solid var(--accent);
border-radius: 0 8px 8px 0;
padding: 14px 18px;
margin-bottom: 24px;
font-size: 13.5px;
color: var(--text-dim);
}
.note-box strong { color: var(--accent); }
.note-box code {
color: var(--cyan);
background: var(--bg-code);
padding: 1px 5px;
border-radius: 3px;
font-size: 12.5px;
}
/* === CAPABILITY TABLE === */
.capability-table {
width: 100%;
border-collapse: collapse;
margin: 24px 0;
font-size: 13.5px;
}
.capability-table th {
text-align: left;
padding: 12px 16px;
background: var(--bg-card);
border-bottom: 2px solid var(--border);
color: var(--text-dim);
font-weight: 600;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.capability-table td {
padding: 10px 16px;
border-bottom: 1px solid rgba(42,45,58,0.5);
vertical-align: top;
}
.capability-table .check { color: var(--green); font-weight: 700; }
@media (max-width: 900px) {
.sidebar { display: none; }
.main { margin-left: 0; }
.hero { padding: 30px 24px; }
.content { padding: 24px; }
}
</style>
</head>
<body>
<!-- ========== SIDEBAR ========== -->
<nav class="sidebar">
<div class="sidebar-logo">
<h2>&#x1F451; Agnes-2.0-Flash <span class="badge">最新</span></h2>
</div>
<div class="sidebar-section">概述</div>
<a href="#overview">&#x1F4CB; 模型概述</a>
<a href="#capabilities">&#x2699;&#xFE0F; 能力与场景</a>
<a href="#pricing">&#x1F4B0; 价格</a>
<div class="sidebar-section">API 参考</div>
<a href="#endpoint"><span class="method method-post">POST</span> /chat/completions</a>
<a href="#request-params">&#x1F4E5; 请求参数</a>
<a href="#response-format">&#x1F4E4; 响应格式</a>
<div class="sidebar-section">调用示例</div>
<a href="#example-basic">&#x1F4AC; 基础对话</a>
<a href="#example-stream">&#x26A1; 流式输出</a>
<a href="#example-tool">&#x1F527; 工具调用</a>
<a href="#example-image">&#x1F5BC;&#xFE0F; 图片理解</a>
<div class="sidebar-section">高级指南</div>
<a href="#thinking">&#x1F9E0; Thinking 模式</a>
<a href="#image-guide">&#x1F5BC;&#xFE0F; 图片 URL 使用</a>
<a href="#best-practices">&#x1F4D0; 最佳实践</a>
</nav>
<!-- ========== MAIN CONTENT ========== -->
<div class="main">
<!-- HERO -->
<div class="hero">
<h1>Agnes-2.0-Flash API 完整接口文档</h1>
<p>Agnes-2.0-Flash 由 <a href="#">Sapiens AI</a> 开发,是一款快速、高效的语言模型,面向智能体工作流、工具调用、编程任务、推理、多轮对话、图片理解以及高频生产环境应用场景设计。</p>
<p style="margin-top: 12px;">在 Claw-Eval 基准测试中排名 General Leaderboard <strong style="color:var(--accent)">第 9</strong>Pass³ 分数 <strong style="color:var(--green)">60.9%</strong></p>
<div class="hero-meta">
<span><span class="dot dot-blue"></span> 模型名称: <strong>agnes-2.0-flash</strong></span>
<span><span class="dot dot-green"></span> 上下文: <strong>1M</strong> | 最大输出: <strong>65.5K</strong></span>
<span><span class="dot dot-orange"></span> Base URL: <strong>https://apihub.agnes-ai.com/v1</strong></span>
</div>
</div>
<div class="content">
<!-- ========== 模型概述 ========== -->
<section class="api-section" id="overview">
<h2>&#x1F4CB; 模型概述</h2>
<p class="desc">Agnes-2.0-Flash 针对快速、可靠、低成本的语言生成、智能体任务执行和图片理解进行了优化。兼容 <strong>OpenAI Chat Completions API</strong> 结构。</p>
<table class="overview-table">
<thead>
<tr><th>能力</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td>Chat Completion</td><td>为对话和应用生成高质量回复</td></tr>
<tr><td>多轮对话</td><td>在多轮交互中保持上下文连续性</td></tr>
<tr><td>图片 URL 输入</td><td>支持通过公网图片 URL 传入图片内容</td></tr>
<tr><td>图片理解</td><td>支持基于图片的内容理解、截图分析和信息提取</td></tr>
<tr><td>工具调用</td><td>调用外部工具和函数,支持智能体工作流</td></tr>
<tr><td>智能体工作流</td><td>支持规划、执行和多步骤任务完成</td></tr>
<tr><td>编程任务</td><td>辅助代码生成、调试、解释和重构</td></tr>
<tr><td>推理</td><td>处理结构化推理、任务拆解和决策</td></tr>
<tr><td>流式输出</td><td>实时返回响应,提升用户体验</td></tr>
<tr><td>OpenAI 兼容 API</td><td>使用兼容 OpenAI Chat Completions API 的结构</td></tr>
</tbody>
</table>
</section>
<!-- ========== 适用场景 ========== -->
<section class="api-section" id="capabilities">
<h2>&#x2699;&#xFE0F; 适用场景</h2>
<p class="desc">Agnes-2.0-Flash 适用于多种生产级场景:</p>
<table class="capability-table">
<thead>
<tr><th>场景</th><th>示例用例</th></tr>
</thead>
<tbody>
<tr><td>AI 助手</td><td>通用问答、日常助手、效率支持</td></tr>
<tr><td>自主智能体</td><td>多步骤任务执行、规划和工具使用</td></tr>
<tr><td>编程助手</td><td>代码生成、调试、重构和解释</td></tr>
<tr><td>工作流自动化</td><td>任务拆解、流程自动化和执行规划</td></tr>
<tr><td>客户支持</td><td>FAQ 问答、客服聊天机器人、服务自动化</td></tr>
<tr><td>搜索与问答</td><td>基于搜索的回答、摘要生成、信息提取</td></tr>
<tr><td>内容生成</td><td>营销文案、文章、产品描述、脚本</td></tr>
<tr><td>开发者工具</td><td>API 助手、文档助手、编程 Copilot</td></tr>
<tr><td>AI 原生应用</td><td>消费级应用、效率工具、智能体应用</td></tr>
<tr><td>图片理解</td><td>图片描述、截图分析、视觉问答、信息提取</td></tr>
</tbody>
</table>
</section>
<hr class="section-divider">
<!-- ========== Endpoint ========== -->
<section class="api-section" id="endpoint">
<h2><span class="method method-post">POST</span> /chat/completions</h2>
<p class="desc">Agnes-2.0-Flash 核心对话接口。支持多轮对话、Thinking 模式、工具调用、图片理解、流式响应等全部功能。</p>
<div class="endpoint-bar">
<span class="http-method method-post">POST</span>
<span class="url">https://apihub.agnes-ai.com/v1/chat/completions</span>
</div>
<table class="overview-table">
<thead>
<tr><th>项目</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td>API Endpoint</td><td>https://apihub.agnes-ai.com/v1/chat/completions</td></tr>
<tr><td>Request Method</td><td>POST</td></tr>
<tr><td>Content-Type</td><td>application/json</td></tr>
<tr><td>Authentication</td><td>Bearer Token</td></tr>
<tr><td>Authentication Header</td><td><code>Authorization: Bearer YOUR_API_KEY</code></td></tr>
</tbody>
</table>
</section>
<!-- ========== 请求参数 ========== -->
<section class="api-section" id="request-params">
<h2>&#x1F4E5; 请求参数</h2>
<div class="params-title">&#x1F4E5; 请求参数</div>
<table class="params">
<thead><tr><th>参数名</th><th>类型</th><th>必填</th><th>说明</th></tr></thead>
<tbody>
<tr><td class="param-name">model</td><td class="param-type">string</td><td class="param-required">必填</td><td>模型名称,固定为 "agnes-2.0-flash"</td></tr>
<tr><td class="param-name">messages</td><td class="param-type">array</td><td class="param-required">必填</td><td>对话消息数组,包括 system、user 和 assistant 消息</td></tr>
<tr><td class="param-name">messages[].content</td><td class="param-type">string / array</td><td class="param-required">必填</td><td>消息内容。可为纯文本字符串,也可为包含 text、image_url 的内容数组</td></tr>
<tr><td class="param-name">temperature</td><td class="param-type">number</td><td class="param-optional">可选</td><td>控制输出随机性。较低值会生成更确定性的结果</td></tr>
<tr><td class="param-name">top_p</td><td class="param-type">number</td><td class="param-optional">可选</td><td>控制核采样。较低值会使输出更加聚焦</td></tr>
<tr><td class="param-name">max_tokens</td><td class="param-type">number</td><td class="param-optional">可选</td><td>响应中最多生成的 token 数</td></tr>
<tr><td class="param-name">stream</td><td class="param-type">boolean</td><td class="param-optional">可选</td><td>是否启用流式响应输出</td></tr>
<tr><td class="param-name">tools</td><td class="param-type">array</td><td class="param-optional">可选</td><td>用于工具调用工作流的工具定义</td></tr>
<tr><td class="param-name">tool_choice</td><td class="param-type">string / object</td><td class="param-optional">可选</td><td>控制模型是否以及如何使用工具</td></tr>
<tr><td class="param-name">chat_template_kwargs</td><td class="param-type">object</td><td class="param-optional">可选</td><td>OpenAI 兼容请求中用于开启 Thinking 等扩展能力</td></tr>
<tr><td class="param-name">thinking</td><td class="param-type">object</td><td class="param-optional">可选</td><td>Anthropic 兼容请求中用于开启 Thinking 模式</td></tr>
</tbody>
</table>
<div class="note-box">
<strong>&#x1F4A1; 提示:</strong><code>messages[].content</code> 可使用纯文本字符串,也可使用包含 <code>text</code><code>image_url</code> 的内容数组来传入图片。
</div>
</section>
<hr class="section-divider">
<!-- ========== 调用示例:基础对话 ========== -->
<section class="api-section" id="example-basic">
<h2>&#x1F4AC; 示例 1:基础 Chat Completion 请求</h2>
<p class="desc">用于生成普通的聊天补全响应。</p>
<div class="code-tabs">
<button class="code-tab active" onclick="switchTab(this, 'basic-curl')">curl</button>
<button class="code-tab" onclick="switchTab(this, 'basic-python')">Python (OpenAI SDK)</button>
</div>
<div class="code-block">
<div class="code-panel active" id="basic-curl">
<pre><span class="hl-fn">curl</span> <span class="hl-str">https://apihub.agnes-ai.com/v1/chat/completions</span> \
-H <span class="hl-str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="hl-str">"Content-Type: application/json"</span> \
-d <span class="hl-str">'{
"model": "agnes-2.0-flash",
"messages": [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "Explain how autonomous agents use tools to complete tasks."}
],
"temperature": 0.7,
"max_tokens": 1024
}'</span></pre>
</div>
<div class="code-panel" id="basic-python">
<pre><span class="hl-kw">from</span> openai <span class="hl-kw">import</span> OpenAI
client = <span class="hl-fn">OpenAI</span>(
<span class="hl-prop">api_key</span>=<span class="hl-str">"YOUR_API_KEY"</span>,
<span class="hl-prop">base_url</span>=<span class="hl-str">"https://apihub.agnes-ai.com/v1"</span>
)
response = client.chat.completions.<span class="hl-fn">create</span>(
<span class="hl-prop">model</span>=<span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">messages</span>=[
{<span class="hl-str">"role"</span>: <span class="hl-str">"system"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"You are a helpful AI assistant."</span>},
{<span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"Explain how autonomous agents use tools to complete tasks."</span>}
],
<span class="hl-prop">temperature</span>=<span class="hl-num">0.7</span>,
<span class="hl-prop">max_tokens</span>=<span class="hl-num">1024</span>
)
<span class="hl-fn">print</span>(response.choices[<span class="hl-num">0</span>].message.content)</pre>
</div>
</div>
</section>
<!-- ========== 调用示例:流式输出 ========== -->
<section class="api-section" id="example-stream">
<h2>&#x26A1; 示例 2:流式输出请求</h2>
<p class="desc">启用流式输出,实时接收模型生成的 token。</p>
<div class="code-tabs">
<button class="code-tab active" onclick="switchTab(this, 'stream-curl')">curl</button>
<button class="code-tab" onclick="switchTab(this, 'stream-python')">Python (OpenAI SDK)</button>
<button class="code-tab" onclick="switchTab(this, 'stream-js')">JavaScript (Fetch)</button>
</div>
<div class="code-block">
<div class="code-panel active" id="stream-curl">
<pre><span class="hl-fn">curl</span> <span class="hl-str">https://apihub.agnes-ai.com/v1/chat/completions</span> \
-H <span class="hl-str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="hl-str">"Content-Type: application/json"</span> \
-d <span class="hl-str">'{
"model": "agnes-2.0-flash",
"messages": [
{"role": "user", "content": "Write a short product introduction for an AI assistant app."}
],
"stream": true
}'</span></pre>
</div>
<div class="code-panel" id="stream-python">
<pre><span class="hl-kw">from</span> openai <span class="hl-kw">import</span> OpenAI
client = <span class="hl-fn">OpenAI</span>(
<span class="hl-prop">api_key</span>=<span class="hl-str">"YOUR_API_KEY"</span>,
<span class="hl-prop">base_url</span>=<span class="hl-str">"https://apihub.agnes-ai.com/v1"</span>
)
stream = client.chat.completions.<span class="hl-fn">create</span>(
<span class="hl-prop">model</span>=<span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">messages</span>=[
{<span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"Write a short product introduction for an AI assistant app."</span>}
],
<span class="hl-prop">stream</span>=<span class="hl-kw">True</span>
)
<span class="hl-kw">for</span> chunk <span class="hl-kw">in</span> stream:
content = chunk.choices[<span class="hl-num">0</span>].delta.content
<span class="hl-kw">if</span> content:
<span class="hl-fn">print</span>(content, <span class="hl-prop">end</span>=<span class="hl-str">""</span>, <span class="hl-prop">flush</span>=<span class="hl-kw">True</span>)</pre>
</div>
<div class="code-panel" id="stream-js">
<pre><span class="hl-kw">const</span> response = <span class="hl-kw">await</span> <span class="hl-fn">fetch</span>(<span class="hl-str">'https://apihub.agnes-ai.com/v1/chat/completions'</span>, {
<span class="hl-prop">method</span>: <span class="hl-str">'POST'</span>,
<span class="hl-prop">headers</span>: {
<span class="hl-str">'Content-Type'</span>: <span class="hl-str">'application/json'</span>,
<span class="hl-str">'Authorization'</span>: <span class="hl-str">`Bearer ${API_KEY}`</span>
},
<span class="hl-prop">body</span>: JSON.<span class="hl-fn">stringify</span>({
<span class="hl-prop">model</span>: <span class="hl-str">'agnes-2.0-flash'</span>,
<span class="hl-prop">messages</span>: [{ <span class="hl-prop">role</span>: <span class="hl-str">'user'</span>, <span class="hl-prop">content</span>: <span class="hl-str">'Write a short product introduction for an AI assistant app.'</span> }],
<span class="hl-prop">stream</span>: <span class="hl-kw">true</span>
})
});
<span class="hl-kw">const</span> reader = response.body.<span class="hl-fn">getReader</span>();
<span class="hl-kw">const</span> decoder = <span class="hl-kw">new</span> <span class="hl-fn">TextDecoder</span>();
<span class="hl-kw">let</span> buffer = <span class="hl-str">''</span>;
<span class="hl-kw">while</span> (<span class="hl-kw">true</span>) {
<span class="hl-kw">const</span> { done, value } = <span class="hl-kw">await</span> reader.<span class="hl-fn">read</span>();
<span class="hl-kw">if</span> (done) <span class="hl-kw">break</span>;
buffer += decoder.<span class="hl-fn">decode</span>(value, { <span class="hl-prop">stream</span>: <span class="hl-kw">true</span> });
<span class="hl-kw">const</span> lines = buffer.<span class="hl-fn">split</span>(<span class="hl-str">'\n'</span>);
buffer = lines.<span class="hl-fn">pop</span>();
<span class="hl-kw">for</span> (<span class="hl-kw">const</span> line <span class="hl-kw">of</span> lines) {
<span class="hl-kw">if</span> (!line.<span class="hl-fn">startsWith</span>(<span class="hl-str">'data: '</span>) || line === <span class="hl-str">'data: [DONE]'</span>) <span class="hl-kw">continue</span>;
<span class="hl-kw">const</span> chunk = JSON.<span class="hl-fn">parse</span>(line.<span class="hl-fn">slice</span>(<span class="hl-num">6</span>));
<span class="hl-kw">const</span> content = chunk.choices[<span class="hl-num">0</span>]?.delta?.content;
<span class="hl-kw">if</span> (content) process.stdout.<span class="hl-fn">write</span>(content);
}
}</pre>
</div>
</div>
</section>
<!-- ========== 调用示例:工具调用 ========== -->
<section class="api-section" id="example-tool">
<h2>&#x1F527; 示例 3:工具调用请求</h2>
<p class="desc">用于需要外部工具调用的智能体工作流。模型会返回工具调用请求,开发者执行后需将结果传回。</p>
<div class="code-tabs">
<button class="code-tab active" onclick="switchTab(this, 'tool-curl')">curl</button>
<button class="code-tab" onclick="switchTab(this, 'tool-python')">Python (OpenAI SDK)</button>
</div>
<div class="code-block">
<div class="code-panel active" id="tool-curl">
<pre><span class="hl-fn">curl</span> <span class="hl-str">https://apihub.agnes-ai.com/v1/chat/completions</span> \
-H <span class="hl-str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="hl-str">"Content-Type: application/json"</span> \
-d <span class="hl-str">'{
"model": "agnes-2.0-flash",
"messages": [
{"role": "user", "content": "What is the weather like in Singapore today?"}
],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "The city and country" }
},
"required": ["location"]
}
}
}]
}'</span></pre>
</div>
<div class="code-panel" id="tool-python">
<pre><span class="hl-kw">from</span> openai <span class="hl-kw">import</span> OpenAI
client = <span class="hl-fn">OpenAI</span>(
<span class="hl-prop">api_key</span>=<span class="hl-str">"YOUR_API_KEY"</span>,
<span class="hl-prop">base_url</span>=<span class="hl-str">"https://apihub.agnes-ai.com/v1"</span>
)
response = client.chat.completions.<span class="hl-fn">create</span>(
<span class="hl-prop">model</span>=<span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">messages</span>=[
{<span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"What is the weather like in Singapore today?"</span>}
],
<span class="hl-prop">tools</span>=[{
<span class="hl-str">"type"</span>: <span class="hl-str">"function"</span>,
<span class="hl-str">"function"</span>: {
<span class="hl-str">"name"</span>: <span class="hl-str">"get_weather"</span>,
<span class="hl-str">"description"</span>: <span class="hl-str">"Get the current weather for a location"</span>,
<span class="hl-str">"parameters"</span>: {
<span class="hl-str">"type"</span>: <span class="hl-str">"object"</span>,
<span class="hl-str">"properties"</span>: {
<span class="hl-str">"location"</span>: { <span class="hl-str">"type"</span>: <span class="hl-str">"string"</span>, <span class="hl-str">"description"</span>: <span class="hl-str">"The city and country"</span> }
},
<span class="hl-str">"required"</span>: [<span class="hl-str">"location"</span>]
}
}
}]
)
msg = response.choices[<span class="hl-num">0</span>].message
<span class="hl-kw">if</span> msg.tool_calls:
<span class="hl-kw">for</span> tc <span class="hl-kw">in</span> msg.tool_calls:
<span class="hl-fn">print</span>(<span class="hl-str">f"Tool: {tc.function.name}, Args: {tc.function.arguments}"</span>)</pre>
</div>
</div>
</section>
<!-- ========== 调用示例:图片理解 ========== -->
<section class="api-section" id="example-image">
<h2>&#x1F5BC;&#xFE0F; 示例 4:图片 URL 输入请求</h2>
<p class="desc">通过图片链接传入图片,让模型理解或分析图片内容。<code>messages[].content</code> 使用数组结构,可同时包含文本和图片。</p>
<div class="params-title">图片内容结构</div>
<table class="params">
<thead><tr><th>输入类型</th><th>支持方式</th><th>说明</th></tr></thead>
<tbody>
<tr><td class="param-name">text</td><td class="param-type">text</td><td>普通文本指令或问题</td></tr>
<tr><td class="param-name">image_url</td><td class="param-type">image_url</td><td>通过公网可访问的图片链接传入图片</td></tr>
</tbody>
</table>
<div class="code-tabs">
<button class="code-tab active" onclick="switchTab(this, 'img-curl')">curl</button>
<button class="code-tab" onclick="switchTab(this, 'img-python')">Python (OpenAI SDK)</button>
</div>
<div class="code-block">
<div class="code-panel active" id="img-curl">
<pre><span class="hl-fn">curl</span> <span class="hl-str">https://apihub.agnes-ai.com/v1/chat/completions</span> \
-H <span class="hl-str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="hl-str">"Content-Type: application/json"</span> \
-d <span class="hl-str">'{
"model": "agnes-2.0-flash",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this image."},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
}'</span></pre>
</div>
<div class="code-panel" id="img-python">
<pre><span class="hl-kw">from</span> openai <span class="hl-kw">import</span> OpenAI
client = <span class="hl-fn">OpenAI</span>(
<span class="hl-prop">api_key</span>=<span class="hl-str">"YOUR_API_KEY"</span>,
<span class="hl-prop">base_url</span>=<span class="hl-str">"https://apihub.agnes-ai.com/v1"</span>
)
response = client.chat.completions.<span class="hl-fn">create</span>(
<span class="hl-prop">model</span>=<span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">messages</span>=[{
<span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>,
<span class="hl-str">"content"</span>: [
{<span class="hl-str">"type"</span>: <span class="hl-str">"text"</span>, <span class="hl-str">"text"</span>: <span class="hl-str">"Describe the content of this image."</span>},
{<span class="hl-str">"type"</span>: <span class="hl-str">"image_url"</span>, <span class="hl-str">"image_url"</span>: {<span class="hl-str">"url"</span>: <span class="hl-str">"https://example.com/image.jpg"</span>}}
]
}]
)
<span class="hl-fn">print</span>(response.choices[<span class="hl-num">0</span>].message.content)</pre>
</div>
</div>
</section>
<hr class="section-divider">
<!-- ========== 响应格式 ========== -->
<section class="api-section" id="response-format">
<h2>&#x1F4E4; 响应格式</h2>
<div class="response-title">&#x1F4E4; 响应示例</div>
<div class="response-block">
<pre>{
<span class="hl-prop">"id"</span>: <span class="hl-str">"chatcmpl_xxx"</span>,
<span class="hl-prop">"object"</span>: <span class="hl-str">"chat.completion"</span>,
<span class="hl-prop">"created"</span>: <span class="hl-num">1774432125</span>,
<span class="hl-prop">"model"</span>: <span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">"choices"</span>: [{
<span class="hl-prop">"index"</span>: <span class="hl-num">0</span>,
<span class="hl-prop">"message"</span>: {
<span class="hl-prop">"role"</span>: <span class="hl-str">"assistant"</span>,
<span class="hl-prop">"content"</span>: <span class="hl-str">"Autonomous agents use tools by understanding the user's goal..."</span>
},
<span class="hl-prop">"finish_reason"</span>: <span class="hl-str">"stop"</span>
}],
<span class="hl-prop">"usage"</span>: {
<span class="hl-prop">"prompt_tokens"</span>: <span class="hl-num">35</span>,
<span class="hl-prop">"completion_tokens"</span>: <span class="hl-num">58</span>,
<span class="hl-prop">"total_tokens"</span>: <span class="hl-num">93</span>
}
}</pre>
</div>
<div class="params-title">&#x1F4E4; 响应字段说明</div>
<table class="params">
<thead><tr><th>字段名</th><th>类型</th><th>描述</th></tr></thead>
<tbody>
<tr><td class="param-name">id</td><td class="param-type">string</td><td>本次补全请求的唯一 ID</td></tr>
<tr><td class="param-name">object</td><td class="param-type">string</td><td>对象类型,通常为 "chat.completion"</td></tr>
<tr><td class="param-name">created</td><td class="param-type">integer</td><td>请求时间戳</td></tr>
<tr><td class="param-name">model</td><td class="param-type">string</td><td>本次请求使用的模型</td></tr>
<tr><td class="param-name">choices</td><td class="param-type">array</td><td>生成的响应结果列表</td></tr>
<tr><td class="param-name">choices[].index</td><td class="param-type">integer</td><td>响应结果的索引</td></tr>
<tr><td class="param-name">choices[].message</td><td class="param-type">object</td><td>Assistant 消息对象</td></tr>
<tr><td class="param-name">choices[].message.role</td><td class="param-type">string</td><td>消息发送者角色</td></tr>
<tr><td class="param-name">choices[].message.content</td><td class="param-type">string</td><td>模型生成的响应内容</td></tr>
<tr><td class="param-name">choices[].finish_reason</td><td class="param-type">string</td><td>生成停止原因</td></tr>
<tr><td class="param-name">usage</td><td class="param-type">object</td><td>Token 使用信息</td></tr>
<tr><td class="param-name">usage.prompt_tokens</td><td class="param-type">integer</td><td>输入 token 数量</td></tr>
<tr><td class="param-name">usage.completion_tokens</td><td class="param-type">integer</td><td>输出 token 数量</td></tr>
<tr><td class="param-name">usage.total_tokens</td><td class="param-type">integer</td><td>使用的 token 总数</td></tr>
</tbody>
</table>
</section>
<hr class="section-divider">
<!-- ========== Thinking 模式 ========== -->
<section class="api-section" id="thinking">
<h2>&#x1F9E0; Thinking 模式</h2>
<p class="desc">对于代码编写、调试、推理和 Agent 工作流,建议开启 Thinking 模式,以提升代码质量、任务拆解能力和问题解决效果。</p>
<div class="params-title">OpenAI 兼容请求</div>
<p class="desc">在请求体中添加 <code>chat_template_kwargs.enable_thinking</code></p>
<div class="response-block">
<pre>{
<span class="hl-prop">"model"</span>: <span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">"messages"</span>: [
{ <span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"Help me write a Python script to process a CSV file."</span> }
],
<span class="hl-prop">"chat_template_kwargs"</span>: {
<span class="hl-prop">"enable_thinking"</span>: <span class="hl-kw">true</span>
}
}</pre>
</div>
<div class="params-title">Anthropic 兼容请求</div>
<p class="desc">使用 <code>thinking</code> 字段,支持 <code>budget_tokens</code> 控制最大 Token 预算:</p>
<div class="response-block">
<pre>{
<span class="hl-prop">"model"</span>: <span class="hl-str">"agnes-2.0-flash"</span>,
<span class="hl-prop">"messages"</span>: [
{ <span class="hl-str">"role"</span>: <span class="hl-str">"user"</span>, <span class="hl-str">"content"</span>: <span class="hl-str">"Help me refactor this TypeScript function and explain the changes."</span> }
],
<span class="hl-prop">"thinking"</span>: {
<span class="hl-prop">"type"</span>: <span class="hl-str">"enabled"</span>,
<span class="hl-prop">"budget_tokens"</span>: <span class="hl-num">2048</span>
}
}</pre>
</div>
<div class="note-box">
<strong>&#x1F4A1; 建议:</strong>常见编码任务建议从 <code>budget_tokens: 2048</code> 开始。更复杂的调试、重构或多步骤 Agent 任务可适当提高该值。
</div>
</section>
<hr class="section-divider">
<!-- ========== 图片 URL 使用指南 ========== -->
<section class="api-section" id="image-guide">
<h2>&#x1F5BC;&#xFE0F; 图片 URL 使用建议</h2>
<ul class="desc" style="list-style: disc; padding-left: 20px; line-height: 2;">
<li>图片 URL 必须可<strong>公网访问</strong></li>
<li>如果图片 URL 需要登录、鉴权或存在防盗链,模型可能无法读取。</li>
<li>建议使用标准图片格式:<code>JPG</code><code>JPEG</code><code>PNG</code><code>WebP</code></li>
<li>对于截图、报错图、产品界面图,建议在文本中补充你希望模型重点关注的问题。</li>
<li>图片 URL 输入可以与工具调用、流式输出和 Agent 工作流结合使用。</li>
</ul>
</section>
<hr class="section-divider">
<!-- ========== 最佳实践 ========== -->
<section class="api-section" id="best-practices">
<h2>&#x1F4D0; 最佳实践</h2>
<p class="desc">推荐 Prompt 结构:<strong>[角色] + [任务] + [上下文] + [要求] + [输出格式]</strong></p>
<div class="params-title">示例:产品文案生成</div>
<div class="response-block">
<pre>You are a product marketing expert. Write a concise App Store description for an AI assistant app. The tone should be clear, professional, and user-friendly.</pre>
</div>
<div class="params-title">示例:编程任务</div>
<div class="response-block">
<pre>Help me debug this React component. The issue is that the button state does not update after clicking. Explain the cause and provide the corrected code.</pre>
</div>
<div class="params-title">示例:智能体工作流</div>
<div class="response-block">
<pre>You are an autonomous research agent. Search for relevant information, summarize the key findings, and return the result in a structured format with source links.</pre>
</div>
<div class="params-title">示例:图片理解任务</div>
<div class="response-block">
<pre>Analyze this screenshot. Identify the main UI elements, explain the possible issue, and provide suggestions to improve the user experience.</pre>
</div>
</section>
<hr class="section-divider">
<!-- ========== 模型限制 ========== -->
<section class="api-section" id="limits">
<h2>&#x1F4CF; 模型限制</h2>
<table class="params">
<thead><tr><th>项目</th><th>数值</th></tr></thead>
<tbody>
<tr><td class="param-name">Context</td><td class="param-type">1M</td></tr>
<tr><td class="param-name">Max Output</td><td class="param-type">65.5K</td></tr>
</tbody>
</table>
</section>
<hr class="section-divider">
<!-- ========== 价格 ========== -->
<section class="api-section" id="pricing">
<h2>&#x1F4B0; 价格</h2>
<p class="desc">Agnes-2.0-Flash 当前提供免费使用。</p>
<table class="pricing-table">
<thead>
<tr><th>类型</th><th>原价</th><th>现价</th></tr>
</thead>
<tbody>
<tr>
<td>Input Tokens</td>
<td class="strike">$0.03 / 1M tokens</td>
<td class="special">$0 / 1M tokens</td>
</tr>
<tr>
<td>Output Tokens</td>
<td class="strike">$0.15 / 1M tokens</td>
<td class="special">$0 / 1M tokens</td>
</tr>
</tbody>
</table>
</section>
<hr class="section-divider">
<!-- ========== 说明 ========== -->
<section class="api-section" id="notes">
<h2>&#x1F4DD; 使用说明</h2>
<ul class="desc" style="list-style: disc; padding-left: 20px; line-height: 2;">
<li>使用 <code>agnes-2.0-flash</code> 作为模型名称。</li>
<li>基础 Chat Completion 请求必须包含 <code>model</code><code>messages</code></li>
<li><code>messages[].content</code> 可使用纯文本字符串,也可使用包含文本和图片 URL 的内容数组。</li>
<li>如需输入图片,请使用 <code>image_url</code> 并提供公网可访问的图片 URL。</li>
<li>如需启用流式响应,请将 <code>stream</code> 设置为 <code>true</code></li>
<li>对于工具调用工作流,请提供 <code>tools</code>,并可按需提供 <code>tool_choice</code></li>
<li><code>temperature</code> 用于控制随机性。较低值更适合确定性任务,较高值更适合创意生成。</li>
<li>Agnes-2.0-Flash 适合需要快速响应、强任务完成能力、图片理解能力和可靠智能体表现的生产级应用。</li>
</ul>
</section>
<!-- FOOTER -->
<div style="text-align:center; padding: 40px 0 20px; color: var(--text-dim); font-size: 13px; border-top: 1px solid var(--border);">
<p>&#x1F4C4; 本文档基于 Agnes-2.0-Flash 官方 API 文档整理</p>
<p>模型: <strong style="color:var(--accent)">agnes-2.0-flash</strong> · 开发商: <strong style="color:var(--accent)">Sapiens AI</strong> · 文档日期: <strong style="color:var(--accent)">2025-06-25</strong></p>
<p style="margin-top:8px;">API Endpoint: <a href="https://apihub.agnes-ai.com/v1" style="color:var(--accent)">https://apihub.agnes-ai.com/v1</a> · 兼容: <a href="https://platform.openai.com/docs/api-reference" style="color:var(--accent)">OpenAI Chat Completions API</a></p>
</div>
</div>
</div>
<script>
function switchTab(clickedTab, panelId) {
const tabContainer = clickedTab.parentElement;
const blockContainer = tabContainer.nextElementSibling;
tabContainer.querySelectorAll('.code-tab').forEach(t => t.classList.remove('active'));
blockContainer.querySelectorAll('.code-panel').forEach(p => p.classList.remove('active'));
clickedTab.classList.add('active');
document.getElementById(panelId).classList.add('active');
}
// Smooth scroll for sidebar links
document.querySelectorAll('.sidebar a[href^="#"]').forEach(a => {
a.addEventListener('click', e => {
e.preventDefault();
const target = document.querySelector(a.getAttribute('href'));
if (target) target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
// Highlight active sidebar item on scroll
const sections = document.querySelectorAll('.api-section');
const sidebarLinks = document.querySelectorAll('.sidebar a[href^="#"]');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(s => {
if (window.scrollY >= s.offsetTop - 100) current = s.id;
});
sidebarLinks.forEach(a => {
a.classList.toggle('active', a.getAttribute('href') === '#' + current);
});
});
</script>
</body>
</html>