Skip to content

fix: #6481 - Add async support for before/after_kickoff_callbacks in akickoff - #6697

Open
Diwak4r wants to merge 2 commits into
crewAIInc:mainfrom
Diwak4r:fix/6481-async-callbacks-support
Open

fix: #6481 - Add async support for before/after_kickoff_callbacks in akickoff#6697
Diwak4r wants to merge 2 commits into
crewAIInc:mainfrom
Diwak4r:fix/6481-async-callbacks-support

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Fixes #6481 - Adds async support for before_kickoff_callbacks and after_kickoff_callbacks in Crew.akickoff() method.

Changes

  • lib/crewai/src/crewai/crew.py: Added inspect.isawaitable() checks for both before_kickoff_callbacks (via new aprepare_kickoff) and after_kickoff_callbacks to properly await async callables
  • lib/crewai/src/crewai/crews/utils.py: Added async aprepare_kickoff() function with async callback support for before_kickoff_callbacks
  • lib/crewai/tests/crew/test_async_callbacks.py: Added 4 comprehensive tests:
    • test_akickoff_calls_async_before_callback - verifies async before callback is awaited
    • test_akickoff_calls_async_after_callback - verifies async after callback is awaited
    • test_akickoff_mixed_sync_and_async_callbacks - verifies mixed sync/async callbacks work together
    • test_akickoff_empty_callbacks - verifies empty callbacks still function normally

Root Cause

The akickoff method only awaited task_callbacks but not before_kickoff_callbacks or after_kickoff_callbacks, causing async callbacks to not execute properly (coroutines were never awaited).

Fix

Applied the same inspect.isawaitable() pattern used for task_callbacks to both kickoff callback types, and created an async version of prepare_kickoff for the async path.

Testing

All 4 new tests pass + all 11 existing async crew tests pass (15 total). Only Windows teardown PermissionError observed (environmental, not code-related).

Diwak4r added 2 commits July 28, 2026 12:39
…_original_tool_calling for consistent error handling
…th proper awaiting of async callables and async prepare_kickoff for before_kickoff_callbacks
Copilot AI review requested due to automatic review settings July 28, 2026 08:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca149960-c3e1-4fb7-a70c-77baef2f1c8b

📥 Commits

Reviewing files that changed from the base of the PR and between 97981ed and b6ccda0.

📒 Files selected for processing (4)
  • lib/crewai/src/crewai/crew.py
  • lib/crewai/src/crewai/crews/utils.py
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/crew/test_async_callbacks.py

📝 Walkthrough

Walkthrough

Crew.akickoff now supports async kickoff callbacks through asynchronous preparation and awaitable callback handling. New tests cover sync, async, mixed, and empty callback lists. Tool argument validation now consistently uses ToolUsageError.

Changes

Async kickoff callbacks

Layer / File(s) Summary
Async kickoff preparation
lib/crewai/src/crewai/crews/utils.py
Adds aprepare_kickoff, preserving kickoff setup while awaiting asynchronous before-kickoff callbacks.
Async kickoff integration
lib/crewai/src/crewai/crew.py
akickoff uses asynchronous preparation and awaits awaitable after-kickoff callback results.
Async callback validation
lib/crewai/tests/crew/test_async_callbacks.py
Tests async before and after callbacks, mixed callback types, and empty callback lists.

Tool argument errors

Layer / File(s) Summary
Tool argument error handling
lib/crewai/src/crewai/tools/tool_usage.py
Invalid tool arguments now consistently raise or return a localized ToolUsageError.

Sequence Diagram(s)

sequenceDiagram
  participant CrewAkickoff as Crew.akickoff
  participant AsyncPreparation as aprepare_kickoff
  participant TaskExecution as Task.aexecute_sync
  participant AfterCallback as after_kickoff_callback
  CrewAkickoff->>AsyncPreparation: await input preparation
  AsyncPreparation-->>CrewAkickoff: return normalized inputs
  CrewAkickoff->>TaskExecution: execute kickoff task
  TaskExecution-->>CrewAkickoff: return CrewOutput
  CrewAkickoff->>AfterCallback: invoke callback
  AfterCallback-->>CrewAkickoff: return result or awaitable
  CrewAkickoff-->>CrewAkickoff: await result when awaitable
Loading

Suggested reviewers: copilot, greysonlalonde

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The tool_usage.py error-handling change is unrelated to async kickoff callback support and appears out of scope. Remove or split the tool_usage.py change into a separate PR so this patch stays focused on #6481.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main async kickoff callback fix and matches the changeset.
Description check ✅ Passed The description is directly related to the async kickoff callback support changes.
Linked Issues check ✅ Passed The PR addresses #6481 by awaiting async after callbacks and adding async before-callback preparation plus tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (defensive_cruft). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] before/after_kickoff_callbacks do not support async callables in akickoff

2 participants