Python: Add hosted agent sample for the agent harness#7010
Open
vaibhav-patel wants to merge 2 commits into
Open
Python: Add hosted agent sample for the agent harness#7010vaibhav-patel wants to merge 2 commits into
vaibhav-patel wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
/responsesroute (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 on lines
+138
to
+146
| # Turn off the interactive-only and provider-specific features so the | ||
| # agent is a good fit for a headless, one-shot HTTP endpoint. Todo | ||
| # management and compaction stay enabled. | ||
| disable_mode=True, | ||
| disable_web_search=True, | ||
| # The app owns session state locally, so do not also persist server-side | ||
| # Responses conversations. | ||
| default_options={"store": False}, | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
Good catch — disabled both providers (disable_file_memory=True, disable_file_access=True) in b36eb7f, so this headless sample no longer exposes file read/write tools or creates on-disk side effects outside storage/.
…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).
919f0a5 to
b36eb7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new Python sample,
python/samples/04-hosting/af-hosting/local_responses_harness/, that hosts a harness agent (built withcreate_harness_agent) behind the same helper-first Responses hosting seam used by the existinglocal_responses/sample.Files:
app.py— a module-level FastAPI ASGI app whose target is acreate_harness_agent(...)agent. UsesAgentState+ theagent-framework-hosting-responseshelpers (responses_to_run,responses_session_id,create_response_id,responses_from_run,responses_from_streaming_run) exactly likelocal_responses/app.py, with a native/responsesroute and Hypercorn startup.call_server.py— a plainopenaiSDK client that drives a three-turn conversation (rotatingprevious_response_id) to exercise session continuity.pyproject.toml— mirrorslocal_responses/pyproject.toml([tool.uv.sources]wires the pre-PyPIagent-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.af-hosting/README.md.The takeaway the sample makes concrete: a harness agent is just an
Agent, so it drops straight into the existingAgentState/ 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/and04-hosting/af-hosting/samples rather than inventing a new shape:af-hosting/, namedlocal_responses_harness/to match the existinglocal_responses/andlocal_responses_workflow/pair. It reuses that directory's exact layout (app.py+call_server.py+pyproject.toml+storage/).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 plainAgent..pyand followedSAMPLE_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 intolocal_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 checkanduv run ruff format --checkon both files — clean.create_harness_agent,AgentState, all Responses helpers,FoundryChatClient,tool,ResponseStream).create_agent()assembles the harness agent andcreate_session(session_id=...)succeeds (the exact callAgentState.get_or_create_sessionmakes) — no network required.Fixes #6477.