Skip to content

Python: Add hosted agent sample for the agent harness - #7010

Open
vaibhav-patel wants to merge 3 commits into
microsoft:mainfrom
vaibhav-patel:fix/6477-hosted-harness-sample
Open

Python: Add hosted agent sample for the agent harness#7010
vaibhav-patel wants to merge 3 commits into
microsoft:mainfrom
vaibhav-patel:fix/6477-hosted-harness-sample

Conversation

@vaibhav-patel

Copy link
Copy Markdown
Contributor

What this adds

A new Python sample, python/samples/04-hosting/af-hosting/local_responses_harness/, that hosts a harness agent (built with create_harness_agent) behind the same helper-first Responses hosting seam used by the existing local_responses/ sample.

Files:

  • app.py — a module-level FastAPI ASGI app whose target is a create_harness_agent(...) agent. Uses AgentState + the agent-framework-hosting-responses helpers (responses_to_run, responses_session_id, create_response_id, responses_from_run, responses_from_streaming_run) exactly like local_responses/app.py, with a native /responses route and Hypercorn startup.
  • call_server.py — a plain openai SDK client that drives a three-turn conversation (rotating previous_response_id) to exercise session continuity.
  • pyproject.toml — mirrors local_responses/pyproject.toml ([tool.uv.sources] wires the pre-PyPI agent-framework-hosting* packages to the repo).
  • README.md — mirrors the sibling READMEs (what it shows, prerequisites, how to run, production-readiness notes).
  • storage/.gitignore — same session-storage placeholder as the siblings.
  • Registers the sample in af-hosting/README.md.

The takeaway the sample makes concrete: a harness agent is just an Agent, so it drops straight into the existing AgentState / Responses-helper seam. The harness supplies the function-invocation loop, per-service-call persistence, compaction, and todo management on top of a single @tool.

Choices I made (issue had no spec)

#6477 has no body and no comments, so I followed the conventions of the existing 02-agents/harness/ and 04-hosting/af-hosting/ samples rather than inventing a new shape:

  • Placement / naming: added as a third sibling under af-hosting/, named local_responses_harness/ to match the existing local_responses/ and local_responses_workflow/ pair. It reuses that directory's exact layout (app.py + call_server.py + pyproject.toml + storage/).
  • Headless-friendly harness config: disabled the interactive-only features (plan/execute mode and the Textual console) and web search, and registered the tool with approval_mode="never_require" so a one-shot HTTP request never blocks on human tool approval. Kept todo management and compaction enabled so the target is a genuine harness agent, not a relabelled plain Agent.
  • Copied the repo copyright header verbatim onto every .py and followed SAMPLE_GUIDELINES.md (AzureCliCredential, over-documented, expected-output comment).

Happy to move or rename this (e.g. a top-level 04-hosting/harness-hosted-agent/, or folding it into local_responses/ as a variant) if maintainers prefer a different structure or scope — glad to adjust.

Verification

No cloud credentials were used; this was not run against Azure.

  • python3 -m py_compile app.py call_server.py — clean.
  • uv run ruff check and uv run ruff format --check on both files — clean.
  • Dry import in the workspace env resolves every symbol used (create_harness_agent, AgentState, all Responses helpers, FoundryChatClient, tool, ResponseStream).
  • create_agent() assembles the harness agent and create_session(session_id=...) succeeds (the exact call AgentState.get_or_create_session makes) — no network required.

Fixes #6477.

Copilot AI review requested due to automatic review settings July 9, 2026 09:18
@giles17 giles17 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Jul 9, 2026

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 new Python hosting sample under python/samples/04-hosting/af-hosting/local_responses_harness/ that mirrors the existing Responses-route + AgentState seam, but hosts a harness agent created via create_harness_agent(...) instead of a plain Agent.

Changes:

  • Registered the new sample in af-hosting/README.md.
  • Added a self-contained sample directory with FastAPI /responses route (app.py), a local OpenAI SDK client (call_server.py), and run/docs scaffolding (README.md, pyproject.toml, storage/.gitignore).

Reviewed changes

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

Show a summary per file
File Description
python/samples/04-hosting/af-hosting/README.md Adds the new local_responses_harness/ entry to the hosting samples index.
python/samples/04-hosting/af-hosting/local_responses_harness/storage/.gitignore Keeps session/storage artifacts out of git for the new sample.
python/samples/04-hosting/af-hosting/local_responses_harness/README.md Documents what the sample demonstrates, how to run it, and production-readiness cautions.
python/samples/04-hosting/af-hosting/local_responses_harness/pyproject.toml Defines dependencies and local uv git sources for hosting packages.
python/samples/04-hosting/af-hosting/local_responses_harness/call_server.py Adds a 3-turn OpenAI SDK client to exercise previous_response_id continuity.
python/samples/04-hosting/af-hosting/local_responses_harness/app.py Implements a FastAPI /responses route hosting a harness agent behind Responses helper functions.

Comment thread python/samples/04-hosting/af-hosting/local_responses_harness/app.py
Comment thread python/samples/04-hosting/af-hosting/local_responses_harness/app.py
@vaibhav-patel
vaibhav-patel force-pushed the fix/6477-hosted-harness-sample branch from 919f0a5 to b36eb7f Compare July 9, 2026 10:21
@moonbox3 moonbox3 added the hosting Usage: [Issues, PRs], Target: all hosting related solutions label Jul 14, 2026
Comment thread python/samples/04-hosting/af-hosting/local_responses_harness/app.py Outdated
Comment thread python/samples/04-hosting/af-hosting/local_responses_harness/app.py Outdated

@eavanvalkenburg eavanvalkenburg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as long as @moonbox3 his comments are addressed, this is fine for me. @westey-m could you also have a look

@westey-m

Copy link
Copy Markdown
Contributor

as long as @moonbox3 his comments are addressed, this is fine for me. @westey-m could you also have a look

LGTM, other than the fix to reference the latest code.

vaibhav-patel and others added 3 commits August 3, 2026 15:43
…mple

Addresses PR review: disable the harness file-memory and file-access
providers so the headless sample doesn't expose file tools or write
outside storage/, and correct the app.py docstring to match
call_server.py (which takes no prompt argument).
@moonbox3
moonbox3 force-pushed the fix/6477-hosted-harness-sample branch from b36eb7f to 7501b85 Compare August 3, 2026 06:59
@moonbox3
moonbox3 temporarily deployed to github-app-auth August 3, 2026 06:59 — with GitHub Actions Inactive
@moonbox3
moonbox3 enabled auto-merge August 3, 2026 07:08
@moonbox3

moonbox3 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Helping get this across the finish line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs hosting Usage: [Issues, PRs], Target: all hosting related solutions python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Add hosted agent sample for agent harness

6 participants