Co-Pilot / 辅助式
更新于 a month ago

kode-sdk-csharp

JJinFanZheng
0.0k
jinfanzheng/kode-sdk-csharp
80
Agent 评分

💡 摘要

一个用于构建AI代理的.NET SDK,支持多模型和全面的工具管理。

🎯 适合人群

构建AI应用的C#开发者企业软件架构师集成AI模型的数据科学家管理AI部署的DevOps工程师监督AI项目的技术项目经理

🤖 AI 吐槽:这个SDK就像是AI代理的瑞士军刀,但它有说明书吗?

安全分析中风险

该SDK可能暴露与命令执行和API密钥管理相关的风险。确保安全地使用环境变量并验证输入,以减轻潜在的注入攻击。

Kode Agent SDK for .NET

中文版: 查看中文 README

.NET License NuGet NuGet Downloads Build

A powerful AI Agent runtime SDK built on .NET 10, supporting Anthropic Claude and OpenAI GPT models, with comprehensive capabilities for tool calling, state management, event streaming, and more. Designed for building production-grade AI applications.

Project Background

Kode Agent SDK for .NET is the C# implementation of Kode SDK, providing feature parity with the TypeScript version:

  • Event-Driven Architecture - Three-channel event system (Progress, Control, Monitor) for separation of concerns
  • Complete State Management - Support for persistence, crash recovery, and resumable execution
  • Flexible Tool System - 20+ built-in tools with support for custom tools and MCP protocol
  • Multi-Model Support - Anthropic Claude, OpenAI GPT, and compatible APIs
  • Enterprise Features - Permission control, sandbox execution, dependency injection, logging integration

Table of Contents

Features

| Feature | Description | Documentation | | ----------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | Multi-Model Support | Support for Anthropic Claude (Claude 4, 3.5) and OpenAI GPT (GPT-4o, o1) series models, plus compatible APIs | Model Providers | | Rich Tool System | 20+ built-in tools (file system, shell, todo management, etc.), support for custom tools and MCP protocol | Tool Development Guide | | Three-Channel Event Stream | Progress (real-time output), Control (approval flow), Monitor (logging) separated architecture | Event System Details | | State Persistence | JSON file storage and Redis distributed storage, support for session recovery and resumable execution | State Storage | | Permission Control | Fine-grained tool permission management, support for auto-approval, manual approval, and deny policies | Permission Control System | | Sandbox Execution | Secure command execution environment, support for local and Docker sandboxes | Sandbox Environments | | Source Generator | Compile-time tool schema generation, zero reflection overhead, type-safe | Tool Development Guide | | MCP Integration | Native Model Context Protocol support, easy integration with external tool ecosystem | MCP Protocol Integration | | Dependency Injection | Complete Microsoft.Extensions.DependencyInjection support | Dependency Injection | | Template System | Predefined agent templates for quick creation of scenario-specific agents | Sub-Agent Delegation | | Skills System | Progressive skill discovery and activation, dynamic extension of agent capabilities | Skills System | | Sub-Agent Delegation | Support for task delegation to specialized sub-agents, enabling complex workflow orchestration | Sub-Agent Delegation |

Sandbox (Local vs Docker)

The SDK exposes a single ISandbox interface, but you can choose different implementations depending on your risk/performance needs:

| Dimension | LocalSandbox | DockerSandbox | |---|---|---| | Command execution | Runs commands on the host | Runs commands in a dedicated container | | Blast radius | Higher (host-wide if misused) | Lower (container + mounted paths) | | Toolchain | Uses host-installed tools | Depends on Docker image (DockerImage) | | Network | Same as host | Configurable (often none) |

More details: docs/ADVANCED_GUIDE.md#sandbox-environments.

Architecture Overview

graph TB subgraph Application["Application Layer"] App[Your Application] end subgraph Agent["Agent Core"] AgentCore[Agent] Config[AgentConfig] State[Runtime State] EventBus[EventBus] Skills[SkillsManager] end subgraph Dependencies["Dependencies"] Store[(AgentStore)] Registry[ToolRegistry] Provider[ModelProvider] Sandbox[Sandbox] end subgraph Tools["Tools"] Builtin[Builtin Tools] Custom[Custom Tools] MCP[MCP Tools] SkillTools[Skill Tools] TaskRun[task_run<br/>Sub-Agent] end subgraph Providers["Model Providers"] Anthropic[Anthropic Claude] OpenAI[OpenAI GPT] Compatible[Compatible APIs] end subgraph Storage["Storage"] JSON[(JSON Store)] Redis[(Redis Store)] end App --> AgentCore AgentCore --> Config AgentCore --> State AgentCore --> EventBus AgentCore --> Skills AgentCore --> Store AgentCore --> Registry AgentCore --> Provider AgentCore --> Sandbox Registry --> Builtin Registry --> Custom Registry --> MCP Registry --> SkillTools Registry --> TaskRun Provider --> Anthropic Provider --> OpenAI Provider --> Compatible Store --> JSON Store --> Redis

Agent Execution Flow

sequenceDiagram participant User participant Agent participant EventBus participant Provider as Model Provider participant Tools as Tool Registry User->>Agent: RunAsync("User message") Agent->>EventBus: Publish(Progress, Start) loop Agent Loop Agent->>Provider: StreamAsync(messages) Provider-->>Agent: Text chunks Agent->>EventBus: Publish(Progress, TextChunk) alt Tool Call Required Provider-->>Agent: ToolUse Agent->>EventBus: Publish(Progress, ToolStart) alt Requires Approval Agent->>EventBus: Publish(Control, ApprovalRequest) EventBus-->>Agent: ApprovalResponse end Agent->>Tools: ExecuteAsync(tool, args) Tools-->>Agent: ToolResult Agent->>EventBus: Publish(Progress, ToolEnd) end end Agent->>EventBus: Publish(Progress, Done) Agent-->>User: AgentRunResult

Quick Start

1. Install Packages

From NuGet.org (Recommended):

# Core packages dotnet add package Kode.Agent.Sdk dotnet add package Kode.Agent.Store.Json dotnet add package Kode.Agent.Tools.Builtin # Optional: MCP support dotnet add package Kode.Agent.Mcp # Optional: Redis storage dotnet add package Kode.Agent.Store.Redis

From GitHub Packages:

# Configure GitHub Packages source (one-time setup) dotnet nuget add source \ --username YOUR_GITHUB_USERNAME \ --password YOUR_GITHUB_TOKEN \ --store-password-in-clear-text \ --name github \ "https://nuget.pkg.github.com/JinFanZheng/index.json" # Install packages dotnet add package Kode.Agent.Sdk --source github

📚 For detailed GitHub Packages setup, see GitHub Packages Guide

Or reference projects directly:

<ProjectReference Include="path/to/Kode.Agent.Sdk.csproj" /> <ProjectReference Include="path/to/Kode.Agent.Store.Json.csproj" /> <ProjectReference Include="path/to/Kode.Agent.Tools.Builtin.csproj" />

2. Configure Environment Variables

Create a .env file (Anthropic Claude recommended):

# Anthropic configuration (recommended) ANTHROPIC_API_KEY=your-api-key-here ANTHROPIC_MODEL_ID=claude-sonnet-4-20250514 ANTHROPIC_BASE_URL=https://api.anthropic.com # Optional, supports custom endpoint

Optional configuration for other providers:

# OpenAI configuration (optiona
五维分析
清晰度8/10
创新性7/10
实用性9/10
完整性8/10
可维护性8/10
优缺点分析

优点

  • 支持多种AI模型,包括Anthropic和OpenAI。
  • 全面的工具管理,包含内置和自定义工具。
  • 事件驱动架构,便于关注点分离。

缺点

  • 新用户的设置过程复杂。
  • 本地执行可能消耗较高资源。
  • 高级功能的文档有限。

相关技能

pytorch

S
toolCode Lib / 代码库
92/ 100

“它是深度学习的瑞士军刀,但祝你好运能从47种安装方法里找到那个不会搞崩你系统的那一个。”

agno

S
toolCode Lib / 代码库
90/ 100

“它承诺成为智能体领域的Kubernetes,但得看开发者有没有耐心学习又一个编排层。”

nuxt-skills

S
toolCo-Pilot / 辅助式
90/ 100

“这本质上是一份组织良好的小抄,能把你的 AI 助手变成一只 Nuxt 框架的复读机。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 JinFanZheng.