{"id":48218526,"url":"https://github.com/codeany-ai/open-agent-sdk-rust","last_synced_at":"2026-04-05T20:00:31.773Z","repository":{"id":348630683,"uuid":"1198705761","full_name":"codeany-ai/open-agent-sdk-rust","owner":"codeany-ai","description":"Open Agent SDK - A Rust framework for building autonomous AI agents","archived":false,"fork":false,"pushed_at":"2026-04-03T15:59:40.000Z","size":132,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-04T19:57:38.604Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/codeany-ai.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-01T17:19:01.000Z","updated_at":"2026-04-04T11:55:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/codeany-ai/open-agent-sdk-rust","commit_stats":null,"previous_names":["codeany-ai/open-agent-sdk-rust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeany-ai/open-agent-sdk-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeany-ai%2Fopen-agent-sdk-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeany-ai%2Fopen-agent-sdk-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeany-ai%2Fopen-agent-sdk-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeany-ai%2Fopen-agent-sdk-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeany-ai","download_url":"https://codeload.github.com/codeany-ai/open-agent-sdk-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeany-ai%2Fopen-agent-sdk-rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31448216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T15:22:31.103Z","status":"ssl_error","status_checked_at":"2026-04-05T15:22:00.205Z","response_time":75,"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":[],"created_at":"2026-04-04T19:03:05.282Z","updated_at":"2026-04-05T20:00:31.767Z","avatar_url":"https://github.com/codeany-ai.png","language":"Rust","readme":"# Open Agent SDK (Rust)\n\nA lightweight, open-source Rust SDK for building AI agents. Run the full agent loop in-process — no CLI or subprocess required. Deploy anywhere: cloud, serverless, Docker, CI/CD.\n\nAlso available in [TypeScript](https://github.com/codeany-ai/open-agent-sdk-typescript) and [Go](https://github.com/codeany-ai/open-agent-sdk-go).\n\n## Features\n\n- **Multi-Provider** — Supports both Anthropic Messages API and OpenAI Chat Completions API, with auto-detection by model name\n- **Agent Loop** — Streaming agentic loop with tool execution, multi-turn conversations, and cost tracking\n- **25+ Built-in Tools** — Bash, Read, Write, Edit, Glob, Grep, WebFetch, WebSearch, Agent (subagents), AskUser, Tasks, Teams, Plans, Worktrees, Todos, Cron, LSP, Config, MCP Resources, ToolSearch\n- **Session Persistence** — Save, load, fork, and resume conversations across sessions\n- **MCP Support** — Connect to MCP servers via stdio, HTTP, and SSE transports\n- **Permission System** — Configurable tool approval with allow/deny rules and filesystem path validation\n- **Hook System** — 20+ hook events: PreToolUse, PostToolUse, SessionStart/End, SubagentStart/Stop, TaskCreated/Completed, FileChanged, PreCompact/PostCompact, and more\n- **Extended Thinking** — Support for extended thinking with budget tokens\n- **Cost Tracking** — Per-model token usage and pricing for Anthropic, OpenAI, and DeepSeek models\n- **Custom Tools** — Implement the `Tool` trait to add your own tools\n- **Auto-Compaction** — Multi-tier context compression (micro-compact, LLM summarization, image stripping)\n- **Sandbox Config** — Network and filesystem restrictions for tool execution\n- **File State Cache** — LRU cache for file state tracking and staleness detection\n\n## Quick Start\n\n```toml\n[dependencies]\nopen-agent-sdk = \"0.1.0\"\ntokio = { version = \"1\", features = [\"full\"] }\n```\n\n```rust\nuse open_agent_sdk::{Agent, AgentOptions, SDKMessage};\nuse open_agent_sdk::types;\n\n#[tokio::main]\nasync fn main() {\n    let mut agent = Agent::new(AgentOptions::default()).await.unwrap();\n\n    // Streaming\n    let (mut rx, handle) = agent.query(\"What files are in this directory?\").await;\n    while let Some(event) = rx.recv().await {\n        match event {\n            SDKMessage::Assistant { message, .. } =\u003e {\n                print!(\"{}\", types::extract_text(\u0026message));\n            }\n            SDKMessage::Result { text, cost_usd, .. } =\u003e {\n                println!(\"\\nDone (${:.4})\", cost_usd);\n            }\n            _ =\u003e {}\n        }\n    }\n    handle.await.unwrap();\n\n    // Or use the blocking API\n    let result = agent.prompt(\"Count lines in Cargo.toml\").await.unwrap();\n    println!(\"{}\", result.text);\n\n    agent.close().await;\n}\n```\n\n## Examples\n\n| #   | Example                                                         | Description                                      |\n| --- | --------------------------------------------------------------- | ------------------------------------------------ |\n| 01  | [Simple Query](examples/01-simple-query.rs)                     | Streaming query with tool calls                  |\n| 02  | [Multi-Tool](examples/02-multi-tool.rs)                         | Glob + Bash multi-tool orchestration             |\n| 03  | [Multi-Turn](examples/03-multi-turn.rs)                         | Multi-turn conversation with session persistence |\n| 04  | [Prompt API](examples/04-prompt-api.rs)                         | Blocking `prompt()` for one-shot queries         |\n| 05  | [Custom System Prompt](examples/05-custom-system-prompt.rs)     | Custom system prompt for code review             |\n| 06  | [MCP Server](examples/06-mcp-server.rs)                         | MCP server integration (stdio transport)         |\n| 07  | [Custom Tools](examples/07-custom-tools.rs)                     | Define and use custom tools                      |\n| 08  | [One-shot Query](examples/08-oneshot-query.rs)                  | Quick one-shot agent query                       |\n| 09  | [Subagents](examples/09-subagents.rs)                           | Specialized subagent with restricted tools       |\n| 10  | [Permissions](examples/10-permissions.rs)                       | Read-only agent with allowed tools               |\n| 11  | [Web Chat](examples/web/)                                       | Web-based chat UI with streaming                 |\n\nRun any example:\n\n```bash\nexport CODEANY_BASE_URL=https://openrouter.ai/api\nexport CODEANY_API_KEY=your-api-key\nexport CODEANY_MODEL=anthropic/claude-sonnet-4\ncargo run --example 01-simple-query\n```\n\nFor the web chat UI:\n\n```bash\ncargo run --example web-chat\n# Open http://localhost:8082\n```\n\n## Custom Tools\n\nImplement the `Tool` trait:\n\n```rust\nuse async_trait::async_trait;\nuse open_agent_sdk::*;\nuse serde_json::{json, Value};\nuse std::collections::HashMap;\nuse std::sync::Arc;\n\nstruct MyTool;\n\n#[async_trait]\nimpl Tool for MyTool {\n    fn name(\u0026self) -\u003e \u0026str { \"MyTool\" }\n    fn description(\u0026self) -\u003e \u0026str { \"Does something useful\" }\n    fn input_schema(\u0026self) -\u003e ToolInputSchema {\n        ToolInputSchema {\n            schema_type: \"object\".to_string(),\n            properties: HashMap::from([(\n                \"input\".to_string(),\n                json!({\"type\": \"string\", \"description\": \"The input\"}),\n            )]),\n            required: vec![\"input\".to_string()],\n            additional_properties: Some(false),\n        }\n    }\n    fn is_read_only(\u0026self, _: \u0026Value) -\u003e bool { true }\n    async fn call(\u0026self, input: Value, _ctx: \u0026ToolUseContext) -\u003e Result\u003cToolResult, ToolError\u003e {\n        Ok(ToolResult::text(\"result\"))\n    }\n}\n\n// Use it\nlet agent = Agent::new(AgentOptions {\n    custom_tools: vec![Arc::new(MyTool)],\n    ..Default::default()\n}).await.unwrap();\n```\n\n## Session Persistence\n\n```rust\nuse open_agent_sdk::session::*;\n\n// Save current session\nsave_session(\u0026session_data).await.unwrap();\n\n// List all sessions\nlet sessions = list_sessions().await.unwrap();\n\n// Resume a session\nlet data = load_session(\"session-id\").await.unwrap();\n\n// Fork a session\nlet new_id = fork_session(\"session-id\").await.unwrap();\n```\n\n## MCP Servers\n\n```rust\nuse open_agent_sdk::types::McpServerConfig;\n\nlet agent = Agent::new(AgentOptions {\n    mcp_servers: HashMap::from([(\n        \"filesystem\".to_string(),\n        McpServerConfig::Stdio {\n            command: \"npx\".to_string(),\n            args: vec![\"-y\".to_string(), \"@modelcontextprotocol/server-filesystem\".to_string(), \"/tmp\".to_string()],\n            env: HashMap::new(),\n        },\n    )]),\n    ..Default::default()\n}).await.unwrap();\n```\n\n## Built-in Tools\n\n| Tool | Description | Read-Only |\n|------|-------------|-----------|\n| **Bash** | Execute shell commands | No |\n| **Read** | Read files with line numbers | Yes |\n| **Write** | Create/overwrite files | No |\n| **Edit** | String replacement in files | No |\n| **Glob** | File pattern matching | Yes |\n| **Grep** | Regex search (ripgrep) | Yes |\n| **NotebookEdit** | Edit Jupyter notebook cells | No |\n| **WebFetch** | Fetch URL content | Yes |\n| **WebSearch** | Web search (pluggable) | Yes |\n| **AskUserQuestion** | Interactive user prompts | No |\n| **SendMessage** | Inter-agent messaging | No |\n| **TeamCreate/Delete** | Multi-agent team management | No |\n| **EnterPlanMode/ExitPlanMode** | Structured planning mode | No |\n| **EnterWorktree/ExitWorktree** | Git worktree isolation | No |\n| **TodoWrite** | Session todo list | No |\n| **TaskCreate/Get/List/Update/Stop/Output** | Task tracking (6 tools) | Mixed |\n| **CronCreate/Delete/List** | Scheduled task management | Mixed |\n| **Config** | Session configuration | Mixed |\n| **LSP** | Language Server Protocol operations | Yes |\n| **ListMcpResources/ReadMcpResource** | MCP resource access | Yes |\n| **ToolSearch** | Discover available tools | Yes |\n\n## Multi-Provider Support\n\nThe SDK automatically detects which API format to use based on the model name:\n\n| Models | API Format | Auto-detected |\n|--------|-----------|---------------|\n| Claude (sonnet, opus, haiku) | Anthropic Messages | Yes |\n| GPT-4o, O1, O3, O4 | OpenAI Chat Completions | Yes |\n| DeepSeek, Qwen, Mistral | OpenAI Chat Completions | Yes |\n| LLaMA, Gemma, Gemini, Yi, GLM | OpenAI Chat Completions | Yes |\n\nOverride with `CODEANY_API_TYPE=openai-completions` or `CODEANY_API_TYPE=anthropic-messages`.\n\nWorks with any OpenAI-compatible endpoint (OpenRouter, vLLM, Ollama, LiteLLM, etc.):\n\n```bash\nexport CODEANY_BASE_URL=https://openrouter.ai/api\nexport CODEANY_API_KEY=your-key\nexport CODEANY_MODEL=anthropic/claude-sonnet-4\ncargo run --example 01-simple-query\n```\n\n## Architecture\n\n```\nopen-agent-sdk-rust/\n├── src/\n│   ├── agent/          # Agent loop, query engine, options\n│   ├── api/            # Multi-provider API abstraction\n│   │   ├── provider.rs # LLMProvider trait + auto-detection\n│   │   ├── anthropic.rs# Anthropic Messages API (SSE streaming)\n│   │   └── openai.rs   # OpenAI Chat Completions API (SSE streaming)\n│   ├── types/          # Core types: Message, Tool, ContentBlock, MCP, Sandbox\n│   ├── tools/          # 25+ built-in tool implementations + registry + executor\n│   ├── mcp/            # MCP client (stdio, HTTP, SSE) + tool wrapping\n│   ├── permissions/    # Permission rules, filesystem validation\n│   ├── hooks/          # 20+ hook events with pre/post tool-use lifecycle\n│   ├── costtracker/    # Token usage and cost tracking (Anthropic, OpenAI, DeepSeek)\n│   ├── context/        # System/user context injection (git status, AGENT.md)\n│   ├── session/        # Session persistence (save, load, fork, resume)\n│   └── utils/          # Token estimation, retry, messages, compaction, file cache\n├── tests/              # Comprehensive test suite (116 tests)\n└── examples/           # 11 runnable examples + web chat UI\n```\n\n## Configuration\n\nEnvironment variables:\n\n| Variable                     | Description                                           |\n| ---------------------------- | ----------------------------------------------------- |\n| `CODEANY_API_KEY`            | API key (required)                                    |\n| `CODEANY_MODEL`              | Default model (default: `sonnet-4-6`)                 |\n| `CODEANY_BASE_URL`           | API base URL override                                 |\n| `CODEANY_API_TYPE`           | Force API format: `anthropic-messages` or `openai-completions` |\n| `CODEANY_CUSTOM_HEADERS`     | Custom headers (comma-separated `key:value`)          |\n| `API_TIMEOUT_MS`             | API request timeout in ms                             |\n| `HTTPS_PROXY` / `HTTP_PROXY` | Proxy URL                                             |\n\n## Links\n\n- Website: [codeany.ai](https://codeany.ai)\n- TypeScript SDK: [github.com/codeany-ai/open-agent-sdk-typescript](https://github.com/codeany-ai/open-agent-sdk-typescript)\n- Go SDK: [github.com/codeany-ai/open-agent-sdk-go](https://github.com/codeany-ai/open-agent-sdk-go)\n- Issues: [github.com/codeany-ai/open-agent-sdk-rust/issues](https://github.com/codeany-ai/open-agent-sdk-rust/issues)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeany-ai%2Fopen-agent-sdk-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeany-ai%2Fopen-agent-sdk-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeany-ai%2Fopen-agent-sdk-rust/lists"}