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
52 lines
1.8 KiB
Markdown
52 lines
1.8 KiB
Markdown
# agent-framework-hosting-responses
|
|
|
|
OpenAI Responses-shaped helpers for app-owned Agent Framework hosting.
|
|
|
|
This package provides the Responses-specific conversion layer:
|
|
|
|
- `responses_to_run(...)` — convert a Responses request body into Agent
|
|
Framework run values.
|
|
- `responses_session_id(...)` — extract a prior `resp_*` response id or
|
|
`conv_*` conversation id from the request body when present.
|
|
- `create_response_id(...)` — mint a Responses-shaped response id.
|
|
- `responses_from_run(...)` — convert an `AgentResponse` into a
|
|
Responses-compatible JSON payload.
|
|
- `responses_from_streaming_run(...)` — convert an Agent Framework
|
|
`ResponseStream` into Responses-compatible SSE events.
|
|
|
|
FastAPI/Starlette/Django/Azure Functions code owns route registration,
|
|
authentication, status codes, response construction, and background work.
|
|
|
|
```python
|
|
from agent_framework_hosting import AgentState
|
|
from agent_framework_hosting_responses import (
|
|
create_response_id,
|
|
responses_from_run,
|
|
responses_session_id,
|
|
responses_to_run,
|
|
)
|
|
from fastapi import Body, FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
|
|
app = FastAPI()
|
|
state = AgentState(agent)
|
|
|
|
|
|
@app.post("/responses")
|
|
async def responses(body: dict = Body(...)) -> JSONResponse:
|
|
run = responses_to_run(body)
|
|
session_id = responses_session_id(body)
|
|
response_id = create_response_id()
|
|
session = await state.get_or_create_session(session_id or response_id)
|
|
result = await (await state.get_target()).run(
|
|
run["messages"],
|
|
session=session,
|
|
options=run["options"],
|
|
)
|
|
await state.set_session(response_id, session)
|
|
return JSONResponse(responses_from_run(result, response_id=response_id, session_id=session_id))
|
|
```
|
|
|
|
The base execution-state helpers live in
|
|
[`agent-framework-hosting`](https://pypi.org/project/agent-framework-hosting/).
|