Agent Framework 系列|基础篇(30讲)
本系列文章将系统介绍 Agent Framework 的基本使用方法与核心概念适合初学者快速入门也适用于已有经验的开发者进行体系化学习。文中涉及的示例代码均已整理至代码仓库欢迎大家前往查看并仓库地址https://github.com/bingbing-gui/dotnet-agent-playbook⭐️ Star 支持随着 Agent Framework 于2026 年 4 月 3 日正式发布 1.0GA版本本系列内容也将逐步进行升级与完善。需要特别说明的是 历史版本说明早期文章中的示例代码基于Prerelease版本编写部分 API 与当前正式版本存在差异。后续将逐步完成向正式版本的迁移与更新。不同版本的变更记录可参考官方发布说明https://github.com/microsoft/agent-framework/releases随着后续案例的持续完善部分基于 Prerelease 版本实现的示例将逐步被新的实践案例所替换与覆盖以保持整体内容与正式版本的一致性。 代码仓库重构笔者对仓库进行了重构与优化之前仓库下的大概几百篇涉及AspNetCore的文章的案例已迁移到_archive目录下仓库重命名dotnet-agent-playbook将打造一个dotnet AI Agent实战指南涵盖从基础到进阶的多个主题模块。老的项目结构已调整新的目录结构更清晰便于大家查找与学习。请以本篇文章中列举的 GitHub 地址为准。仓库地址https://github.com/bingbing-gui/dotnet-agent-playbook⭐️ Star 支持 后续规划重点在后续内容中将重点探索 Agent Framework 中的Workflows工作流编排能力。该能力在设计理念上与 LangChain 生态中的 LangGraph 存在一定相似性主要用于构建多 Agent 协作、任务流转以及复杂业务流程的编排与控制。Workflows 本质上是一种面向 Agent 的流程编排机制用于描述任务在多个 Agent、工具与状态之间的流转关系。后续将推出Agent Framework 进阶篇深入讲解多 Agent 编排、状态管理以及企业级应用实践敬请期待。⚠️重要提示由于仓库结构已进行重构部分历史文章中的 Demo 示例路径已发生变化请以本篇文章提供的仓库地址为准。包括《Semantic Kernel 二十二篇从零到实战 AI 智能体》系列中的部分示例代码也已同步迁移至新仓库中。仓库地址https://github.com/bingbing-gui/dotnet-agent-playbook 相关示例导航Semantic Kernel 二十二篇从零到实战 AI 智能体Semantic Kernel 中 Function Calling GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Semantic-Kernel/SK.FunctionCallingSemantic Kernel 插件Plugins开发指南 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Semantic-Kernel/SK.MCP.PluginsSemantic Kernel 中 Run Prompts GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Semantic-Kernel/SK.RunPrompts[Semantic Kernel 中文本向量Embedding生成] GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Semantic-Kernel/SK.TextEmbeddingGeneration[Semantic Kernel 向量搜索Vector Store实践] GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Semantic-Kernel/SK.VectorStores⭐ 欢迎大家前往查看并 Star 支持️ 系列目录第1篇第30篇第1篇使用Agent Framework构建你的第一个Agent应用 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/01-Agent-Running第2篇Agent Thread实现同一Agent的多轮回话 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/02-Multiturn-Conversation第3篇Agent Framework调用工具 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/03-FunctionTools第4篇Agent Framework的人工审批机制确保本地函数调用安全可控 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/04-FunctionTools-WithApprovals第5篇Agent Framework结构化数据 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/05-StructuredOutput第6篇Agent-Framework实现Agent会话持久化 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/06-PersistedConversations第7篇Agent Framework链接外部存储资源 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/07-StorageConversations第8篇10行代码搞定Agent的全链路监控 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/08-AgentObservability第9篇使用依赖注入构建Agent 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/09-DI第10篇将Agent暴露为mcp工具供第三方安全调用 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/10-AgentAsMcpTools第11篇Agent Framework构建视觉Agent 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/11-Vision-Agent第12篇Agent Framework构建可组合的多agent系统 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/12-Agent-As-Function-Tool第13篇不阻塞、不等待让Agent像后台服务一样持续运行 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/13-Backgroud-Response-With-Tool-And-Persistence第14篇Agent Framework中的 Middleware 设计从 HTTP Pipeline 到 AI Agent Pipeline 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/14-Agent-Middleware第15篇Agent Framework中 IChatReducer 进行聊天记录缩减 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/15-ChatReduction第16篇如何用 Plugins 和依赖注入为 AI Agent 装上外挂 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/16-Plugins第17篇Agent Framework中构建声明式DeclarativeAI Agent 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/17-Declarative-Agent第18篇Microsoft Agent Framework 集成 MCP基于 STDIO 的工具接入 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/18-Agent-MCP-Server-Stdio第19篇Agent-To-Agent协议 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/19-A2AProtocal第20篇使用 Microsoft Foundry 实现持久化 Agents 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/20-Persistent-Agent第21篇使用Microsoft Agent Framework与Microsoft Foundry构建持久化 AI AgentAIProjectClient 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/21-Persistent-Agent-AIProject第22篇OpenAI API 调用模式对比ChatCompletions vs Response API 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/22-OpenAI-API-Patterns第23篇Agent Framework 集成 GitHub Copilot SDK实现 AI 自动操控你的电脑 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/23-GitHubCopilotSDK第24篇Agent Framework 接入 Ollama本地模型实践记录 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/24-Agent-On-Ollama第25篇从 MCP 到 Skill基于 FileBased Skill 与 Agent Framework 的实践探索 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/25-FileBased-Agent-Skills第26篇基于 CodeDefined Skill 与 Agent Framework 的实践探索 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/26-CodeDefined-Agent-Skills第27篇基于 ClassBased Skill 与 Agent Framework 的实践探索 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/27-ClassBased-Agent-Skills第28篇基于 FileBased、CodeBased 和 ClassBased 组合 Skills 与 Agent Framework 的实践探索 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/28-Mixed-Agent-Skills第29篇在 Agent Framework 中为 Agent Skill 接入依赖注入 DI 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/29-AgentSkill-Integration-DI第30篇Agent Framework接入原生DeepSeek-v4-pro 文章地址 GitHub源代码地址https://github.com/bingbing-gui/dotnet-agent-playbook/tree/master/src/ai-agent/Agent-Framework/30-Agent-Providers-DeepSeek