diff --git a/cmd/verifyexamples/examples.go b/cmd/verifyexamples/examples.go index 6aa19081..c7fb553f 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_step02_todo", + ProjectPath: "examples/02-agents/harness/step02_todo", + RequiredEnvironmentVariables: []string{"FOUNDRY_PROJECT_ENDPOINT"}, + OptionalEnvironmentVariables: []string{"FOUNDRY_MODEL"}, + ExpectedOutputDescription: []string{ + "The output should show the agent planning a three-course dinner using todo items.", + "The agent should add todo items for the courses and complete them as it works.", + "The output should not contain error messages or stack traces.", + }, + }, } var workflowExamples = []ExampleDefinition{ diff --git a/examples/02-agents/harness/step02_todo/main.go b/examples/02-agents/harness/step02_todo/main.go new file mode 100644 index 00000000..ceeec522 --- /dev/null +++ b/examples/02-agents/harness/step02_todo/main.go @@ -0,0 +1,54 @@ +// 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/todo" + "github.com/microsoft/agent-framework-go/examples/internal/demo" + "github.com/microsoft/agent-framework-go/provider/foundryprovider" +) + +var logger = demo.NewLogger( + "Todo Harness", + "This sample shows how the todo harness gives an agent tools to plan and track a "+ + "multi-step task. The current todo list is injected on each turn, and the agent "+ + "adds, completes, and removes items as it works.", + "Model", demo.FoundryModel, +) + +func main() { + token := demo.FoundryTokenCredential() + + // Attach the todo context provider: it exposes todo tools to the agent and + // injects the current todo list summary on each invocation. The todos 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 planful assistant. For multi-step requests, use the todo tools to " + + "break the work into items, then complete them one by one, marking each item complete " + + "when finished.", + Config: agent.Config{ + Name: "Planner", + Middlewares: []agent.Middleware{logger}, // for logging agent interactions + ContextProviders: []agent.ContextProvider{todo.New(nil)}, + }, + }, + ) + + ctx := context.Background() + session, err := a.CreateSession(ctx) + if err != nil { + demo.Panic(err) + } + resp, err := a.RunText(ctx, + "Plan a simple three-course dinner: choose a starter, a main, and a dessert. "+ + "Track each course as a todo item and complete them one by one.", + agent.WithSession(session)).Collect() + demo.Response(resp, err) +}