mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-04 22:49:23 +00:00
* feat: adopt directory-based docs versioning with Edge channel Switch docs.crewai.com from navigation-only versioning (every version selector entry rendered the same docs/<lang>/* source files) to Mintlify's directory-based versioning so each version selector entry renders its own snapshot. Add an "Edge" channel under docs/edge/<lang>/* that always reflects main HEAD for unreleased work, eliminating pre-release leakage onto frozen release labels. External links to canonical /<lang>/* URLs are preserved via wildcard redirects that always land on the current default version. Layout: - docs/edge/<lang>/* rolling source (you edit here) - docs/edge/enterprise-api.*.yaml - docs/v<X.Y.Z>/<lang>/* frozen, immutable snapshots - docs/v<X.Y.Z>/enterprise-api.*.yaml - docs/images/ shared, append-only - docs/docs.json nav + redirects URLs follow the Mintlify-idiomatic shape: /edge/<lang>/<page> for Edge, /v<X.Y.Z>/<lang>/<page> for every frozen snapshot. The wildcard redirects /<lang>/:slug* -> /<default>/<lang>/:slug* keep stale links working, and every freeze rewrites them (plus all per-section/per-page redirects) so destinations always resolve to the current default without depending on a second redirect hop. Release flow integration (devtools release): - New module crewai_devtools.docs_versioning.freeze() materialises docs/v<X.Y.Z>/ from docs/edge/, rewrites openapi: refs inside the snapshot, inserts the version into every language block in docs.json, and refreshes all redirect destinations. - _update_docs_and_create_pr() in cli.py now calls that freeze during Phase 2 of devtools release. Edge changelogs are updated first (so the snapshot freeze picks them up), then the snapshot is staged alongside docs.json, branched as docs/freeze-v<X.Y.Z>, and the PR is titled [docs-freeze] docs: snapshot and changelog for v<X.Y.Z> — the title prefix the new CI guard reads. - The PR still gates tag, GitHub release, PyPI publish, and the enterprise release as before; no new PRs are added. - Pre-releases (1.X.YaN, 1.X.YbN, ...) skip the snapshot — they ride Edge — and the docs PR title omits the [docs-freeze] prefix. - docs_check (AI-generated docs scaffolding) writes to docs/edge/<lang>/* so newly-generated unreleased docs land in Edge and never accidentally touch a frozen snapshot. Migration scripts (one-shot): - scripts/docs/freeze_historical_versions.py reconstructs all 16 historical snapshots (v1.10.0 .. v1.14.7) from git tags via git archive | tar, rewriting openapi: MDX refs so each snapshot reads its own enterprise-api YAML rather than the live one. - scripts/docs/prefix_version_paths.py one-shot-migrates docs.json: rewrites every page path in 16 versioned blocks to point under docs/v<X.Y.Z>/, inserts a new Edge entry per language, tags v1.14.7 as Latest (default), prunes pages whose target file doesn't exist in the snapshot (e.g. docs/ar/ didn't exist before v1.12.0), and writes the wildcard + per-section redirects. - scripts/docs/freeze_current_edge.py is now a thin CLI wrapper around docs_versioning.freeze for manual one-off freezes (e.g. retroactively snapshotting a forgotten release). CI guards (.github/workflows/docs-snapshots.yml): - Frozen snapshots under docs/v[0-9]*/ are immutable; only PRs whose title contains [docs-freeze] (i.e. release-cut PRs generated by devtools release or the manual wrapper) may modify them. - Images under docs/images/ are append-only since snapshots share a single image directory. Deleting or renaming an image breaks every historical snapshot that still references it. Restored docs/images/crewai-otel-export.png from PR #3673; it was deleted in PR #4908 but v1.10.0 / v1.10.1 snapshots still reference it. Restoring instead of editing the snapshots preserves historical rendering fidelity and validates the new append-only rule retroactively. Tests: - lib/devtools/tests/test_docs_versioning.py covers the freeze: file copy, openapi rewrite, version insertion, default demotion, redirect upserts, per-section redirect rewriting, idempotency, and invalid inputs. Verified locally with mintlify broken-links: 0 broken links across the full site (Edge + 16 frozen versions, 4 locales). AGENTS.md (repo root) is the contributor guide for the new model; RELEASING.md is the release-cut runbook; README's Contribution section links to both. Co-authored-by: Cursor <cursoragent@cursor.com> * style: resolve linter issues --------- Co-authored-by: Cursor <cursoragent@cursor.com>
230 lines
6.3 KiB
Plaintext
230 lines
6.3 KiB
Plaintext
---
|
|
title: Checkpointing
|
|
description: Salve automaticamente o estado de execucao para que crews, flows e agentes possam retomar apos falhas.
|
|
icon: floppy-disk
|
|
mode: "wide"
|
|
---
|
|
|
|
<Warning>
|
|
O checkpointing esta em versao inicial. As APIs podem mudar em versoes futuras.
|
|
</Warning>
|
|
|
|
## Visao Geral
|
|
|
|
O checkpointing salva automaticamente o estado de execucao durante uma execucao. Se uma crew, flow ou agente falhar no meio da execucao, voce pode restaurar a partir do ultimo checkpoint e retomar sem reexecutar o trabalho ja concluido.
|
|
|
|
## Inicio Rapido
|
|
|
|
```python
|
|
from crewai import Crew, CheckpointConfig
|
|
|
|
crew = Crew(
|
|
agents=[...],
|
|
tasks=[...],
|
|
checkpoint=True, # usa padroes: ./.checkpoints, em task_completed
|
|
)
|
|
result = crew.kickoff()
|
|
```
|
|
|
|
Os arquivos de checkpoint sao gravados em `./.checkpoints/` apos cada tarefa concluida.
|
|
|
|
## Configuracao
|
|
|
|
Use `CheckpointConfig` para controle total:
|
|
|
|
```python
|
|
from crewai import Crew, CheckpointConfig
|
|
|
|
crew = Crew(
|
|
agents=[...],
|
|
tasks=[...],
|
|
checkpoint=CheckpointConfig(
|
|
location="./my_checkpoints",
|
|
on_events=["task_completed", "crew_kickoff_completed"],
|
|
max_checkpoints=5,
|
|
),
|
|
)
|
|
```
|
|
|
|
### Campos do CheckpointConfig
|
|
|
|
| Campo | Tipo | Padrao | Descricao |
|
|
|:------|:-----|:-------|:----------|
|
|
| `location` | `str` | `"./.checkpoints"` | Caminho para os arquivos de checkpoint |
|
|
| `on_events` | `list[str]` | `["task_completed"]` | Tipos de evento que acionam um checkpoint |
|
|
| `provider` | `BaseProvider` | `JsonProvider()` | Backend de armazenamento |
|
|
| `max_checkpoints` | `int \| None` | `None` | Maximo de arquivos a manter; os mais antigos sao removidos primeiro |
|
|
|
|
### Heranca e Desativacao
|
|
|
|
O campo `checkpoint` em Crew, Flow e Agent aceita `CheckpointConfig`, `True`, `False` ou `None`:
|
|
|
|
| Valor | Comportamento |
|
|
|:------|:--------------|
|
|
| `None` (padrao) | Herda do pai. Um agente herda a configuracao da crew. |
|
|
| `True` | Ativa com padroes. |
|
|
| `False` | Desativacao explicita. Interrompe a heranca do pai. |
|
|
| `CheckpointConfig(...)` | Configuracao personalizada. |
|
|
|
|
```python
|
|
crew = Crew(
|
|
agents=[
|
|
Agent(role="Researcher", ...), # herda checkpoint da crew
|
|
Agent(role="Writer", ..., checkpoint=False), # desativado, sem checkpoints
|
|
],
|
|
tasks=[...],
|
|
checkpoint=True,
|
|
)
|
|
```
|
|
|
|
## Retomando a partir de um Checkpoint
|
|
|
|
```python
|
|
# Restaurar e retomar
|
|
crew = Crew.from_checkpoint("./my_checkpoints/20260407T120000_abc123.json")
|
|
result = crew.kickoff() # retoma a partir da ultima tarefa concluida
|
|
```
|
|
|
|
A crew restaurada pula tarefas ja concluidas e retoma a partir da primeira incompleta.
|
|
|
|
## Funciona em Crew, Flow e Agent
|
|
|
|
### Crew
|
|
|
|
```python
|
|
crew = Crew(
|
|
agents=[researcher, writer],
|
|
tasks=[research_task, write_task, review_task],
|
|
checkpoint=CheckpointConfig(location="./crew_cp"),
|
|
)
|
|
```
|
|
|
|
Gatilho padrao: `task_completed` (um checkpoint por tarefa finalizada).
|
|
|
|
### Flow
|
|
|
|
```python
|
|
from crewai.flow.flow import Flow, start, listen
|
|
from crewai import CheckpointConfig
|
|
|
|
class MyFlow(Flow):
|
|
@start()
|
|
def step_one(self):
|
|
return "data"
|
|
|
|
@listen(step_one)
|
|
def step_two(self, data):
|
|
return process(data)
|
|
|
|
flow = MyFlow(
|
|
checkpoint=CheckpointConfig(
|
|
location="./flow_cp",
|
|
on_events=["method_execution_finished"],
|
|
),
|
|
)
|
|
result = flow.kickoff()
|
|
|
|
# Retomar
|
|
flow = MyFlow.from_checkpoint("./flow_cp/20260407T120000_abc123.json")
|
|
result = flow.kickoff()
|
|
```
|
|
|
|
### Agent
|
|
|
|
```python
|
|
agent = Agent(
|
|
role="Researcher",
|
|
goal="Research topics",
|
|
backstory="Expert researcher",
|
|
checkpoint=CheckpointConfig(
|
|
location="./agent_cp",
|
|
on_events=["lite_agent_execution_completed"],
|
|
),
|
|
)
|
|
result = agent.kickoff(messages=[{"role": "user", "content": "Research AI trends"}])
|
|
```
|
|
|
|
## Provedores de Armazenamento
|
|
|
|
O CrewAI inclui dois provedores de armazenamento para checkpoints.
|
|
|
|
### JsonProvider (padrao)
|
|
|
|
Grava cada checkpoint como um arquivo JSON separado.
|
|
|
|
```python
|
|
from crewai import Crew, CheckpointConfig
|
|
from crewai.state import JsonProvider
|
|
|
|
crew = Crew(
|
|
agents=[...],
|
|
tasks=[...],
|
|
checkpoint=CheckpointConfig(
|
|
location="./my_checkpoints",
|
|
provider=JsonProvider(),
|
|
max_checkpoints=5,
|
|
),
|
|
)
|
|
```
|
|
|
|
### SqliteProvider
|
|
|
|
Armazena todos os checkpoints em um unico arquivo SQLite.
|
|
|
|
```python
|
|
from crewai import Crew, CheckpointConfig
|
|
from crewai.state import SqliteProvider
|
|
|
|
crew = Crew(
|
|
agents=[...],
|
|
tasks=[...],
|
|
checkpoint=CheckpointConfig(
|
|
location="./.checkpoints.db",
|
|
provider=SqliteProvider(),
|
|
),
|
|
)
|
|
```
|
|
|
|
|
|
## Tipos de Evento
|
|
|
|
O campo `on_events` aceita qualquer combinacao de strings de tipo de evento. Escolhas comuns:
|
|
|
|
| Caso de Uso | Eventos |
|
|
|:------------|:--------|
|
|
| Apos cada tarefa (Crew) | `["task_completed"]` |
|
|
| Apos cada metodo do flow | `["method_execution_finished"]` |
|
|
| Apos execucao do agente | `["agent_execution_completed"]`, `["lite_agent_execution_completed"]` |
|
|
| Apenas na conclusao da crew | `["crew_kickoff_completed"]` |
|
|
| Apos cada chamada LLM | `["llm_call_completed"]` |
|
|
| Em tudo | `["*"]` |
|
|
|
|
<Warning>
|
|
Usar `["*"]` ou eventos de alta frequencia como `llm_call_completed` gravara muitos arquivos de checkpoint e pode impactar o desempenho. Use `max_checkpoints` para limitar o uso de disco.
|
|
</Warning>
|
|
|
|
## Checkpointing Manual
|
|
|
|
Para controle total, registre seu proprio handler de evento e chame `state.checkpoint()` diretamente:
|
|
|
|
```python
|
|
from crewai.events.event_bus import crewai_event_bus
|
|
from crewai.events.types.llm_events import LLMCallCompletedEvent
|
|
|
|
# Handler sincrono
|
|
@crewai_event_bus.on(LLMCallCompletedEvent)
|
|
def on_llm_done(source, event, state):
|
|
path = state.checkpoint("./my_checkpoints")
|
|
print(f"Checkpoint salvo: {path}")
|
|
|
|
# Handler assincrono
|
|
@crewai_event_bus.on(LLMCallCompletedEvent)
|
|
async def on_llm_done_async(source, event, state):
|
|
path = await state.acheckpoint("./my_checkpoints")
|
|
print(f"Checkpoint salvo: {path}")
|
|
```
|
|
|
|
O argumento `state` e o `RuntimeState` passado automaticamente pelo barramento de eventos quando seu handler aceita 3 parametros. Voce pode registrar handlers em qualquer tipo de evento listado na documentacao de [Event Listeners](/pt-BR/concepts/event-listener).
|
|
|
|
O checkpointing e best-effort: se uma gravacao de checkpoint falhar, o erro e registrado no log, mas a execucao continua sem interrupcao.
|