Skip to Content
ExamplesCrewAI

CrewAI

CrewAI 1.x with donkey.crewai.llm("…"). openai/ models go through CrewAI’s native OpenAI provider to the proxy’s /chat/completions route. CrewAI owns the transport: the credentials go on the wire, but there is no run id and no last_call. Refusals are still typed, because the native provider keeps the openai error’s response.

Both scripts need a live gateway; there is no offline CrewAI script.

#ScriptShowsNeeds
01basic-gw.pyllm.call(...), then a one-agent crewProxy credentials
02typed-refusals-live.pyPIIDetected, UpstreamRequestError, AuthErrorProxy + PII policy

Install

Follow the examples setup first, then:

python -m pip install -e "../donkey-development-kit/python[llm,crewai]" set -a; source .env.local; set +a

Both scripts set CREWAI_TRACING_ENABLED=false unless you set it yourself. Otherwise CrewAI stops on an interactive “view your traces?” prompt and the script appears to hang with no output.

01 — A direct call and a crew

python "demos/human-made/crewai/01 - basic-gw.py"
donkey = Donkey.from_env() llm = donkey.crewai.llm("gpt-4o") print(llm.call("Say hello in exactly three words.")) agent = Agent(role="Greeter", goal="Greet people", backstory="Friendly and brief.", llm=llm) out = agent.kickoff("Say goodbye in exactly three words.") print(out.raw) print("usage ", out.usage_metrics) print("last_call", donkey.last_call.status.value, donkey.last_call.surface)

You should see: the greeting, the crew’s answer, CrewAI’s usage_metrics, and last_call unavailable … — CrewAI owns the transport, so read usage from usage_metrics.

02 — Typed refusals, live

python "demos/human-made/crewai/02 - typed-refusals-live.py"

Three cases, each with its own Donkey: a contact record for PIIDetected, a model that does not exist for UpstreamRequestError, and wrong credentials for AuthError.

for name, case_cfg, model, prompt in CASES: donkey = Donkey(case_cfg) try: donkey.crewai.llm(model).call(prompt) print(name, "NO REFUSAL") except openai.APIStatusError as err: error = classify(err.response) print(name, "->", type(error).__name__, getattr(error, "entities", None)) donkey.close()

Needs: llm-pii-detection-policy with Email and action Reject for the first case. You should see: <case> -> <Type> <entities> per case, or <case> NO REFUSAL. A 404 means the proxy’s upstream has no /chat/completions route.

Learn more: CrewAI

Source: demos/human-made/crewai/

Last updated on