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).

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: Team

Run ID: f774a125-03c3-42a4-963e-f010dd017ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 1b855b4 and 59d446b.

📒 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
🚧 Files skipped from review as they are similar to previous changes (4)
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/crew/test_async_callbacks.py
  • lib/crewai/src/crewai/crew.py
  • lib/crewai/src/crewai/crews/utils.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Crew.akickoff now supports asynchronous before- and after-kickoff callbacks. Kickoff preparation awaits asynchronous callbacks. Tool argument validation now consistently uses the localized ToolUsageError.

Changes

Async kickoff callbacks

Layer / File(s) Summary
Async kickoff preparation
lib/crewai/src/crewai/crews/utils.py, lib/crewai/src/crewai/crew.py
Adds aprepare_kickoff, preserves kickoff setup, and awaits 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 asynchronous 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 TaskExecution
  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

Merge Risk: ⚪ Minimal · up to 59d44

Async kickoff callbacks are now awaited for both preparation and completion paths, with coverage for async, synchronous, mixed, and empty callback configurations. No concrete merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The tool_usage.py change alters ToolUsageError behavior and is unrelated to async kickoff callback support described in issue #6481. Remove the unrelated tool_usage.py change from this pull request, or link it to a separate issue and submit it separately.
Docstring Coverage ⚠️ Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies issue #6481 and the main change: async support for before and after kickoff callbacks in akickoff.
Description check ✅ Passed The description explains the issue, root cause, implementation, affected files, and test results. It does not use every template heading, but it contains the required information in equivalent section…
Linked Issues check ✅ Passed The changes satisfy issue #6481 by adding async before-callback support through aprepare_kickoff, awaiting async after-callback results, and adding tests for async, mixed, and empty callback cases.
  • Fix all pre-merge checks with AI
✨ 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.

Copilot AI review requested due to automatic review settings August 3, 2026 03:51

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.

Copilot AI review requested due to automatic review settings August 4, 2026 02:23
@Diwak4r
Diwak4r force-pushed the fix/6481-async-callbacks-support branch from 6254137 to 973c189 Compare August 4, 2026 02:23

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.

@Diwak4r
Diwak4r force-pushed the fix/6481-async-callbacks-support branch from 973c189 to 955c142 Compare August 22, 2026 19:02
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

…_original_tool_calling for consistent error handling
…th proper awaiting of async callables and async prepare_kickoff for before_kickoff_callbacks
@Diwak4r
Diwak4r force-pushed the fix/6481-async-callbacks-support branch from 955c142 to 59d446b Compare September 7, 2026 16:58
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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