Stop `BackgroundTools` advertising background calls in sequential runs, and warn that its tools run in the foreground

Merged
DO
4d ago
+164-16

Why we make these changes

When a run executes tools sequentially, BackgroundTools already ran background tools in the foreground, but it did so silently:

  • Which runs do this: AWS Lambda, Absurd and pgtask run tools sequentially by default, and DBOS does when a workspace is attached.
  • The user got no signal that the tools they set up to run in the background now block the run.
  • The model was told something false. The instructions still said that some calls reply "running in the background", but every call returns inline.

#13206 asked for each engine to support or refuse BackgroundTools instead of misbehaving silently. The per-engine contract was agreed on #14429 (survey):

  • Sequential runs (the default on Lambda, Absurd and pgtask): warn once and keep running tools in the foreground.
  • Absurd and pgtask in parallel_ordered_events mode: refuse, because a durable suspend there cancels live tasks. That is a separate PR.

The check reads the run's parallel execution mode, not engine names, so any engine or user setting that makes a run sequential gets the same behavior.

New public surface

None.

User-visible behavior

In a run whose parallel execution mode is 'sequential':

  • Instructions: BackgroundTools adds no instructions, as it already did for realtime sessions.

  • Warning: the first time per run that it prepares a tool it would otherwise run in the background, it emits one UserWarning:

    BackgroundTools runs 'research' in the foreground because this run executes tools sequentially (parallel execution mode sequential, which a durable engine such as AWS Lambda, Absurd or pgtask sets), and does not tell the model about background calls.

    It doesn't warn for realtime runs, for tools marked sequential=True, or when no tool would have run in the background.

Parallel runs don't change.

Verification

  • tests/harness/background_tools/test_background_tools.py::TestBackgroundTools::test_run_scoped_sequential_mode_uses_normal_execution: two sequential steps produce one warning naming only the background tool, no instructions on any request, and every result returned inline.
  • test_run_scoped_sequential_mode_does_not_advertise_run_in_background: two runs of one agent warn once each.
  • test_instructions_explain_pending_calls: a parallel run with a background tool doesn't warn and keeps its instructions.
  • tests/harness/background_tools/test_aws_lambda.py::test_sequential_durable_run_keeps_tools_in_the_foreground: the same under AWSLambdaDurability, including the recorded step names.

What changes for existing users

In sequential runs only, the model no longer receives the background-call instructions, and a one-time warning names the affected tools. A user who chose sequential mode deliberately can filter the warning by message or by module (pydantic_ai_harness.background_tools._capability).

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code