跳转到内容

Webhook 流式传输

Enterprise Event Streaming 让你能够接收关于已部署到 CrewAI AMP 的 crews 和 flows 的实时 webhook 更新,例如模型调用、工具使用和 flow 步骤。

使用 Kickoff API 时,在请求中加入 webhooks 对象,例如:

{
"inputs": { "foo": "bar" },
"webhooks": {
"events": ["crew_kickoff_started", "llm_call_started"],
"url": "https://your.endpoint/webhook",
"realtime": false,
"authentication": {
"strategy": "bearer",
"token": "my-secret-token"
}
}
}

如果 realtime 设置为 true,每个事件都会单独且立即投递,但代价是 crew/flow 性能会下降。

每个 webhook 都会发送一个事件列表:

{
"events": [
{
"id": "event-id",
"execution_id": "crew-run-id",
"timestamp": "2025-02-16T10:58:44.965Z",
"type": "llm_call_started",
"data": {
"model": "gpt-4",
"messages": [
{ "role": "system", "content": "You are an assistant." },
{ "role": "user", "content": "Summarize this article." }
]
}
}
]
}

data 对象的结构会因事件类型而异。请参考 GitHub 上的 event list

由于请求通过 HTTP 发送,事件顺序无法保证。如果你需要顺序,请使用 timestamp 字段。

CrewAI 在 Enterprise Event Streaming 中同时支持系统事件和自定义事件。这些事件会在 crew 和 flow 执行期间发送到你配置的 webhook endpoint。

  • flow_created
  • flow_started
  • flow_finished
  • flow_plot
  • method_execution_started
  • method_execution_finished
  • method_execution_failed
  • agent_execution_started
  • agent_execution_completed
  • agent_execution_error
  • lite_agent_execution_started
  • lite_agent_execution_completed
  • lite_agent_execution_error
  • agent_logs_started
  • agent_logs_execution
  • agent_evaluation_started
  • agent_evaluation_completed
  • agent_evaluation_failed
  • crew_kickoff_started
  • crew_kickoff_completed
  • crew_kickoff_failed
  • crew_train_started
  • crew_train_completed
  • crew_train_failed
  • crew_test_started
  • crew_test_completed
  • crew_test_failed
  • crew_test_result
  • task_started
  • task_completed
  • task_failed
  • task_evaluation
  • tool_usage_started
  • tool_usage_finished
  • tool_usage_error
  • tool_validate_input_error
  • tool_selection_error
  • tool_execution_error
  • llm_call_started
  • llm_call_completed
  • llm_call_failed
  • llm_stream_chunk
  • llm_guardrail_started
  • llm_guardrail_completed
  • memory_query_started
  • memory_query_completed
  • memory_query_failed
  • memory_save_started
  • memory_save_completed
  • memory_save_failed
  • memory_retrieval_started
  • memory_retrieval_completed
  • knowledge_search_query_started
  • knowledge_search_query_completed
  • knowledge_search_query_failed
  • knowledge_query_started
  • knowledge_query_completed
  • knowledge_query_failed
  • agent_reasoning_started
  • agent_reasoning_completed
  • agent_reasoning_failed

事件名称与内部事件总线一致。完整事件列表请查看 GitHub。

你也可以发出自己的自定义事件,它们会与系统事件一起通过 webhook stream 发送。