crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[Project] Integrate OpenAI Decisions API with CrewAI routing and guardrails

Open lorenzejay opened this issue 1 month ago • 7 comments

Outcome

Let a CrewAI workflow use OpenAI Decisions API typed judgments for a concrete routing or guardrail task. Preserve predicate probabilities, discrete choices, scores, and associated metadata instead of treating the result as generated chat text.

Difficulty: Hard. Team: 2–3 contributors. Prerequisites: Python, typed models, async API clients, Flow routing or guardrails, and integration testing.

Verified starting point

Official OpenAI Decisions documentation describes POST /v1/decisions with predicate, choice, and score questions. At issue creation it is in public beta and the documented Python SDK minimum is 3.26.0. This checkout pins openai>=2.30.0,<3; SDK compatibility must be resolved before integration. Recheck current API and model availability when implementing.

Milestones / PR deliverables

  • [ ] Establish the smallest compatibility path and public integration shape. Prefer existing SDK types and HTTP/client infrastructure; avoid an unconditional SDK upgrade without running existing provider checks.
  • [ ] Implement a narrow Python adapter for one question type first, with sync/async behavior and mocked request/response tests. Do not force typed decisions into BaseLLM.call as arbitrary chat text.
  • [ ] Extend the adapter to predicate, choice, and score judgments, with clear handling of invalid questions, missing/malformed answers, and API failures.
  • [ ] Add one opt-in Flow routing or guardrail integration with explicit, configurable thresholds or allowed choices.
  • [ ] Add tests showing boundaries do not silently accept failed or missing decisions and existing workflows are unchanged when the feature is disabled.
  • [ ] Provide one small labeled evaluation dataset and a reproducible example comparing decision quality, measured latency, and measured usage against an ordinary LLM baseline. Live runs are optional and explicitly require credentials.

Acceptance criteria

Submit Python implementation PRs with mocked tests that run without paid calls. The completed example exposes typed answers, handles errors predictably, and demonstrates one real CrewAI use case. No new cross-provider decision abstraction is required for the first version.

Starting points

Contribution workflow

This project is intended for contributors to implement Python changes and submit their own PRs. Deliver work as small, independently reviewable PRs linked to open implementation issues. Include behavioral tests, type annotations, and relevant docs. A project is complete when the scoped code is merged and its example works.

Open to all contributors, including students in the Stanford semester collaboration. Interested contributors should state the milestone they want to own in the issue before starting. Mentor: to be designated by maintainers; no assignment is implied.

Follow .github/CONTRIBUTING.md. For docs edits, use docs/edge/ and sync ar, ko, and pt-BR per DOCS_TRANSLATIONS.md. This tracking issue was prepared with AI assistance.

Additional Stanford cohort implementation slots

These distinct follow-up tickets are coordinated through #8118. Existing volunteer claims and PRs remain in place. Maintainer assignment determines ownership of the new cohort tickets.

  • [ ] #8129 — Integrate an OpenAI Decisions predicate with callable task guardrails (hard)

lorenzejay avatar Oct 09 '26 22:10 lorenzejay

Hi! I’d like to take the first implementation milestone: establish the smallest compatibility path and add a narrow typed Decisions adapter for one question type, with sync/async mocked tests and no paid API calls.

I’ll first verify the current OpenAI SDK compatibility constraints, then keep the integration isolated from BaseLLM.call and preserve typed decision data instead of flattening it into chat text.

If that milestone is still available, I’m happy to own it and submit it as a focused PR.

iveteamorim avatar Oct 11 '26 22:10 iveteamorim

Hi @iveteamorim, I'm working on #8129 (the predicate guardrail) and wanted to line up with your adapter milestone.

My plan is a self-contained DecisionGuardrail callable that fits the existing (bool, Any) guardrail contract, so no changes to Task or process_guardrail. It depends only on this structural protocol, so it doesn't touch the SDK and leaves the compatibility choice with your adapter:

class PredicateAnswer(BaseModel):
    name: str
    probability: float  # 0.0–1.0

class PredicateDecider(Protocol):
    def predicate(
        self, input: str, *, name: str, instructions: str
    ) -> PredicateAnswer | None:
        """None = no answer for that question (missing or refusal); raise on API/transport errors."""

The guardrail calls this synchronously, since guardrails run sync today even on the async task path. It passes only when probability >= threshold, and it fails closed on None, a mismatched name, a malformed probability or any exception.

Could your adapter expose something with this shape, or a thin wrapper around it? If your answer type or method signature differs, tell me and I'll adjust on my side. I'll be testing against a fake until your PR lands.

namupta-max avatar Oct 14 '26 21:10 namupta-max

Hi @namupta-max, thanks for reaching out!

Your proposed PredicateDecider interface looks good. I'll align the adapter with that contract, preserving typed responses and distinguishing missing answers from API errors.

I'll first verify the SDK compatibility path and confirm the final interface before submitting the adapter PR.

Thanks for coordinating!

iveteamorim avatar Oct 15 '26 10:10 iveteamorim

Hi @lorenzejay, I'd like to take the evaluation milestone: a small labeled dataset and a reproducible example comparing Decisions against an ordinary LLM baseline on decision quality, latency and usage. If that milestone is still available, I'm happy to own it and deliver it as two small PRs, dataset first, then the example.

Plan: a written labeling guide, 240 labeled examples (100 routing/choice, 80 guardrail/predicate, 60 score) with a deliberate share of hard cases (near-miss routes, outputs that look fine but break a rule, empty or garbled outputs), and labels frozen before any system is run. I'd use the record format from scripts/jev_evaluation_runner.py (#8230) so the offline evaluation reuses existing tooling, and map Decisions predicate/choice/score answers onto it. The example would build on #8201 and #8167 once they land, with live runs opt-in and tests mocked.

Two questions before I start on the records:

  • where would you like the dataset to live in the repo,
  • and is extending that runner for Decisions answers preferred over a separate script?

ramarlina avatar Oct 23 '26 07:10 ramarlina

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 22 '26 12:11 github-actions[bot]

Hello, and thank you for labelling this as a good first issue and for welcoming new contributors.

I'm interested in working on it. I build full-stack apps in TypeScript, so the codebase should be comfortable for me. Could you please assign it to me? I'll post a short plan first.

Vijay431 avatar Nov 26 '26 02:11 Vijay431

I am posting on the evaluation milestone, which ramarlina outlined in October, because the design choices there affect the adapter and guardrail work too. A decision used for routing or for blocking a task output is only useful if the evaluation reports more than headline accuracy.

Three things I would want the dataset and runner to capture. First, calibration, not just correctness. A predicate that returns 0.8 should be right about eight times in ten, and a guardrail threshold set at 0.7 behaves very differently depending on whether scores cluster near the boundary. Reporting accuracy in bands around the configured threshold would show whether a threshold is safe to use. Second, the failure cases need their own counts: missing answer, malformed probability, mismatched question name, and API error should each appear as separate outcomes, never folded into a simple pass or fail, since the acceptance criteria require that boundaries do not silently accept them. Third, the comparison against an ordinary LLM baseline should use the same labeled records, the same pass rule, and a note of cost and latency per decision, because a small quality gain at several times the latency may not be worth it for a guardrail called on every task.

On ramarlina's open questions, my view is that extending the existing evaluation runner keeps one record format for both paths, which makes the baseline comparison fairer.

If useful, I can write up a short evaluation design note covering the threshold band reporting and the failure outcome categories for the dataset PR.

Eshaan Jain, independent researcher (IEEE Senior Member)

eshaanjain26 avatar Nov 28 '26 21:11 eshaanjain26