Snak

Um mecanismo de agente para criar Agentes de IA poderosos

Documentação

Um Agent Engine para criar Agentes de IA poderosos e seguros, alimentado pela Starknet. Disponível tanto como pacote NPM quanto como backend pronto para uso.

Início Rápido

Pré-requisitos

  • Carteira Starknet (recomendada: Argent X)
  • Chave de API do provedor de IA (Anthropic/OpenAI/Google Gemini/Ollama)
  • Docker e Docker compose instalados
  • Node.js e pnpm instalados

Instalação

git clone https://github.com/kasarlabs/snak.git
cd snak
pnpm install

Configuração

  1. Crie um arquivo .env copiando .env.example:
cp .env.example .env

Em seguida, preencha os valores necessários no seu arquivo .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"
  1. Configure os Modelos de IA (Opcional): O arquivo config/models/default.models.json define os modelos de IA padrão usados para diferentes tarefas (fast, smart, cheap). Você pode personalizar este arquivo ou criar novas configurações de modelo (por exemplo, my_models.json) e especificá-las ao executar o agente. Consulte config/models/example.models.json para ver a estrutura.

    O agente usa o campo provider na configuração do modelo para determinar qual chave de API carregar do arquivo .env (por exemplo, se provider for openai, ele carrega OPENAI_API_KEY).

  2. Crie seu arquivo de configuração do agente (por exemplo, default.agent.json ou my_agent.json) no diretório config/agents/:

{
  "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"]
    }
  }
}

Você pode simplesmente criar sua própria configuração de agente usando nossa ferramenta em snakagent

Uso

Modo Prompt

Execute o prompt:

# 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"

Modo Servidor

Execute o servidor:

# 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"

Modos Disponíveis

Modo InterativoModo Autônomo
Modo Prompt✅✅
Modo Servidor✅✅

Implemente o Snak no seu projeto

  1. Instale o pacote snak
#using npm
npm install @snakagent

# using pnpm
pnpm add @snakagent
  1. Crie sua instância de agente
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?");

Ações

Para saber mais sobre ações, você pode ler esta seção da documentação. Uma interface abrangente no Kit fornecerá um catálogo de fácil navegação com todos os plugins disponíveis e suas ações, tornando a descoberta e o uso mais simples.

Para adicionar ações ao seu agente, você pode seguir facilmente o guia passo a passo aqui

Contribuição

Contribuições são bem-vindas! Sinta-se à vontade para enviar um Pull Request.

Licença

Licença MIT - consulte o arquivo LICENSE para obter detalhes.


Para documentação detalhada, visite docs.kasar.io