Files
wehub-resource-sync db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:25 +08:00
..

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 URL
    • FOUNDRY_MODEL — Model deployment name (defaults to gpt-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.