context_fragments 按主体存放,由 pgvector 支撑。直接调 API 也行,用 SDK 也行:Python、Rust、Swift、Kotlin 与 TypeScript 的 SDK 形态都与 OpenAI Agents SDK 一致。
基础 URL
https://agent.ariacompute.cn
https://agent.ariacompute.com。
认证
用下面任一方案,在Authorization 头里传 API 密钥:
Authorization: Bearer <api_key>Authorization: ApiKey <key>
- 出示的密钥等于
AGENT_CLOUD_API_KEY→ 引导 Admin 主体。 - 否则按 sha256 在
api_keys表中查找。 - 未出示密钥:已设置
AGENT_CLOUD_API_KEY就返回401;未设置则以 开放模式 运行,主体是default租户。
/v1/api-keys 上管理,需要 admin 作用域。
错误格式
错误返回 HTTP 状态码,外加 OpenAI 形态的 JSON 响应体;响应体里还有一个扁平的message 字段,用于兼容 Aria 客户端:
{
"error": {
"message": "Description of what went wrong",
"type": "400 Bad Request"
},
"message": "Description of what went wrong"
}
语言绑定
AGENT API 提供 Python、Rust、Swift、Kotlin 与 TypeScript 的 SDK,形态都与 OpenAI Agents SDK 一致。# pip install ariacompute-agent
import asyncio
import os
from ariacompute_agent import Agent, ClientOptions, Runner, Session, function_tool
# Cloud SDK — talks to the beta Agents REST API.
client = ClientOptions(
base_url=os.environ.get("ARIA_AGENT_BASE_URL", "https://agent.ariacompute.cn"),
api_key=os.environ.get("AGENT_CLOUD_API_KEY"),
)
@function_tool
def history_fun_fact() -> str:
"""Return a short history fact."""
return "Sharks are older than trees."
agent = Agent(
name="History tutor",
instructions="Answer history questions clearly and concisely.",
model="gpt-4o-mini",
tools=[history_fun_fact],
client=client,
# memory backend: cloud | local (aria memo) | both
memory_backend="both",
memo_db="~/.ariacompute/memo.db",
)
async def main() -> None:
session = Session.create(agent, client)
# 1) One-shot run.
first = await Runner.run(agent, "When did the Roman Empire fall?", session=session)
print(first.final_output)
# Long-term memory: memorize persists a fact that every later turn of the
# session can recall — Postgres + pgvector in the cloud, aria memo locally.
session.memorize("user_name", "Ada")
# 2) Continue the same conversation by reusing the session.
second = await Runner.run(agent, "What is my name?", session=session)
print(second.final_output)
print(session.recall("user_name")) # -> "Ada"
print(session.recall("user_name", backend="local")) # aria memo copy only
# 3) Streaming run — agent.turn.* events.
streamed = await Runner.run_streamed(agent, "Tell me something surprising", session=session)
async for event in streamed.events:
if event["type"] == "agent.turn.output_text.delta":
print(event["delta"], end="")
print((await streamed.completed).final_output)
asyncio.run(main())
// cargo add ariacompute-agent
use aria_agent_ffi::{
create_agent_with, SdkAgentConfig, SdkAgentListener, SdkMemoryConfig, SdkStreamEvent,
};
struct Printer;
impl SdkAgentListener for Printer {
fn on_event(&self, event: SdkStreamEvent) {
if let SdkStreamEvent::Token { text } = event {
print!("{text}");
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Native SDK — the runtime embedded in-process (no server, no network).
// No session argument: the runtime assigns one isolated context scope per agent.
// memory.backend selects cloud | local (aria memo) | both; default is local.
let agent = create_agent_with(SdkAgentConfig {
agent_name: "History tutor".into(),
instructions: "Answer history questions clearly and concisely.".into(),
model: "gpt-4o-mini".into(),
memory: SdkMemoryConfig {
backend: "both".into(),
local_db_path: "~/.ariacompute/memo.db".into(),
cloud_base_url: std::env::var("ARIA_AGENT_BASE_URL")
.unwrap_or_else(|_| "https://agent.ariacompute.cn".into()),
cloud_api_key: String::new(),
},
..Default::default()
})?;
// 1) One-shot run.
println!("{}", agent.run("When did the Roman Empire fall?".into())?);
// Long-term memory: memorize persists a fact that later turns recall.
let session = agent.session();
session.memorize("user_name".into(), "Ada".into())?;
// 2) Continue the same conversation (same agent / session scope).
println!("{}", agent.run("What is my name?".into())?);
println!("{:?}", session.recall("user_name".into(), None)?); // Some("Ada")
println!("{:?}", session.recall("user_name".into(), Some("local".into()))?); // aria memo only
// 3) Streaming run — events are pushed to the listener.
agent.run_stream("Tell me something surprising".into(), Box::new(Printer))?;
Ok(())
}
// pod 'AriaComputeAgent'
import AriaComputeAgent
do {
// Native SDK — the runtime embedded in-process (no server, no network).
// memory.backend selects cloud | local (aria memo) | both; default is local.
let agent = try createAgentWith(config: SdkAgentConfig(
agentName: "History tutor",
instructions: "Answer history questions clearly and concisely.",
model: "gpt-4o-mini",
sandboxProvider: "docker",
memory: SdkMemoryConfig(
backend: "both",
localDbPath: "~/.ariacompute/memo.db",
cloudBaseUrl: "https://agent.ariacompute.cn",
cloudApiKey: ""
)
))
// 1) One-shot run.
print(try agent.run("When did the Roman Empire fall?"))
// Long-term memory: memorize persists a fact that later turns recall.
let session = agent.session()
try session.memorize(key: "user_name", value: "Ada", backend: nil)
// 2) Continue the same conversation (same agent / session scope).
print(try agent.run("What is my name?"))
print(try session.recall(key: "user_name", backend: nil) ?? "") // -> "Ada"
print(try session.recall(key: "user_name", backend: "local") ?? "") // aria memo only
// 3) Streaming run — events are delivered to the listener.
try agent.runStream("Tell me something surprising", listener: Printer())
} catch {
print(error)
}
// implementation("com.ariacompute:agent:+")
import com.ariacompute.agent.uniffi.aria_agent_ffi.*
fun main() {
// Native SDK — the runtime embedded in-process (no server, no network).
// memory.backend selects cloud | local (aria memo) | both; default is local.
val agent = createAgentWith(
SdkAgentConfig(
agentName = "History tutor",
instructions = "Answer history questions clearly and concisely.",
model = "gpt-4o-mini",
sandboxProvider = "docker",
memory = SdkMemoryConfig(
backend = "both",
localDbPath = "~/.ariacompute/memo.db",
cloudBaseUrl = "https://agent.ariacompute.cn",
cloudApiKey = ""
)
)
)
// 1) One-shot run.
println(agent.run("When did the Roman Empire fall?"))
// Long-term memory: memorize persists a fact that later turns recall.
val session = agent.session()
session.memorize("user_name", "Ada", null)
// 2) Continue the same conversation (same agent / session scope).
println(agent.run("What is my name?"))
println(session.recall("user_name", null)) // -> "Ada"
println(session.recall("user_name", "local")) // aria memo only
// 3) Streaming run — events are delivered to the listener.
agent.runStream("Tell me something surprising", Printer())
}
// npm i @ariacompute/agent
import { Agent, run, runStreamed, Session, tool } from "@ariacompute/agent";
// Cloud SDK — talks to the beta Agents REST API.
const client = {
baseUrl: process.env.ARIA_AGENT_BASE_URL ?? "https://agent.ariacompute.cn",
apiKey: process.env.AGENT_CLOUD_API_KEY,
};
const historyFunFact = tool({
name: "history_fun_fact",
description: "Return a short history fact.",
parameters: { type: "object", properties: {} },
});
const agent = new Agent({
name: "History tutor",
instructions: "Answer history questions clearly and concisely.",
model: "gpt-4o-mini",
tools: [historyFunFact],
client,
// memory backend: cloud | local (aria memo) | both
memory: { ...client, backend: "both", memoDb: "~/.ariacompute/memo.db" },
});
const session = await Session.create(agent, client);
// 1) One-shot run.
const first = await run(agent, "When did the Roman Empire fall?", { session });
console.log(first.finalOutput);
// Long-term memory: memorize persists a fact that every later turn of the
// session can recall — Postgres + pgvector in the cloud, aria memo locally.
await session.memorize("user_name", "Ada");
// 2) Continue the same conversation by reusing the session.
const second = await run(agent, "What is my name?", { session });
console.log(second.finalOutput);
console.log(await session.recall("user_name")); // -> "Ada"
console.log(await session.recall("user_name", { backend: "local" })); // aria memo only
// 3) Streaming run — agent.turn.* events.
const streamed = await runStreamed(agent, "Tell me something surprising", { session });
for await (const event of streamed.events) {
if (event.type === "agent.turn.output_text.delta") process.stdout.write(event.delta);
}
console.log((await streamed.completed).finalOutput);
版本管理
当前接口以/v1 为前缀,形态遵循 OpenAI Agents API。部分路由已被识别,但返回 HTTP 501 Not Implemented,不单独建文档页:
- Vaults:
GET|POST /v1/vaults、GET /v1/vaults/{vault_id}、GET /v1/vaults/{vault_id}/credentials - Environments:
GET|POST /v1/agents/environments、GET /v1/agents/environments/{environment_id}、GET|POST /v1/agents/environments/{environment_id}/files、GET /v1/agents/environments/templates - 会话产物:
GET /v1/agents/sessions/{session_id}/artifacts