From 2b047038f8d8104ddc0ae1ce82139f815ea847be Mon Sep 17 00:00:00 2001 From: PratikDhanave Date: Wed, 23 Sep 2026 10:19:39 +0530 Subject: [PATCH 1/2] Add an agent-mode harness example Go supports the agent-mode harness (agent/harness/agentmode) but has no sample. Add an example that attaches the agent-mode context provider (default plan/execute modes with mode_set/mode_get tools) to a Foundry agent so the agent plans then executes, and register it with cmd/verifyexamples. --- cmd/verifyexamples/examples.go | 11 ++++ .../harness/step03_agentmode/main.go | 52 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 examples/02-agents/harness/step03_agentmode/main.go diff --git a/cmd/verifyexamples/examples.go b/cmd/verifyexamples/examples.go index 6aa19081..806b27d1 100644 --- a/cmd/verifyexamples/examples.go +++ b/cmd/verifyexamples/examples.go @@ -812,6 +812,17 @@ var agentsExamples = []ExampleDefinition{ "The output should not contain error messages or stack traces.", }, }, + { + Name: "02_agents_harness_step03_agentmode", + ProjectPath: "examples/02-agents/harness/step03_agentmode", + RequiredEnvironmentVariables: []string{"FOUNDRY_PROJECT_ENDPOINT"}, + OptionalEnvironmentVariables: []string{"FOUNDRY_MODEL"}, + ExpectedOutputDescription: []string{ + "The output should show the agent planning steps for a study group and then executing them.", + "The agent may switch from plan mode to execute mode using the mode tools.", + "The output should not contain error messages or stack traces.", + }, + }, } var workflowExamples = []ExampleDefinition{ diff --git a/examples/02-agents/harness/step03_agentmode/main.go b/examples/02-agents/harness/step03_agentmode/main.go new file mode 100644 index 00000000..438e9460 --- /dev/null +++ b/examples/02-agents/harness/step03_agentmode/main.go @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft. All rights reserved. + +package main + +import ( + "context" + + "github.com/microsoft/agent-framework-go/agent" + "github.com/microsoft/agent-framework-go/agent/harness/agentmode" + "github.com/microsoft/agent-framework-go/examples/internal/demo" + "github.com/microsoft/agent-framework-go/provider/foundryprovider" +) + +var logger = demo.NewLogger( + "Agent Mode Harness", + "This sample shows how the agent-mode harness gives an agent a set of operating "+ + "modes (plan / execute by default) plus mode_set/mode_get tools, and injects "+ + "mode-specific instructions so the agent adjusts its behavior per mode.", + "Model", demo.FoundryModel, +) + +func main() { + token := demo.FoundryTokenCredential() + + // Attach the agent-mode context provider. With the default configuration the + // agent starts in "plan" mode and can switch to "execute" via the mode_set + // tool; the provider injects the current mode's instructions each turn. Modes + // are session-backed, so the example runs inside a session. + a := foundryprovider.NewAgent( + demo.FoundryProjectEndpoint, + token, + foundryprovider.ModelDeployment(demo.FoundryModel), + foundryprovider.AgentConfig{ + Instructions: "You are a capable assistant that follows the current operating mode's guidance.", + Config: agent.Config{ + Name: "ModalAssistant", + Middlewares: []agent.Middleware{logger}, // for logging agent interactions + ContextProviders: []agent.ContextProvider{agentmode.New(agentmode.Config{})}, + }, + }, + ) + + ctx := context.Background() + session, err := a.CreateSession(ctx) + if err != nil { + demo.Panic(err) + } + resp, err := a.RunText(ctx, + "I want to organize a small study group. First plan the steps, then switch to execute mode and carry them out.", + agent.WithSession(session)).Collect() + demo.Response(resp, err) +} From e8152de09ba1a074e1fb00ef25bf3b56163b974b Mon Sep 17 00:00:00 2001 From: PratikDhanave Date: Sat, 3 Oct 2026 12:13:14 +0530 Subject: [PATCH 2/2] Use renamed agentmode SetMode API in the example --- examples/02-agents/harness/step03_agentmode/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/02-agents/harness/step03_agentmode/main.go b/examples/02-agents/harness/step03_agentmode/main.go index 0ad32e63..5995ae1b 100644 --- a/examples/02-agents/harness/step03_agentmode/main.go +++ b/examples/02-agents/harness/step03_agentmode/main.go @@ -58,7 +58,7 @@ func main() { // Switch the session to "execute" mode. The next run rebuilds the injected // instructions from this mode, so the agent now carries out the plan. - if err := modeProvider.SetModeForSession(session, "execute"); err != nil { + if err := modeProvider.SetMode(session, "execute", false); err != nil { demo.Panic(err) }