CLI API client. The ZIP deployment and integration-token methods live here as well as in newer crewai-core versions so editable CLI installs still work when an older crewai-core is present in the runtime environment. The evaluation methods live here because only the CLI calls them.
| 14 | |
| 15 | |
| 16 | class PlusAPI(_CorePlusAPI): |
| 17 | """CLI API client. |
| 18 | |
| 19 | The ZIP deployment and integration-token methods live here as well as in |
| 20 | newer crewai-core versions so editable CLI installs still work when an |
| 21 | older crewai-core is present in the runtime environment. The evaluation |
| 22 | methods live here because only the CLI calls them. |
| 23 | """ |
| 24 | |
| 25 | EVALUATIONS_RESOURCE = f"{_CorePlusAPI.TRACING_RESOURCE}/evaluations" |
| 26 | # AMP reads the run's spans from Wharf inside the POST; a large run takes a while. |
| 27 | EVALUATION_START_TIMEOUT = 120.0 |
| 28 | EVALUATION_POLL_TIMEOUT = 30.0 |
| 29 | # The export carries every setup's outputs, checks and traces — tens of MB |
| 30 | # for a large comparison — and AMP gathers them before it answers. |
| 31 | EVALUATION_EXPORT_TIMEOUT = httpx.Timeout(EVALUATION_POLL_TIMEOUT, read=120.0) |
| 32 | CLI_INTEGRATION_TOKEN_RESOURCE = "/crewai_plus/api/v1/me/integration-token" # noqa: S105 - API path, not a secret |
| 33 | |
| 34 | def get_integration_token(self) -> str: |
| 35 | """Return the Enterprise Action Auth Token for the active organization.""" |
| 36 | response = self._make_request( |
| 37 | "GET", self.CLI_INTEGRATION_TOKEN_RESOURCE, timeout=30 |
| 38 | ) |
| 39 | response.raise_for_status() |
| 40 | payload = response.json() |
| 41 | token = payload.get("api_key") if isinstance(payload, dict) else None |
| 42 | if not isinstance(token, str) or not token: |
| 43 | raise RuntimeError("AMP did not return an integration token") |
| 44 | return token |
| 45 | |
| 46 | def create_evaluation( |
| 47 | self, |
| 48 | execution_id: str, |
| 49 | *, |
| 50 | eval_config: str | None = None, |
| 51 | project_id: str | None = None, |
| 52 | ) -> httpx.Response: |
| 53 | """Ask AMP to evaluate the traced run EXECUTION_ID (crewai eval). |
| 54 | |
| 55 | EVAL_CONFIG is the project's own `eval.jsonc` when it has one: what |
| 56 | good means for this crew, in its own words. Sent as it was written, |
| 57 | comments and all, and read by the grader rather than here. PROJECT_ID |
| 58 | is `[tool.crewai].project_id`, so the evaluation is filed under the |
| 59 | project it is about. |
| 60 | """ |
| 61 | body: dict[str, str] = {"execution_id": execution_id} |
| 62 | if eval_config: |
| 63 | body["eval_config"] = eval_config |
| 64 | if project_id: |
| 65 | body["project_id"] = project_id |
| 66 | return self._make_request( |
| 67 | "POST", |
| 68 | self.EVALUATIONS_RESOURCE, |
| 69 | json=body, |
| 70 | timeout=self.EVALUATION_START_TIMEOUT, |
| 71 | ) |
| 72 | |
| 73 | def create_models_evaluation( |
no outgoing calls