From c4ef1196463afdc912aa8c6821049dffe3bf0098 Mon Sep 17 00:00:00 2001 From: PratikDhanave Date: Thu, 23 Jul 2026 13:48:04 +0530 Subject: [PATCH 1/2] Add OpenAI Responses file-search hosted-tool example Add examples/02-agents/providers/openai/filesearch demonstrating the hosted file-search (vector store) tool with an OpenAI Responses agent. The example wires hostedtool.FileSearch with a HostedVectorStoreContent input and MaximumResultCount, runs a retrieval-style query via RunText, and gates the run on VECTOR_STORE_ID so CI does not require a live store. --- .../providers/openai/filesearch/main.go | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 examples/02-agents/providers/openai/filesearch/main.go diff --git a/examples/02-agents/providers/openai/filesearch/main.go b/examples/02-agents/providers/openai/filesearch/main.go new file mode 100644 index 00000000..42c97840 --- /dev/null +++ b/examples/02-agents/providers/openai/filesearch/main.go @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft. All rights reserved. + +package main + +import ( + "context" + "os" + + "github.com/microsoft/agent-framework-go/agent" + "github.com/microsoft/agent-framework-go/examples/internal/demo" + "github.com/microsoft/agent-framework-go/message" + "github.com/microsoft/agent-framework-go/provider/openaiprovider" + "github.com/microsoft/agent-framework-go/tool" + "github.com/microsoft/agent-framework-go/tool/hostedtool" + "github.com/openai/openai-go/v3" +) + +// vectorStoreID identifies the OpenAI vector store the file-search tool queries. +// Create one via the OpenAI dashboard or API, upload your documents to it, then +// export its identifier before running this example: +// +// export VECTOR_STORE_ID=vs_... +var vectorStoreID = os.Getenv("VECTOR_STORE_ID") + +var logger = demo.NewLogger( + "OpenAI File Search", + "Demonstrates the hosted file-search (vector store) tool with an OpenAI Responses agent.", + "Model", "gpt-4o-mini", +) + +func main() { + if vectorStoreID == "" { + demo.Assistant("Set VECTOR_STORE_ID to a vector store you own to run this example.") + demo.Assistant(" export VECTOR_STORE_ID=vs_...") + return + } + + // Create an OpenAI Responses agent with the hosted file-search tool. The tool + // retrieves grounding context from the referenced vector store and caps the + // number of returned chunks with MaximumResultCount. + a := openaiprovider.NewAgent( + openai.NewClient(), + openaiprovider.AgentConfig{ + Model: "gpt-4o-mini", + Instructions: "You are a helpful assistant. Answer using the documents in the vector store.", + Config: agent.Config{ + Name: "FileSearchAgent", + Middlewares: []agent.Middleware{logger}, // for logging agent interactions + Tools: []tool.Tool{ + &hostedtool.FileSearch{ + MaximumResultCount: 5, + Inputs: []message.Content{ + &message.HostedVectorStoreContent{VectorStoreID: vectorStoreID}, + }, + }, + }, + }, + }, + ) + + // Invoke the agent with a retrieval-style query and output the text result. + resp, err := a.RunText(context.Background(), "What do the documents say? Summarize the key points.").Collect() + demo.Response(resp, err) +} From b2f3a065954fb1d192f82cd2d910fe44af0a0121 Mon Sep 17 00:00:00 2001 From: PratikDhanave Date: Fri, 24 Jul 2026 10:31:30 +0530 Subject: [PATCH 2/2] Trim whitespace when reading VECTOR_STORE_ID in filesearch example --- examples/02-agents/providers/openai/filesearch/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/02-agents/providers/openai/filesearch/main.go b/examples/02-agents/providers/openai/filesearch/main.go index 42c97840..b52c1ab4 100644 --- a/examples/02-agents/providers/openai/filesearch/main.go +++ b/examples/02-agents/providers/openai/filesearch/main.go @@ -5,6 +5,7 @@ package main import ( "context" "os" + "strings" "github.com/microsoft/agent-framework-go/agent" "github.com/microsoft/agent-framework-go/examples/internal/demo" @@ -20,7 +21,7 @@ import ( // export its identifier before running this example: // // export VECTOR_STORE_ID=vs_... -var vectorStoreID = os.Getenv("VECTOR_STORE_ID") +var vectorStoreID = strings.TrimSpace(os.Getenv("VECTOR_STORE_ID")) var logger = demo.NewLogger( "OpenAI File Search",