Skip to content

Add a background-responses agent example - #569

Open
PratikDhanave (PratikDhanave) wants to merge 5 commits into
microsoft:mainfrom
PratikDhanaveFork:example-background-responses
Open

Add a background-responses agent example#569
PratikDhanave (PratikDhanave) wants to merge 5 commits into
microsoft:mainfrom
PratikDhanaveFork:example-background-responses

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Ports the Python getting-started background responses sample (python/samples/02-agents/background_responses.py) to Go. The Go SDK supports the feature (agent.AllowBackgroundResponses + Response.ContinuationToken + agent.WithContinuationToken) but had no example for it.

What it shows

The non-streaming polling pattern:

  1. Start a run with agent.AllowBackgroundResponses(true) — the OpenAI Responses API returns quickly with a continuation token instead of the final answer.
  2. Poll with agent.WithContinuationToken(resp.ContinuationToken) until the run completes (no more token).
  3. Print the final result.

A correctness detail worth calling out: continuation runs must not carry messages (the provider rejects messages are not allowed when continuing a background response using a continuation token), so the poll uses Run(ctx, nil, …) rather than RunText. If the model/endpoint does not support background execution, the run simply completes inline with no token, so the example degrades gracefully.

Placement

Put next to the existing providers/azure/openai_responses example, since background responses are an OpenAI Responses capability — this avoids guessing an agents/stepNN number. Happy to relocate/renumber to match your preferred layout.

Registered in cmd/verifyexamples with the same AZURE_OPENAI_ENDPOINT gate as the sibling example, so it skips cleanly when credentials are absent. go build ./..., go vet, gofmt, and go test ./cmd/verifyexamples/ all pass.

Copilot AI review requested due to automatic review settings July 20, 2026 06:52
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner July 20, 2026 06:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Go example demonstrating OpenAI Responses “background” execution (continuation-token polling) for the Azure OpenAI provider, and wires it into the repo’s example verification harness.

Changes:

  • Introduces openai_responses_background example showing non-streaming background execution + polling via Response.ContinuationToken / agent.WithContinuationToken.
  • Registers the new example in cmd/verifyexamples with the same AZURE_OPENAI_ENDPOINT gate used by the sibling Azure Responses example.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
examples/02-agents/providers/azure/openai_responses_background/main.go New sample: start a background Responses run, then poll until continuation token is cleared.
cmd/verifyexamples/examples.go Adds the new sample to the agentsExamples verification list with expected-output guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/02-agents/providers/azure/openai_responses_background/main.go Outdated
Comment thread examples/02-agents/providers/azure/openai_responses_background/main.go Outdated
@PratikDhanave
PratikDhanave (PratikDhanave) force-pushed the example-background-responses branch 2 times, most recently from 0cd72f1 to 21efdba Compare July 23, 2026 15:44
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Ports the Python getting-started background-responses sample to Go. It
starts a long-running OpenAI Responses run with
agent.AllowBackgroundResponses(true), which returns a continuation token
instead of the final answer, then polls with agent.WithContinuationToken
(sending no messages) until the run completes.

Placed next to the existing openai_responses provider example since
background responses are an OpenAI Responses capability, and registered in
verifyexamples with the same AZURE_OPENAI_ENDPOINT gate so it skips
cleanly without credentials.
Bound the sample with a timeout and replace the blocking sleep with a
select on ctx.Done(), so a run that never completes (stuck queued, bad
continuation token) cannot hang the example or verifyexamples.
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
@github-actions

This comment has been minimized.

@gdams

Copy link
Copy Markdown
Member

The upstream Python sample demonstrates two patterns: non-streaming polling (ported here) and streaming with resumption (start a streaming background run, interrupt, resume from the last continuation_token). The Go SDK already exposes the streaming path through the same WithContinuationToken option, so that second pattern could be added as a follow-up example without any API changes.

PratikDhanave (@PratikDhanave) can you please address this in your PR

@github-actions github-actions Bot added area:examples Changes files in the examples area area:tooling Changes files in the tooling area size:large At most 300 changed lines across at most 10 files pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added failed-auto-risk Automatic risk classification was inconclusive or failed and removed pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions github-actions Bot added pending-auto-risk Automatic risk classification is in progress and removed failed-auto-risk Automatic risk classification was inconclusive or failed labels Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — PR #569: Add a background-responses agent example

Scope: examples only — no exported Go APIs changed. public-api-change label is not applicable.

Upstream reference: python/samples/02-agents/background_responses.py in microsoft/agent-framework.

Summary: The PR correctly ports the non-streaming polling pattern from the upstream Python sample and the Go implementation is semantically aligned with the Python non_streaming_polling() function. The AllowBackgroundResponses / WithContinuationToken API mapping is faithful.


⚠️ Parity gap — streaming-with-resumption pattern not ported

The upstream Python sample contains two top-level scenarios:

  1. non_streaming_polling() — ✅ ported here
  2. streaming_with_resumption() — ❌ not included

The second pattern starts a streaming background run (stream=True + background=True), simulates an interruption, and resumes from the last continuation_token carried in each stream update. The Go SDK already supports this via agent.Stream(true) + agent.AllowBackgroundResponses(true), so the SDK capability exists but the sample coverage diverges from upstream.

This is a sample parity gap, not an API defect. Because the PR description says it ports the Python sample, reviewers should be aware that only one of the two upstream scenarios is covered. I am removing parity-approved and flagging the gap; the label can be re-applied once the streaming-resumption scenario is either included here or deferred with a follow-up issue.


No issues found with: API naming, option shapes, polling semantics, session requirement, graceful degradation when the endpoint does not support background mode, or verifyexamples registration.

Generated by Go API Consistency Review Agent · sonnet46 · 30.2 AIC · ⌖ 5.82 AIC · ⊞ 6K ·

@github-actions github-actions Bot removed the parity-approved Go API consistency review found no parity issues label Aug 22, 2026
@github-actions github-actions Bot added risk:low Limited blast radius and straightforward rollback and removed pending-auto-risk Automatic risk classification is in progress labels Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Changes files in the examples area area:tooling Changes files in the tooling area risk:low Limited blast radius and straightforward rollback size:large At most 300 changed lines across at most 10 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants