【日記】Cloud & AI Platforms トラック Day-3 を見たメモ(AI Agent / Agent Framework)
もくじ
情報源
Cloud & AI Platforms トラック Day-3
ちょまどさん補足記事
かずきさん AgentFramework系記事
Agent Frameworkのドキュメントtop
Agent Framworkのリポジトリ。サンプルをやってみる
メモ
👆のセッションのデモで見たAI系テンプレート

自分のPCでは、WI Chat Web App以外の2つのテンプレが出てこなかった
→以下を実行したら「MCP」のほうは出てきた。
dotnet new install Microsoft.McpServer.ProjectTemplates
が、下記をinstallしても、AI Agentのほうはでてこなかった。
dotnet new install Microsoft.Extensions.AI.Templates
どうも、VS2026 insiderでないといけないらしい。
VSInstallerでinsider版のVS2026を入れる
。。。の前に、かずきさんの記事によると、以下のコマンドで、入るらしい。今VS2026Insider入れてる最中なので、あとでやってみる
dotnet new install Microsoft.Agents.AI.ProjectTemplates::1.0.0-preview.1.25560.10
上のコマンドを実行すると、Agentのテンプレも出てきた。
※insiderでなくても、普通のVS2026でも使えた。
やってみること
- AI Agentのテンプレを動かしてみる
- github models
- ollama
- AgentFrameworkのrepoのサンプルを動かしてみる
26/4/3、01_hello_agentを開いたら、こんな感じでエラーになった。

→01_hello_agent.csprojファイルを直接開いていたのだが、dotnet フォルダのすぐ下にある agent-framework-dotnet.slnx のソリューションファイルをVSで開かないといけなかった。
slnxを開いて、その中のhello_agentのPJを開くと、うまくビルドできた。
うーん、でかい。サンプルだけビルドできないものか。(こねくり回して変になると興味がそれるので、あとで見てみる)
下記の部分を実行すると、そういう環境変数がないよ、というエラーになる。
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
ので、コード中にでてくる環境変数を2つ、下記のコマンドで登録した。
※中身は、ちゃんと自分のエンドポイントと、デプロイしているモデル名にした。
$env:AZURE_OPENAI_ENDPOINT = "https://your-resource-name.openai.azure.com/"
$env:AZURE_OPENAI_DEPLOYMENT_NAME = "gpt-4o-mini"
で、VSを再起動する。
再起動しないとGetEnvironmentVariable(key, EnvironmentVariableTarget.Process)は、親プロセスの環境変数を受け継ぐらしく、この場合の親プロセスはVSなので、VSを立ち上げなおさないとVSから起動したexeにも反映されないらしい。(再起動したら環境変数が読めた)
次に、こういうエラーが出た。
認証エラーっぽい。たぶん、以前このへんで試したように、クレデンシャルの部分を、デフォルトじゃないものに変えるとうまくいきそうなのだが、サンプルコードを全部直していくのが面倒なので、DefaultAzureCredentialを使うやり方を今一度調べる。(以前はそれが面倒で逃げてた)

copilotはこういっている。

まずは、VSのAzureサービス認証というのをやってみる。

上記のように入れて、OKを押した。
ら、エラーが変わった。

環境変数の登録内容を間違えていた。(仮のエンドポイントの値になってた)
→環境変数を直して、VS再起動。
またエラーが変わった。

AIにはこういわれた。

まずは、Congnitive OpenAI Userを入れてみた

いわれたものを全部いれてみたが、うまくいかない。(401になる)
Azure CLIで認証している、という話があったので、AzureCLIを入れてみる。
下のドキュメントに従い、
下記を実行。
winget install --exact --id Microsoft.AzureCLI
そうすると、Azure CLIが入った。
※ここで、一回VSを再起動しないといけないっぽい。(AzureCLI入ったときの環境変数の変化についていってないので、Azure CLIのモジュール等が、再起動しないと見えないっぽい)
で、az login とやると、MSアカウントを聞く画面が出たので、Azureのアカウントのメールアドレスを選択。
すると、「このテナントにログインするならaz login --tenant TENANT_IDとコマンドを打ちなさい」というエラーが出たので、テナントIDを調べてそれを入力。
※テナントIDは、ココに書かれてる。
ここを押して出てくる

これ

で、コマンドをうつと、どれでログインするかを選んでと出てくる。

で、1個しかなかったので1を入力してEnter。
→ログインできた。
この状態(Azure CLIからログインしている状態)で、DefaultAzureCredentialOptionsで認証すると通るはず
→とおらなかった。原因は、下記の順番で認証しに行くところで、
Azure CLIの前の1~4のどこかで、別ルートで認証が行われて、それがはじかれてるからと思われる。
DefaultAzureCredential の認証チェーン:
1. 環境変数
2. ワークロードID
3. マネージドID
4. Visual Studio
5. ★ Azure CLI ← az login で設定された認証情報
6. Azure PowerShell
なので、Azure CLIを使って認証をするようにコードをすこし変えてあげた。
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
ExcludeEnvironmentCredential = true,
ExcludeAzureCliCredential = false,//★AzureCLIだけfalse=認証をとばさない
ExcludeVisualStudioCredential = true,
ExcludeVisualStudioCodeCredential = true,
ExcludeInteractiveBrowserCredential = true,
Diagnostics = { IsLoggingEnabled = true, LoggedHeaderNames = { "Authorization" } }
}))
.GetChatClient(deploymentName)
.AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
Azure CLIでログインした状態でこれを実行すると、認証がとおってうまく動作した。
(動作は下の通り。なにかジョークを言うAgentっぽい)
Why did the pirate go to school?
Because he wanted to improve his "arrrticulation"! ?????
DefaultAzureCredentialで動いて、うまくいった気に一瞬なったが、DefaultAzureCredentialを使おうとしていたのは、他にもたくさんあるサンプルで、毎回コードをいじりたくなかったからで、CLI認証をするためにコードを変える必要があるなら、DefaultAzureCredentialじゃないAPIキー方式でやるのとあまり変わらない。。。
※結局、ロールをいろいろ追加したが、最終的には追加した分を全部けしたので、関係なかった様子。(すでに入っていたAI開発者?的な奴が効いているのかも?未検証)
※az loginのコマンドで「テナントID」というのが出てきたが、AIによるとこういうものらしい。
要は、一番大きな括り、みたいなもんか。(そのなかに、課金のためのサブスクリプションなどがあるっぽい)

とりあえず、これで01_hello_agentのサンプルは動いたので、次は02_add_toolsで、👆でやってきたことが再現出来てちゃんと動くかの確認と、本来の目的のAgentのあれこれを実験する。
でも02_add_tools はMCPのツールを追加する的な奴っぽい → MCP関連は大体作り方わかった感じがするので、skipしてもいいかも。
★イマココ★
現状、サンプルを動くようにするまでにやること(さいごには消すべし)
下記でテナントにログインする
az login --tenant 18a4d07c-aeb6-4b65-9c76-e5d607a4c3d8
new DefaultAzureCredential()の部分を👇のように変える
new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
ExcludeEnvironmentCredential = true,
ExcludeAzureCliCredential = false,
ExcludeVisualStudioCredential = true,
ExcludeVisualStudioCodeCredential = true,
ExcludeInteractiveBrowserCredential = true,
Diagnostics = { IsLoggingEnabled = true, LoggedHeaderNames = { "Authorization" } }
}))
たぶんこれで行ける。
サンプルの構成
26/04/03時点のサンプルの構成は、以下のようになっていた。
全部見るには多すぎるので、基本的な部分だけまず見てみる。
フォルダー パスの一覧: ボリューム MYSYSTEM
ボリューム シリアル番号は C410-C755 です
C:.
+---01-get-started
| +---01_hello_agent
| +---02_add_tools
| +---03_multi_turn
| +---04_memory
| +---05_first_workflow
| \---06_host_your_agent
+---02-agents
| +---AgentOpenTelemetry
| +---AgentProviders
| | +---Agent_With_A2A
| | +---Agent_With_Anthropic
| | +---Agent_With_AzureAIAgentsPersistent
| | +---Agent_With_AzureAIProject
| | +---Agent_With_AzureFoundryModel
| | +---Agent_With_AzureOpenAIChatCompletion
| | +---Agent_With_AzureOpenAIResponses
| | +---Agent_With_CustomImplementation
| | +---Agent_With_GitHubCopilot
| | +---Agent_With_GoogleGemini
| | +---Agent_With_Ollama
| | +---Agent_With_ONNX
| | +---Agent_With_OpenAIChatCompletion
| | \---Agent_With_OpenAIResponses
| +---Agents
| | +---Agent_Step01_UsingFunctionToolsWithApprovals
| | +---Agent_Step02_StructuredOutput
| | +---Agent_Step03_PersistedConversations
| | +---Agent_Step04_3rdPartyChatHistoryStorage
| | +---Agent_Step05_Observability
| | +---Agent_Step06_DependencyInjection
| | +---Agent_Step07_AsMcpTool
| | +---Agent_Step08_UsingImages
| | | \---Assets
| | +---Agent_Step09_AsFunctionTool
| | +---Agent_Step10_BackgroundResponsesWithToolsAndPersistence
| | +---Agent_Step11_Middleware
| | +---Agent_Step12_Plugins
| | +---Agent_Step13_ChatReduction
| | +---Agent_Step14_BackgroundResponses
| | +---Agent_Step15_DeepResearch
| | +---Agent_Step16_Declarative
| | +---Agent_Step17_AdditionalAIContext
| | +---Agent_Step18_CompactionPipeline
| | \---Agent_Step19_InFunctionLoopCheckpointing
| +---AgentSkills
| | +---Agent_Step01_FileBasedSkills
| | | \---skills
| | | \---unit-converter
| | | +---references
| | | \---scripts
| | \---Agent_Step02_CodeDefinedSkills
| +---AgentsWithFoundry
| | +---Agent_Step00_FoundryAgentLifecycle
| | +---Agent_Step01_Basics
| | +---Agent_Step02.1_MultiturnConversation
| | +---Agent_Step02.2_MultiturnWithServerConversations
| | +---Agent_Step03_UsingFunctionTools
| | +---Agent_Step04_UsingFunctionToolsWithApprovals
| | +---Agent_Step05_StructuredOutput
| | +---Agent_Step06_PersistedConversations
| | +---Agent_Step07_Observability
| | +---Agent_Step08_DependencyInjection
| | +---Agent_Step09_UsingMcpClientAsTools
| | +---Agent_Step10_UsingImages
| | | \---assets
| | +---Agent_Step11_AsFunctionTool
| | +---Agent_Step12_Middleware
| | +---Agent_Step13_Plugins
| | +---Agent_Step14_CodeInterpreter
| | +---Agent_Step15_ComputerUse
| | | \---Assets
| | +---Agent_Step16_FileSearch
| | +---Agent_Step17_OpenAPITools
| | +---Agent_Step18_BingCustomSearch
| | +---Agent_Step19_SharePoint
| | +---Agent_Step20_MicrosoftFabric
| | +---Agent_Step21_WebSearch
| | +---Agent_Step22_MemorySearch
| | \---Agent_Step23_LocalMCP
| +---AgentWithAnthropic
| | +---Agent_Anthropic_Step01_Running
| | +---Agent_Anthropic_Step02_Reasoning
| | +---Agent_Anthropic_Step03_UsingFunctionTools
| | \---Agent_Anthropic_Step04_UsingSkills
| +---AgentWithMemory
| | +---AgentWithMemory_Step01_ChatHistoryMemory
| | +---AgentWithMemory_Step02_MemoryUsingMem0
| | +---AgentWithMemory_Step04_MemoryUsingFoundry
| | \---AgentWithMemory_Step05_BoundedChatHistory
| +---AgentWithOpenAI
| | +---Agent_OpenAI_Step01_Running
| | +---Agent_OpenAI_Step02_Reasoning
| | +---Agent_OpenAI_Step03_CreateFromChatClient
| | +---Agent_OpenAI_Step04_CreateFromOpenAIResponseClient
| | \---Agent_OpenAI_Step05_Conversation
| +---AgentWithRAG
| | +---AgentWithRAG_Step01_BasicTextRAG
| | | \---TextSearchStore
| | +---AgentWithRAG_Step02_CustomVectorStoreRAG
| | +---AgentWithRAG_Step03_CustomRAGDataSource
| | +---AgentWithRAG_Step04_FoundryServiceRAG
| | \---AgentWithRAG_Step05_Neo4jGraphRAG
| +---AGUI
| | +---Step01_GettingStarted
| | | +---Client
| | | \---Server
| | | \---Properties
| | +---Step02_BackendTools
| | | +---Client
| | | \---Server
| | | \---Properties
| | +---Step03_FrontendTools
| | | +---Client
| | | \---Server
| | | \---Properties
| | +---Step04_HumanInLoop
| | | +---Client
| | | \---Server
| | | \---Properties
| | \---Step05_StateManagement
| | +---Client
| | \---Server
| | \---Properties
| +---DeclarativeAgents
| | \---ChatClient
| | \---Properties
| +---DevUI
| | \---DevUI_Step01_BasicUsage
| | \---Properties
| \---ModelContextProtocol
| +---Agent_MCP_Server
| +---Agent_MCP_Server_Auth
| +---FoundryAgent_Hosted_MCP
| \---ResponseAgent_Hosted_MCP
+---03-workflows
| +---Agents
| | +---CustomAgentExecutors
| | +---FoundryAgent
| | +---GroupChatToolApproval
| | \---WorkflowAsAnAgent
| +---Checkpoint
| | +---CheckpointAndRehydrate
| | +---CheckpointAndResume
| | \---CheckpointWithHumanInTheLoop
| +---Concurrent
| | +---Concurrent
| | \---MapReduce
| +---ConditionalEdges
| | +---01_EdgeCondition
| | +---02_SwitchCase
| | \---03_MultiSelection
| +---Declarative
| | +---ConfirmInput
| | +---CustomerSupport
| | | \---Properties
| | +---DeepResearch
| | | \---Properties
| | +---ExecuteCode
| | +---ExecuteWorkflow
| | | \---Properties
| | +---FunctionTools
| | | \---Properties
| | +---GenerateCode
| | | \---Properties
| | +---HostedWorkflow
| | +---InputArguments
| | | \---Properties
| | +---InvokeFunctionTool
| | +---InvokeMcpTool
| | +---Marketing
| | | \---Properties
| | +---OpenAIChatAgent
| | | \---Properties
| | +---OpenAIResponseAgent
| | | \---Properties
| | +---StudentTeacher
| | | \---Properties
| | \---ToolApproval
| | \---Properties
| +---HumanInTheLoop
| | \---HumanInTheLoopBasic
| +---Loop
| +---Observability
| | +---ApplicationInsights
| | +---AspireDashboard
| | \---WorkflowAsAnAgent
| +---Resources
| +---SharedStates
| +---Visualization
| | \---Resources
| \---_StartHere
| +---01_Streaming
| +---02_AgentsInWorkflows
| +---03_AgentWorkflowPatterns
| +---04_MultiModelService
| +---05_SubWorkflows
| +---06_MixedWorkflowAgentsAndExecutors
| \---07_WriterCriticWorkflow
+---04-hosting
| +---A2A
| | +---A2AAgent_AsFunctionTools
| | \---A2AAgent_PollingForTaskCompletion
| +---DurableAgents
| | +---AzureFunctions
| | | +---01_SingleAgent
| | | +---02_AgentOrchestration_Chaining
| | | +---03_AgentOrchestration_Concurrency
| | | +---04_AgentOrchestration_Conditionals
| | | +---05_AgentOrchestration_HITL
| | | +---06_LongRunningTools
| | | +---07_AgentAsMcpTool
| | | \---08_ReliableStreaming
| | \---ConsoleApps
| | +---01_SingleAgent
| | +---02_AgentOrchestration_Chaining
| | +---03_AgentOrchestration_Concurrency
| | +---04_AgentOrchestration_Conditionals
| | +---05_AgentOrchestration_HITL
| | +---06_LongRunningTools
| | \---07_ReliableStreaming
| \---DurableWorkflows
| +---AzureFunctions
| | +---01_SequentialWorkflow
| | +---02_ConcurrentWorkflow
| | +---03_WorkflowHITL
| | +---04_WorkflowMcpTool
| | \---05_WorkflowAndAgents
| \---ConsoleApps
| +---01_SequentialWorkflow
| +---02_ConcurrentWorkflow
| +---03_ConditionalEdges
| +---04_WorkflowAndAgents
| +---05_WorkflowEvents
| +---06_WorkflowSharedState
| +---07_SubWorkflows
| \---08_WorkflowHITL
\---05-end-to-end
+---A2AClientServer
| +---A2AClient
| \---A2AServer
| \---Models
+---AgentWebChat
| +---AgentWebChat.AgentHost
| | +---Custom
| | +---Properties
| | \---Utilities
| +---AgentWebChat.AppHost
| | \---Properties
| +---AgentWebChat.ServiceDefaults
| \---AgentWebChat.Web
| +---Components
| | +---Layout
| | \---Pages
| +---Properties
| \---wwwroot
+---AgentWithPurview
+---AGUIClientServer
| +---AGUIClient
| +---AGUIDojoServer
| | +---AgenticUI
| | +---BackendToolRendering
| | +---PredictiveStateUpdates
| | +---Properties
| | \---SharedState
| \---AGUIServer
| \---Properties
+---AGUIWebChat
| +---Client
| | +---Components
| | | +---Layout
| | | \---Pages
| | | \---Chat
| | +---Properties
| | \---wwwroot
| \---Server
| \---Properties
+---AspNetAgentAuthorization
| +---keycloak
| +---RazorWebClient
| | +---Pages
| | | \---Shared
| | \---Properties
| \---Service
| \---Properties
+---HostedAgents
| +---AgentsInWorkflows
| +---AgentThreadAndHITL
| +---AgentWithHostedMCP
| +---AgentWithLocalTools
| +---AgentWithTextSearchRag
| +---FoundryMultiAgent
| \---FoundrySingleAgent
\---M365Agent
+---Agents
+---appManifest
+---Auth
\---Properties
Discussion