What is @after_kickoff?
@after_kickoff methods receive the CrewOutput produced at the end of a successful kickoff (or the nearest equivalent object your CrewAI version exposes) and run exactly once per invocation. Use them to persist .raw text, push structured pydantic/json_dict payloads to warehouses, emit Slack notifications, or close database connections opened in @before_kickoff. You may transform the output object by returning a replacement, which is useful when downstream APIs expect a different schema than CrewAI defaults.
Keep failure handling intentional: swallowing exceptions here can mask persistence bugs, while re-raising may mark an otherwise successful agent run as failed for your caller. Prefer transactional writes with timeouts and structured logging so operators can tell agent quality issues apart from sink outages.
This hook is not a substitute for streaming callbacks — if you need per-token UI updates, wire BaseEventListener or LLM streaming instead and reserve @after_kickoff for batch summaries.
When to Use
Persisting results, sending notifications, closing external connections.
Use Cases
- • Persist output
- • Slack/email notification
- • Close DB connection
Key Features
- ✓ Runs once per kickoff
- ✓ Receives CrewOutput
- ✓ Can transform the return value
When NOT to Use
Per-step or per-task observability — use callbacks or event listeners.
Notes
Always return output
Omitting a return passes None upstream and breaks callers expecting CrewOutput. Return the object even if you only perform side effects.
Partial failures
If tasks fail mid-run, confirm whether your CrewAI version still invokes @after_kickoff — do not rely on this hook as the only error path.
Latency
Heavy synchronous uploads block the API response to users. Queue work or use async sinks when closing the loop.
Import
from crewai.project import after_kickoff
How to Apply
@after_kickoff
def save(self, output):
persist(output.raw)
return output
What It Enables
- ✓ Cleanup
- ✓ Result persistence
- ✓ Post-run notifications
Code Examples
Persist
@after_kickoff
def save(self, output):
Path('out.md').write_text(output.raw)
return output
Emit metrics from token usage
@after_kickoff
def metrics(self, output):
usage = getattr(output, 'token_usage', None)
if usage:
statsd.timing('crew.tokens', usage.total_tokens)
return output
Strip internal notes before API return
@after_kickoff
def redact(self, output):
text = output.raw.replace('INTERNAL:', '')
output.raw = text
return output
Integration Patterns
Pairs with @before_kickoff
Inside @CrewBase class
Common Mistakes
❌ Forgetting to return output — caller now gets None
✅ Always return the (possibly transformed) output.
Related: Task class reference, Agent class reference, and the first Crew tutorial.
@after_kickoff FAQ
What is @after_kickoff in CrewAI?
Registers a method to run after Crew.kickoff() — for cleanup, post-processing, or persisting the output. @after_kickoff methods receive the CrewOutput produced at the end of a successful kickoff (or the nearest equivalent object your CrewAI version exposes) and run exactly once per invocation. Use them to persist .raw text, push structured pydantic/json_dict payloads to warehouses, emit Slack notifications, or close database connections opened in @before_kickoff. You may transform the output object by returning a replacement, which is useful when downstream APIs expect a differe…
Which module defines the CrewAI decorator @after_kickoff?
DevShelfHub maps @after_kickoff to Python module crewai.project. Pin your installed crewai version and match imports to the import snippet on this page.
When should I use @after_kickoff?
Persisting results, sending notifications, closing external connections.
When should I avoid @after_kickoff?
Per-step or per-task observability — use callbacks or event listeners.
How do I apply @after_kickoff in Python?
@after_kickoff def save(self, output): persist(output.raw) return output
Where can I explore more CrewAI API reference pages?
Open the CrewAI API reference index on DevShelfHub to search classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.