{"id":48072041,"url":"https://github.com/sweihub/ai-agent-sdk","last_synced_at":"2026-04-08T18:00:31.443Z","repository":{"id":348648482,"uuid":"1199158410","full_name":"sweihub/ai-agent-sdk","owner":"sweihub","description":"Idiomatic agent sdk inspired by the claude code source leak.","archived":false,"fork":false,"pushed_at":"2026-04-07T14:45:05.000Z","size":1446,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-07T17:02:46.876Z","etag":null,"topics":["claude-agent-sdk","claudecode"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sweihub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-02T05:11:28.000Z","updated_at":"2026-04-07T14:46:36.000Z","dependencies_parsed_at":"2026-04-08T18:00:27.940Z","dependency_job_id":null,"html_url":"https://github.com/sweihub/ai-agent-sdk","commit_stats":null,"previous_names":["sweihub/ai-agent-sdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sweihub/ai-agent-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweihub%2Fai-agent-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweihub%2Fai-agent-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweihub%2Fai-agent-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweihub%2Fai-agent-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sweihub","download_url":"https://codeload.github.com/sweihub/ai-agent-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sweihub%2Fai-agent-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31567227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["claude-agent-sdk","claudecode"],"created_at":"2026-04-04T14:43:51.043Z","updated_at":"2026-04-08T18:00:31.426Z","avatar_url":"https://github.com/sweihub.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Agent SDK (Rust)\n\n[![Crates.io](https://img.shields.io/crates/v/ai-agent-sdk)](https://crates.io/crates/ai-agent-sdk)\n[![Rust](https://img.shields.io/badge/rust-%3E%3D1.70-blue)](https://www.rust-lang.org)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)\n\n[English](README.md) | [中文](READCN.md)\n\nOne to one Rust translation of `claude code source`.\n\nIdiomatic agent sdk inspired by the `claude code source` leak, written in Rust that runs the full agent loop **in-process** — no subprocess or CLI required. Deploy anywhere: cloud, serverless, Docker, CI/CD.\n\n## Quick Demo\n\n```rust\nuse ai_agent_sdk::Agent;\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\nlet result = agent.prompt(\"List files in current directory\").await?;\nprintln!(\"{}\", result.text);\n```\n\n\u003e That's it! The agent automatically uses 20+ built-in tools (Bash, Read, Write, Edit, Glob, Grep, WebFetch, etc.) to accomplish tasks.\n\n## Core Features\n\n| Feature | Description |\n|---------|-------------|\n| **Agent** | Create agents with custom models, tools, and prompts |\n| **Subagent** | Spawn subagents for parallel or specialized tasks |\n| **Session** | Persist, resume, fork conversations on disk |\n| **Skills** | Load external skills or use 15+ bundled skills |\n| **Command** | Register and execute slash commands with arguments |\n| **Plugin** | Load plugins with commands, skills, MCP servers |\n| **Hooks** | 20+ lifecycle events for custom workflows |\n| **Tools** | 20+ built-in tools + custom tool registration |\n| **Memory** | Automatic session memory management |\n| **Permission** | Tool access control with modes and rules |\n| **Services** | Retry, rate limiting, token estimation, model cost |\n\n## Quick Start\n\nInstall:\n\n```bash\ncargo add ai-agent-sdk\n```\n\nConfigure your API key:\n\n```bash\nexport AI_AUTH_TOKEN=your-api-key\nexport AI_MODEL=MiniMaxAI/MiniMax-M2.5\n```\n\nOr use `.env` file:\n\n```text\nAI_AUTH_TOKEN=your-token\nAI_MODEL=MiniMaxAI/MiniMax-M2.5\nAI_BASE_URL=https://api.minimax.chat/v1\n```\n\n### Simple Prompt\n\n```rust\nuse ai_agent_sdk::Agent;\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\nlet result = agent.prompt(\"What files are in this project?\").await?;\nprintln!(\"{}\", result.text);\n```\n\n### Multi-turn Conversation\n\n```rust\nuse ai_agent_sdk::Agent;\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 5);\nlet r1 = agent.prompt(\"Create file /tmp/hello.txt with 'Hello'\").await?;\nlet r2 = agent.prompt(\"Read that file back\").await?;\nprintln!(\"Session messages: {}\", agent.get_messages().len());\n```\n\n### Custom Tools\n\n```rust\nuse ai_agent_sdk::{Agent, ToolDefinition, ToolInputSchema};\n\nfn calculator_impl(input: serde_json::Value, _ctx: ()) -\u003e impl std::future::Future\u003cOutput = Result\u003cai_agent_sdk::ToolResult, ai_agent_sdk::AgentError\u003e\u003e + Send {\n    async move {\n        let expr = input[\"expression\"].as_str().unwrap_or(\"0\");\n        Ok(ai_agent_sdk::ToolResult {\n            result_type: \"tool_result\".to_string(),\n            tool_use_id: \"\".to_string(),\n            content: format!(\"Result of {}\", expr),\n            is_error: None,\n        })\n    }\n}\n\nlet calculator = ai_agent_sdk::Tool {\n    name: \"Calculator\".to_string(),\n    description: \"Evaluate math expressions\".to_string(),\n    input_schema: ToolInputSchema::Json(serde_json::json!({\n        \"type\": \"object\",\n        \"properties\": {\"expression\": {\"type\": \"string\"}},\n        \"required\": [\"expression\"]\n    })),\n    executor: Box::new(calculator_impl),\n};\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\n// Note: Tool registration via agent tools currently uses ToolDefinition\n```\n\n### MCP Servers\n\n```rust\nuse ai_agent_sdk::{Agent, McpServerConfig};\n\nlet config = McpServerConfig::Stdio(ai_agent_sdk::McpStdioConfig {\n    command: \"npx\".to_string(),\n    args: Some(vec![\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/tmp\"]),\n    ..Default::default()\n});\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\n// Note: MCP servers configured via AgentOptions\n```\n\n### Subagents\n\n```rust\nuse ai_agent_sdk::{Agent, AgentDefinition};\n\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\n// Note: Subagents are used via the Agent tool at runtime\n```\n\n### Skills\n\n```rust\nuse ai_agent_sdk::{Agent, load_skill_from_dir};\n\nlet skill = load_skill_from_dir(\"skills/debug\")?;\nlet mut agent = Agent::new(\"MiniMaxAI/MiniMax-M2.5\", 10);\n// Note: Skills are applied via agent configuration\n```\n\n### Plugin System\n\n```rust\nuse ai_agent_sdk::{load_plugin, load_plugins_from_dir, CommandRegistry};\n\nlet plugin = load_plugin(\"plugins/hello-plugin\").await?;\nlet plugins = load_plugins_from_dir(\"plugins\").await?;\nlet registry = CommandRegistry::new();\n```\n\n### Hooks\n\n```rust\nuse ai_agent_sdk::hooks::{HookRegistry, HookDefinition, HookInput};\n\nlet mut registry = HookRegistry::new();\nregistry.register(\"PreToolUse\", HookDefinition {\n    command: Some(\"echo pre-tool\".to_string()),\n    timeout: Some(5000),\n    matcher: Some(\"Read.*\".to_string()),\n});\n\nlet mut input = HookInput::new(\"PreToolUse\");\ninput.tool_name = Some(\"Read\".to_string());\nlet results = registry.execute(\"PreToolUse\", input).await;\n```\n\n## Configuration\n\n### Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `model` | string | MiniMaxAI/MiniMax-M2.5 | LLM model ID |\n| `api_key` | string | env var | API key |\n| `base_url` | string | — | Custom API endpoint |\n| `cwd` | string | process.cwd() | Working directory |\n| `max_turns` | u32 | 10 | Max agentic turns |\n| `max_budget_usd` | f64 | — | Spending cap |\n| `max_tokens` | u32 | 16384 | Max response tokens |\n| `tools` | Vec\u003cToolDefinition\u003e | All built-in | Available tools |\n| `allowed_tools` | Vec\u003cString\u003e | — | Tool allow-list |\n| `disallowed_tools` | Vec\u003cString\u003e | — | Tool deny-list |\n\n### Environment Variables\n\n| Variable | Description |\n|----------|-------------|\n| `AI_AUTH_TOKEN` | API authentication token (required) |\n| `AI_MODEL` | Model name |\n| `AI_BASE_URL` | API endpoint |\n\n### Context \u0026 Memory\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `AI_CONTEXT_WINDOW` | 200000 | Override context window size |\n| `AI_DISABLE_AUTO_MEMORY` | false | Disable automatic memory |\n| `AI_MEMORY_PATH_OVERRIDE` | ~/.ai | Override memory directory |\n| `AI_REMOTE_MEMORY_DIR` | — | Remote/shared memory directory |\n| `AI_SIMPLE` | false | Use simple memory mode |\n\n### Auto-Compact\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `AI_AUTO_COMPACT_WINDOW` | model-based | Override auto-compact trigger window |\n| `AI_AUTOCOMPACT_PCT_OVERRIDE` | — | Override threshold as % (0-100) |\n| `AI_BLOCKING_LIMIT_OVERRIDE` | — | Override blocking limit for testing |\n\n## Built-in Tools\n\n| Tool | Description |\n|------|-------------|\n| **Bash** | Execute shell commands |\n| **Read** | Read files with line numbers |\n| **Write** | Create / overwrite files |\n| **Edit** | Precise string replacement |\n| **Glob** | Find files by pattern |\n| **Grep** | Search with regex |\n| **WebFetch** | Fetch web content |\n| **WebSearch** | Web search |\n| **NotebookEdit** | Edit Jupyter cells |\n| **Agent** | Spawn subagents |\n| **TaskCreate/List/Update/Get** | Task management |\n| **TeamCreate/Delete** | Multi-agent teams |\n| **SendMessage** | Inter-agent messaging |\n| **EnterWorktree/ExitWorktree** | Git worktree |\n| **EnterPlanMode/ExitPlanMode** | Planning workflow |\n| **AskUserQuestion** | Request user input |\n| **CronCreate/Delete/List** | Scheduled tasks |\n| **TodoWrite** | Session todo list |\n\n## Architecture\n\n```\n┌─────────────────────────────────────┐\n│         Your Application             │\n│   use ai_agent_sdk::Agent            │\n└──────────────┬──────────────────────┘\n               │\n    ┌──────────▼──────────┐\n    │       Agent         │  Session state, tools\n    │    prompt()         │  MCP connections\n    └──────────┬──────────┘\n               │\n    ┌──────────▼──────────┐\n    │    QueryEngine      │  Agent loop:\n    │   submitMessage()   │  API → tools → repeat\n    └──────────┬──────────┘\n               │\n    ┌──────────┼──────────┐\n    │          │          │\n┌───▼───┐  ┌───▼───┐  ┌──▼────┐\n│  LLM  │  │ 20+   │  │  MCP  │\n│  API  │  │Tools  │  │Server │\n└───────┘  └───────┘  └───────┘\n```\n\n## Examples\n\nRun examples from `examples/` directory:\n\n```bash\n# Configure your .env first\ncargo run --example 01_simple_query\ncargo run --example 18_plugin\ncargo run --example 19_hooks\n```\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsweihub%2Fai-agent-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsweihub%2Fai-agent-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsweihub%2Fai-agent-sdk/lists"}