sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Deduplicate logic for getting request model in `openai-agents`

Open alexander-alderman-webb opened this issue 6 months ago • 5 comments

Remove duplication between

https://github.com/getsentry/sentry-python/blob/53188b322fc96dab0c4b064945b62e773fada63c/sentry_sdk/integrations/openai_agents/spans/ai_client.py#L26-L29

and

https://github.com/getsentry/sentry-python/blob/53188b322fc96dab0c4b064945b62e773fada63c/sentry_sdk/integrations/openai_agents/utils.py#L59-L62

alexander-alderman-webb avatar May 26 '26 15:05 alexander-alderman-webb

PY-2495

linear-code[bot] avatar May 26 '26 15:05 linear-code[bot]

Agentic systems are turning into always-on factories: one request fans out into model calls, tool calls, policy checks, and storage.

The hard part is rarely tokens/sec — it is control-plane reliability:

  1. Fan-out control — hard cap on tools/steps per request before external writes
  2. Durable id + idempotency — one write per business object (ledger / preflight)
  3. Observable long jobs — progress + cooperative cancel on multi-minute runs
  4. Expected vs actual — durable artifact id before marking success
  5. Policy before action — gate that can refuse known-bad side effects

If you share one sanitized failing run (expected vs actual + tool result), I can map which pillar is broken. Architecture only.

IgorGanapolsky avatar Jul 24 '26 18:07 IgorGanapolsky

Hi! I'd be happy to take this one.

It looks like the model lookup can be moved into a small helper in utils.py and reused by both call sites, while keeping the current precedence between agent.model and _sentry_request_model.

I'll run the OpenAI Agents integration tests and add coverage if the existing tests don't exercise both paths. Does that sound good?

takagibit18 avatar Sep 03 '26 05:09 takagibit18

Hi — interested in taking this if it’s still free. Plan: extract the duplicated agent/request model resolution from spans/ai_client.py and utils.py into one helper (same precedence as today), call it from both sites, and add a focused unit test so the precedence can’t drift. Happy to keep the PR scoped to dedupe only (no behavior change). OK to assign?

tiagovilasboas avatar Sep 10 '26 22:09 tiagovilasboas

Closing this because we won't set gen_ai.request.model in _set_agent_data() in the major anyway.

alexander-alderman-webb avatar Sep 16 '26 15:09 alexander-alderman-webb