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 格式
Section titled “Webhook 格式”每个 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 事件:
Section titled “Flow 事件:”flow_createdflow_startedflow_finishedflow_plotmethod_execution_startedmethod_execution_finishedmethod_execution_failed
Agent 事件:
Section titled “Agent 事件:”agent_execution_startedagent_execution_completedagent_execution_errorlite_agent_execution_startedlite_agent_execution_completedlite_agent_execution_erroragent_logs_startedagent_logs_executionagent_evaluation_startedagent_evaluation_completedagent_evaluation_failed
Crew 事件:
Section titled “Crew 事件:”crew_kickoff_startedcrew_kickoff_completedcrew_kickoff_failedcrew_train_startedcrew_train_completedcrew_train_failedcrew_test_startedcrew_test_completedcrew_test_failedcrew_test_result
Task 事件:
Section titled “Task 事件:”task_startedtask_completedtask_failedtask_evaluation
Tool Usage 事件:
Section titled “Tool Usage 事件:”tool_usage_startedtool_usage_finishedtool_usage_errortool_validate_input_errortool_selection_errortool_execution_error
LLM 事件:
Section titled “LLM 事件:”llm_call_startedllm_call_completedllm_call_failedllm_stream_chunk
LLM Guardrail 事件:
Section titled “LLM Guardrail 事件:”llm_guardrail_startedllm_guardrail_completed
Memory 事件:
Section titled “Memory 事件:”memory_query_startedmemory_query_completedmemory_query_failedmemory_save_startedmemory_save_completedmemory_save_failedmemory_retrieval_startedmemory_retrieval_completed
Knowledge 事件:
Section titled “Knowledge 事件:”knowledge_search_query_startedknowledge_search_query_completedknowledge_search_query_failedknowledge_query_startedknowledge_query_completedknowledge_query_failed
Reasoning 事件:
Section titled “Reasoning 事件:”agent_reasoning_startedagent_reasoning_completedagent_reasoning_failed
事件名称与内部事件总线一致。完整事件列表请查看 GitHub。
你也可以发出自己的自定义事件,它们会与系统事件一起通过 webhook stream 发送。