[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-26d8ce88-5ef1-4379-836c-c7e19f443b54":3,"$fOMThYMe2JYcGyfF6N2JF8lgE3Pde9tTdwsdWaPOgoNk":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"26d8ce88-5ef1-4379-836c-c7e19f443b54","azure-ai-agents-persistent-dotnet","Azure AI代理持久化SDK for .NET。用于创建和管理AI代理的低级SDK，具有线程、消息、运行和工具。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-ai-agents-persistent-dotnet\ndescription: Azure AI Agents Persistent SDK for .NET. Low-level SDK for creating and managing AI agents with threads, messages, runs, and tools.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure.AI.Agents.Persistent (.NET)\n\nLow-level SDK for creating and managing persistent AI agents with threads, messages, runs, and tools.\n\n## Installation\n\n```bash\ndotnet add package Azure.AI.Agents.Persistent --prerelease\ndotnet add package Azure.Identity\n```\n\n**Current Versions**: Stable v1.1.0, Preview v1.2.0-beta.8\n\n## Environment Variables\n\n```bash\nPROJECT_ENDPOINT=https:\u002F\u002F\u003Cresource>.services.ai.azure.com\u002Fapi\u002Fprojects\u002F\u003Cproject>\nMODEL_DEPLOYMENT_NAME=gpt-4o-mini\nAZURE_BING_CONNECTION_ID=\u003Cbing-connection-resource-id>\nAZURE_AI_SEARCH_CONNECTION_ID=\u003Csearch-connection-resource-id>\n```\n\n## Authentication\n\n```csharp\nusing Azure.AI.Agents.Persistent;\nusing Azure.Identity;\n\nvar projectEndpoint = Environment.GetEnvironmentVariable(\"PROJECT_ENDPOINT\");\nPersistentAgentsClient client = new(projectEndpoint, new DefaultAzureCredential());\n```\n\n## Client Hierarchy\n\n```\nPersistentAgentsClient\n├── Administration  → Agent CRUD operations\n├── Threads         → Thread management\n├── Messages        → Message operations\n├── Runs            → Run execution and streaming\n├── Files           → File upload\u002Fdownload\n└── VectorStores    → Vector store management\n```\n\n## Core Workflow\n\n### 1. Create Agent\n\n```csharp\nvar modelDeploymentName = Environment.GetEnvironmentVariable(\"MODEL_DEPLOYMENT_NAME\");\n\nPersistentAgent agent = await client.Administration.CreateAgentAsync(\n    model: modelDeploymentName,\n    name: \"Math Tutor\",\n    instructions: \"You are a personal math tutor. Write and run code to answer math questions.\",\n    tools: [new CodeInterpreterToolDefinition()]\n);\n```\n\n### 2. Create Thread and Message\n\n```csharp\n\u002F\u002F Create thread\nPersistentAgentThread thread = await client.Threads.CreateThreadAsync();\n\n\u002F\u002F Create message\nawait client.Messages.CreateMessageAsync(\n    thread.Id,\n    MessageRole.User,\n    \"I need to solve the equation `3x + 11 = 14`. Can you help me?\"\n);\n```\n\n### 3. Run Agent (Polling)\n\n```csharp\n\u002F\u002F Create run\nThreadRun run = await client.Runs.CreateRunAsync(\n    thread.Id,\n    agent.Id,\n    additionalInstructions: \"Please address the user as Jane Doe.\"\n);\n\n\u002F\u002F Poll for completion\ndo\n{\n    await Task.Delay(TimeSpan.FromMilliseconds(500));\n    run = await client.Runs.GetRunAsync(thread.Id, run.Id);\n}\nwhile (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress);\n\n\u002F\u002F Retrieve messages\nawait foreach (PersistentThreadMessage message in client.Messages.GetMessagesAsync(\n    threadId: thread.Id, \n    order: ListSortOrder.Ascending))\n{\n    Console.Write($\"{message.Role}: \");\n    foreach (MessageContent content in message.ContentItems)\n    {\n        if (content is MessageTextContent textContent)\n            Console.WriteLine(textContent.Text);\n    }\n}\n```\n\n### 4. Streaming Response\n\n```csharp\nAsyncCollectionResult\u003CStreamingUpdate> stream = client.Runs.CreateRunStreamingAsync(\n    thread.Id, \n    agent.Id\n);\n\nawait foreach (StreamingUpdate update in stream)\n{\n    if (update.UpdateKind == StreamingUpdateReason.RunCreated)\n    {\n        Console.WriteLine(\"--- Run started! ---\");\n    }\n    else if (update is MessageContentUpdate contentUpdate)\n    {\n        Console.Write(contentUpdate.Text);\n    }\n    else if (update.UpdateKind == StreamingUpdateReason.RunCompleted)\n    {\n        Console.WriteLine(\"\\n--- Run completed! ---\");\n    }\n}\n```\n\n### 5. Function Calling\n\n```csharp\n\u002F\u002F Define function tool\nFunctionToolDefinition weatherTool = new(\n    name: \"getCurrentWeather\",\n    description: \"Gets the current weather at a location.\",\n    parameters: BinaryData.FromObjectAsJson(new\n    {\n        Type = \"object\",\n        Properties = new\n        {\n            Location = new { Type = \"string\", Description = \"City and state, e.g. San Francisco, CA\" },\n            Unit = new { Type = \"string\", Enum = new[] { \"c\", \"f\" } }\n        },\n        Required = new[] { \"location\" }\n    }, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })\n);\n\n\u002F\u002F Create agent with function\nPersistentAgent agent = await client.Administration.CreateAgentAsync(\n    model: modelDeploymentName,\n    name: \"Weather Bot\",\n    instructions: \"You are a weather bot.\",\n    tools: [weatherTool]\n);\n\n\u002F\u002F Handle function calls during polling\ndo\n{\n    await Task.Delay(500);\n    run = await client.Runs.GetRunAsync(thread.Id, run.Id);\n\n    if (run.Status == RunStatus.RequiresAction \n        && run.RequiredAction is SubmitToolOutputsAction submitAction)\n    {\n        List\u003CToolOutput> outputs = [];\n        foreach (RequiredToolCall toolCall in submitAction.ToolCalls)\n        {\n            if (toolCall is RequiredFunctionToolCall funcCall)\n            {\n                \u002F\u002F Execute function and get result\n                string result = ExecuteFunction(funcCall.Name, funcCall.Arguments);\n                outputs.Add(new ToolOutput(toolCall, result));\n            }\n        }\n        run = await client.Runs.SubmitToolOutputsToRunAsync(run, outputs, toolApprovals: null);\n    }\n}\nwhile (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress);\n```\n\n### 6. File Search with Vector Store\n\n```csharp\n\u002F\u002F Upload file\nPersistentAgentFileInfo file = await client.Files.UploadFileAsync(\n    filePath: \"document.txt\",\n    purpose: PersistentAgentFilePurpose.Agents\n);\n\n\u002F\u002F Create vector store\nPersistentAgentsVectorStore vectorStore = await client.VectorStores.CreateVectorStoreAsync(\n    fileIds: [file.Id],\n    name: \"my_vector_store\"\n);\n\n\u002F\u002F Create file search resource\nFileSearchToolResource fileSearchResource = new();\nfileSearchResource.VectorStoreIds.Add(vectorStore.Id);\n\n\u002F\u002F Create agent with file search\nPersistentAgent agent = await client.Administration.CreateAgentAsync(\n    model: modelDeploymentName,\n    name: \"Document Assistant\",\n    instructions: \"You help users find information in documents.\",\n    tools: [new FileSearchToolDefinition()],\n    toolResources: new ToolResources { FileSearch = fileSearchResource }\n);\n```\n\n### 7. Bing Grounding\n\n```csharp\nvar bingConnectionId = Environment.GetEnvironmentVariable(\"AZURE_BING_CONNECTION_ID\");\n\nBingGroundingToolDefinition bingTool = new(\n    new BingGroundingSearchToolParameters(\n        [new BingGroundingSearchConfiguration(bingConnectionId)]\n    )\n);\n\nPersistentAgent agent = await client.Administration.CreateAgentAsync(\n    model: modelDeploymentName,\n    name: \"Search Agent\",\n    instructions: \"Use Bing to answer questions about current events.\",\n    tools: [bingTool]\n);\n```\n\n### 8. Azure AI Search\n\n```csharp\nAzureAISearchToolResource searchResource = new(\n    connectionId: searchConnectionId,\n    indexName: \"my_index\",\n    topK: 5,\n    filter: \"category eq 'documentation'\",\n    queryType: AzureAISearchQueryType.Simple\n);\n\nPersistentAgent agent = await client.Administration.CreateAgentAsync(\n    model: modelDeploymentName,\n    name: \"Search Agent\",\n    instructions: \"Search the documentation index to answer questions.\",\n    tools: [new AzureAISearchToolDefinition()],\n    toolResources: new ToolResources { AzureAISearch = searchResource }\n);\n```\n\n### 9. Cleanup\n\n```csharp\nawait client.Threads.DeleteThreadAsync(thread.Id);\nawait client.Administration.DeleteAgentAsync(agent.Id);\nawait client.VectorStores.DeleteVectorStoreAsync(vectorStore.Id);\nawait client.Files.DeleteFileAsync(file.Id);\n```\n\n## Available Tools\n\n| Tool | Class | Purpose |\n|------|-------|---------|\n| Code Interpreter | `CodeInterpreterToolDefinition` | Execute Python code, generate visualizations |\n| File Search | `FileSearchToolDefinition` | Search uploaded files via vector stores |\n| Function Calling | `FunctionToolDefinition` | Call custom functions |\n| Bing Grounding | `BingGroundingToolDefinition` | Web search via Bing |\n| Azure AI Search | `AzureAISearchToolDefinition` | Search Azure AI Search indexes |\n| OpenAPI | `OpenApiToolDefinition` | Call external APIs via OpenAPI spec |\n| Azure Functions | `AzureFunctionToolDefinition` | Invoke Azure Functions |\n| MCP | `MCPToolDefinition` | Model Context Protocol tools |\n| SharePoint | `SharepointToolDefinition` | Access SharePoint content |\n| Microsoft Fabric | `MicrosoftFabricToolDefinition` | Access Fabric data |\n\n## Streaming Update Types\n\n| Update Type | Description |\n|-------------|-------------|\n| `StreamingUpdateReason.RunCreated` | Run started |\n| `StreamingUpdateReason.RunInProgress` | Run processing |\n| `StreamingUpdateReason.RunCompleted` | Run finished |\n| `StreamingUpdateReason.RunFailed` | Run errored |\n| `MessageContentUpdate` | Text content chunk |\n| `RunStepUpdate` | Step status change |\n\n## Key Types Reference\n\n| Type | Purpose |\n|------|---------|\n| `PersistentAgentsClient` | Main entry point |\n| `PersistentAgent` | Agent with model, instructions, tools |\n| `PersistentAgentThread` | Conversation thread |\n| `PersistentThreadMessage` | Message in thread |\n| `ThreadRun` | Execution of agent against thread |\n| `RunStatus` | Queued, InProgress, RequiresAction, Completed, Failed |\n| `ToolResources` | Combined tool resources |\n| `ToolOutput` | Function call response |\n\n## Best Practices\n\n1. **Always dispose clients** — Use `using` statements or explicit disposal\n2. **Poll with appropriate delays** — 500ms recommended between status checks\n3. **Clean up resources** — Delete threads and agents when done\n4. **Handle all run statuses** — Check for `RequiresAction`, `Failed`, `Cancelled`\n5. **Use streaming for real-time UX** — Better user experience than polling\n6. **Store IDs not objects** — Reference agents\u002Fthreads by ID\n7. **Use async methods** — All operations should be async\n\n## Error Handling\n\n```csharp\nusing Azure;\n\ntry\n{\n    var agent = await client.Administration.CreateAgentAsync(...);\n}\ncatch (RequestFailedException ex) when (ex.Status == 404)\n{\n    Console.WriteLine(\"Resource not found\");\n}\ncatch (RequestFailedException ex)\n{\n    Console.WriteLine($\"Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}\");\n}\n```\n\n## Related SDKs\n\n| SDK | Purpose | Install |\n|-----|---------|---------|\n| `Azure.AI.Agents.Persistent` | Low-level agents (this SDK) | `dotnet add package Azure.AI.Agents.Persistent` |\n| `Azure.AI.Projects` | High-level project client | `dotnet add package Azure.AI.Projects` |\n\n## Reference Links\n\n| Resource | URL |\n|----------|-----|\n| NuGet Package | https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FAzure.AI.Agents.Persistent |\n| API Reference | https:\u002F\u002Flearn.microsoft.com\u002Fdotnet\u002Fapi\u002Fazure.ai.agents.persistent |\n| GitHub Source | https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-net\u002Ftree\u002Fmain\u002Fsdk\u002Fai\u002FAzure.AI.Agents.Persistent |\n| Samples | https:\u002F\u002Fgithub.com\u002FAzure\u002Fazure-sdk-for-net\u002Ftree\u002Fmain\u002Fsdk\u002Fai\u002FAzure.AI.Agents.Persistent\u002Fsamples |\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,63,1065,"2026-05-16 13:05:01",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"b37af5e0-2555-4eac-a6ee-b5fc701849a3","1.0.0","azure-ai-agents-persistent-dotnet.zip",3978,"uploads\u002Fskills\u002F26d8ce88-5ef1-4379-836c-c7e19f443b54\u002Fazure-ai-agents-persistent-dotnet.zip","d0022152f0b763ce6ba895c1cfa1427a99497b38ed6b9e13685e7413f03d8a8d","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":11290}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]