Harness Step 02 — BackgroundAgents (Stock Price Research)
This sample demonstrates how to use the BackgroundAgentsProvider to delegate work from a parent agent to background agents. Both agents use HarnessAgent for pre-configured function invocation, per-service-call persistence, and context-window compaction.
What It Does
A parent agent receives a list of stock tickers and uses a web-search background agent to find the closing price for each ticker on December 31, 2025. The background tasks run concurrently, and results are presented in a summary table.
Architecture
┌──────────────────────────────────────────────────┐
│ StockPriceResearcher │
│ (Parent Agent) │
│ │
│ BackgroundAgentsProvider │
│ ├─ background_agents_start_task │
│ ├─ background_agents_wait_for_first_completion│
│ ├─ background_agents_get_task_results │
│ └─ ... │
└─────────────┬────────────────────────────────────┘
│ delegates to
▼
┌─────────────────────────────────┐
│ WebSearchAgent │
│ (Sub-Agent) │
│ │
│ Tools: │
│ └─ web_search (Foundry) │
└─────────────────────────────────┘
Prerequisites
- An Azure AI Foundry endpoint with an OpenAI model deployment
- Set the following environment variables:
AZURE_FOUNDRY_OPENAI_ENDPOINT— Your Foundry OpenAI endpoint URLFOUNDRY_MODEL— Model deployment name (defaults togpt-5.4)
Running the Sample
cd dotnet/samples/02-agents/Harness/Harness_Step02_Research_WithBackgroundAgents
dotnet run
When prompted, enter a list of stock tickers such as:
BAC, MSFT, BA
The parent agent will delegate each ticker lookup to the web search background agent concurrently and present the results in a table.
Security Considerations
BackgroundAgentsProvider delegates work to the agents you supply — the parent sends them text input
and receives back whatever they produce. A compromised or malicious background agent could exfiltrate
data it receives, or return adversarial output designed to influence the parent agent via indirect
prompt injection once its result is retrieved. Only supply background agents you have vetted and trust
with the data the parent may pass to them.