关于 Snak
Snak 是用于构建 AI Agent 的 Agent 引擎,基于 Starknet,既提供 NPM 包,也提供可直接运行的后端。适合需要在 Starknet 上运行 Agent 的开发者,支持提示词模式与服务模式。
主要功能
- 01基于 Starknet 的 AI Agent 引擎
- 02可作为 NPM 包集成到项目中
- 03提供可直接运行的后端服务
- 04支持提示词模式与服务模式
- 05通过配置文件定义 Agent 与模型
适用场景
- 01在 Starknet 上构建自主或交互式 Agent
- 02将 Agent 能力嵌入现有 TypeScript 项目
- 03通过服务模式对外提供 Agent 接口
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/KasarLabs/brand/blob/main/projects/snak/snak-full-white-alpha.png?raw=true">
<img src="https://github.com/KasarLabs/brand/blob/main/projects/snak/snak-full-black-alpha.png?raw=true" width="200" alt="Snak 徽标">
一个用于创建强大、安全的 AI Agent 的 Agent Engine,由 Starknet 提供支持。既可作为 NPM 包使用,也提供可直接使用的后端。
快速开始
前提条件
- Starknet 钱包(推荐:Argent X)
- AI 提供商 API 密钥(Anthropic/OpenAI/Google Gemini/Ollama)
- 已安装 Docker 和 Docker compose
- 已安装 Node.js 和 pnpm
安装
git clone https://github.com/kasarlabs/snak.git
cd snak
pnpm install
配置
- 复制
.env.example创建.env文件:
cp .env.example .env
然后,在 .env 文件中填写必要的值:
# --- Starknet configuration (mandatory) ---
STARKNET_PUBLIC_ADDRESS="YOUR_STARKNET_PUBLIC_ADDRESS"
STARKNET_PRIVATE_KEY="YOUR_STARKNET_PRIVATE_KEY"
STARKNET_RPC_URL="YOUR_STARKNET_RPC_URL"
# --- AI Model API Keys (mandatory) ---
# Add the API keys for the specific AI providers you use in config/models/default.models.json
# The agent will automatically load the correct key based on the provider name.
# Example for OpenAI:
OPENAI_API_KEY="YOUR_OPENAI_API_KEY" # (e.g., sk-...)
# Example for Anthropic:
ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY" # (e.g., sk-ant-...)
# Example for Google Gemini:
GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
# Example for DeepSeek:
DEEPSEEK_API_KEY="YOUR_DEEPSEEK_API_KEY"
# Note: You do not need an API key if using a local Ollama model.
# --- General Agent Configuration (mandatory) ---
SERVER_API_KEY="YOUR_SERVER_API_KEY" # A secret key for your agent server API
SERVER_PORT="3001"
# --- PostgreSQL Database Configuration (mandatory) ---
POSTGRES_USER=admin
POSTGRES_HOST=localhost
POSTGRES_DB=postgres
POSTGRES_PASSWORD=admin
POSTGRES_PORT=5432
# --- LangSmith Tracing (Optional) ---
# Set LANGSMITH_TRACING=true to enable tracing
LANGSMITH_TRACING=false
LANGSMITH_ENDPOINT="https://api.smith.langchain.com"
LANGSMITH_API_KEY="YOUR_LANGSMITH_API_KEY" # (Only needed if LANGSMITH_TRACING=true)
LANGSMITH_PROJECT="Snak" # (Optional project name for LangSmith)
# --- Node Environment ---
NODE_ENV="development" # "development" or "production"
-
配置 AI 模型(可选):
config/models/default.models.json文件定义了用于不同任务(fast、smart、cheap)的默认 AI 模型。你可以自定义此文件,或创建新的模型配置(例如my_models.json),并在运行 Agent 时指定。有关其结构,请参阅config/models/example.models.json。Agent 使用模型配置中的
provider字段来确定从.env文件加载哪个 API 密钥(例如,如果provider为openai,则会加载OPENAI_API_KEY)。 -
在
config/agents/目录中创建 Agent 配置文件(例如default.agent.json或my_agent.json):
{
"name": "Your Agent name",
"group": "Your Agent group",
"description": "Your AI Agent Description",
"lore": ["Some lore of your AI Agent 1", "Some lore of your AI Agent 1"],
"objectives": [
"first objective that your AI Agent need to follow",
"second objective that your AI Agent need to follow"
],
"knowledge": [
"first knowledge of your AI Agent",
"second knowledge of your AI Agent"
],
"interval": "Your agent interval beetween each transaction of the Agent in ms,",
"chatId": "Your Agent Chat-id for isolating memory",
"max_iterations": "The number of iterations your agent will execute before stopping",
"mode": "The mode of your agent, can be interactive, autonomous or hybrid",
"memory": {
"enabled": "true or false to enable or disable memory",
"shortTermMemorySize": "The number of messages your agent will remember"
},
"plugins": ["Your first plugin", "Your second plugin"],
"mcp_servers": {
"nxp_server_example": {
"command": "npx",
"args": ["-y", "@npm_package_example/npx_server_example"],
"env": {
"API_KEY": "YOUR_API_KEY"
}
},
"local_server_example": {
"command": "node",
"args": ["node /path/to/local_server/dist/index.js"]
}
}
}
你也可以使用我们在 snakagent 上提供的工具,轻松创建自己的 Agent 配置。
使用方法
提示词模式
运行提示词:
# start with the default.agent.json
pnpm run start
# start with your custom configuration
pnpm run start --agent="name_of_your_config.json" --models="name_of_your_config.json"
服务模式
运行服务:
# start with the default.agent.json
pnpm run start:server
# start with your custom configuration
pnpm run start:server --agent="name_of_your_config.json" --models="name_of_your_config.json"
可用模式
| 交互模式 | 自主模式 | |
|---|---|---|
| 提示词模式 | ✅ | ✅ |
| 服务模式 | ✅ | ✅ |
在你的项目中集成 Snak
- 安装 snak 包
#using npm
npm install @snakagent
# using pnpm
pnpm add @snakagent
- 创建 Agent 实例
import { SnakAgent } from 'starknet-agent-kit';
const agent = new SnakAgent({
provider: new RpcProvider({ nodeUrl: process.env.STARKNET_RPC_URL }),
accountPrivateKey: process.env.STARKNET_PRIVATE_KEY,
accountPublicKey: process.env.STARKNET_PUBLIC_ADDRESS,
aiModel: process.env.AI_MODEL,
aiProvider: process.env.AI_PROVIDER,
aiProviderApiKey: process.env.AI_PROVIDER_API_KEY,
signature: 'key',
agentMode: 'interactive',
agentconfig: y,
});
const response = await agent.execute("What's my ETH balance?");
操作
如需进一步了解操作,请阅读此文档章节。 Kit 中的综合界面将提供易于浏览的目录,展示所有可用插件及其操作,让发现和使用更加简单。
如需为 Agent 添加操作,请按照此处的分步指南操作。
贡献
欢迎贡献!欢迎提交 Pull Request。
许可证
MIT License - 详情请参阅 LICENSE 文件。
如需详细文档,请访问 docs.kasar.io
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。