import os
from fastapi import FastAPI
from agent_feedback import AgentFeedbackASGI
app = FastAPI()
@app.get("/search")
async def search_endpoint(q: str):
return {"results": await search(q)}
def state(scope, key):
return scope.get("state", {}).get(key)
instrumented_app = AgentFeedbackASGI(
app,
api_key=os.environ["AGENT_FEEDBACK_KEY"],
include=("/search", "/docs/*"),
account_ref=lambda scope: state(scope, "account_id"),
user_ref=lambda scope: state(scope, "user_id"),
anonymous_ref=lambda scope: state(scope, "first_party_visitor_id"),
customer_ref=lambda scope: state(scope, "account_id"), # durable Ask once compatibility
session_ref=lambda scope: state(scope, "journey_id"), # optional server-issued journey
)
app = ProductTenantAuthMiddleware(instrumented_app)