Loading...
Loading...
Compare original and translation side by side
airflow-ai-sdkapache-airflow-providers-common-aiCRITICAL: The new provider requires Airflow 3.0+ and pydantic-ai-slim >= 1.34.0. The API surface has changed: LLM configuration moves from code (model strings/objects) to Airflow connections (type). There is nopydanticaiin the new provider.@task.embed
airflow-ai-sdkapache-airflow-providers-common-ai重要提示:新提供者要求Airflow 3.0及以上版本以及pydantic-ai-slim >= 1.34.0。API层面已发生变更:LLM配置从代码中的模型字符串/对象转移至Airflow连接(类型)。新提供者中不再包含pydanticai装饰器。@task.embed
airflow_ai_sdk|airflow-ai-sdk|ai_sdk|@task\.llm|@task\.agent|@task\.llm_branch|@task\.embedairflow-ai-sdkairflow_ai_sdk@task.llm@task.agent@task.llm_branch@task.embed"gpt-5"OpenAIModel(...)airflow_ai_sdk.BaseModeloutput_typeairflow_ai_sdk|airflow-ai-sdk|ai_sdk|@task\.llm|@task\.agent|@task\.llm_branch|@task\.embedairflow-ai-sdkairflow_ai_sdk@task.llm@task.agent@task.llm_branch@task.embed"gpt-5"OpenAIModel(...)output_typeairflow_ai_sdk.BaseModelairflow-ai-sdk[openai]airflow-ai-sdk[openai]
**Add:**
Use the latest available 0.x version unless the user has pinned a specific one. Available extras match the LLM provider: `[openai]`, `[anthropic]`, `[google]`, `[bedrock]`, `[groq]`, `[mistral]`, `[mcp]`.
Keep `sentence-transformers` and `torch` if the project uses embeddings (they now run via plain `@task` instead of `@task.embed`).
---
**添加以下内容:**
除非用户指定了特定版本,否则请使用最新的0.x版本。可用的扩展包与LLM提供者对应:`[openai]`、`[anthropic]`、`[google]`、`[bedrock]`、`[groq]`、`[mistral]`、`[mcp]`。
如果项目使用嵌入功能,请保留`sentence-transformers`和`torch`(它们现在通过普通`@task`运行,而非`@task.embed`)。
---pydanticaipydanticai_defaultpydanticaipydanticai_defaultAIRFLOW_CONN_PYDANTICAI_DEFAULT='{
"conn_type": "pydanticai",
"password": "<api-key>",
"extra": {
"model": "<provider>:<model-name>"
}
}'AIRFLOW_CONN_PYDANTICAI_DEFAULT='{
"conn_type": "pydanticai",
"password": "<api-key>",
"extra": {
"model": "<provider>:<model-name>"
}
}'provider:model| Provider | Example model value |
|---|---|
| OpenAI | |
| Anthropic | |
| |
| Groq | |
| Mistral | |
| Bedrock | |
provider:model| 提供者 | 模型值示例 |
|---|---|
| OpenAI | |
| Anthropic | |
| |
| Groq | |
| Mistral | |
| Bedrock | |
hostAIRFLOW_CONN_PYDANTICAI_CORTEX='{
"conn_type": "pydanticai",
"password": "<api-key>",
"host": "https://my-endpoint.com/v1",
"extra": {
"model": "openai:<model-name>"
}
}'openai:hostAIRFLOW_CONN_PYDANTICAI_CORTEX='{
"conn_type": "pydanticai",
"password": "<api-key>",
"host": "https://my-endpoint.com/v1",
"extra": {
"model": "openai:<model-name>"
}
}'openai:AIRFLOW_CONN_PYDANTICAI_DEFAULTpydanticai_defaultAIRFLOW_CONN_PYDANTICAI_CORTEXpydanticai_cortexAIRFLOW_CONN_PYDANTICAI_DEFAULTpydanticai_defaultAIRFLOW_CONN_PYDANTICAI_CORTEXpydanticai_cortexmodel_idmodelmodel_idmodelundefinedundefined
**Parameter mapping:**
| airflow-ai-sdk | common-ai provider | Notes |
|----------------|-------------------|-------|
| `model="gpt-5"` | `llm_conn_id="pydanticai_default"` | Model specified in connection |
| `model=OpenAIModel(...)` | `llm_conn_id="pydanticai_default"` | Model + endpoint in connection |
| `system_prompt="..."` | `system_prompt="..."` | Unchanged |
| `output_type=MyModel` | `output_type=MyModel` | Unchanged |
| `result_type=MyModel` | `output_type=MyModel` | `result_type` was already deprecated |
| (not available) | `model_id="openai:gpt-5"` | Override connection's model |
| (not available) | `require_approval=True` | Built-in HITL review |
| (not available) | `agent_params={...}` | Extra kwargs for pydantic-ai Agent |
**参数映射:**
| airflow-ai-sdk | common-ai提供者 | 说明 |
|----------------|-------------------|-------|
| `model="gpt-5"` | `llm_conn_id="pydanticai_default"` | 模型在连接中指定 |
| `model=OpenAIModel(...)` | `llm_conn_id="pydanticai_default"` | 模型与端点在连接中配置 |
| `system_prompt="..."` | `system_prompt="..."` | 保持不变 |
| `output_type=MyModel` | `output_type=MyModel` | 保持不变 |
| `result_type=MyModel` | `output_type=MyModel` | `result_type`已被弃用 |
| (无此参数) | `model_id="openai:gpt-5"` | 覆盖连接中的模型 |
| (无此参数) | `require_approval=True` | 内置人工审核功能 |
| (无此参数) | `agent_params={...}` | 传递给pydantic-ai Agent的额外参数 |undefinedundefined
Only change: `model=` becomes `llm_conn_id=`.
仅需修改:将`model=`替换为`llm_conn_id=`。undefinedundefined
**Parameter mapping:**
| airflow-ai-sdk | common-ai provider | Notes |
|----------------|-------------------|-------|
| `agent=Agent(model, ...)` | `llm_conn_id="..."` | Model from connection |
| Agent's `system_prompt` | `system_prompt="..."` | Now a decorator param |
| Agent's `tools=[...]` | `agent_params={"tools": [...]}` | Tools via agent_params dict |
| Agent's `output_type` | `output_type=MyModel` | Now a decorator param |
| (not available) | `toolsets=[...]` | pydantic-ai 1.x Toolset objects |
| (not available) | `durable=True` | Step-level caching |
| (not available) | `enable_hitl_review=True` | Iterative human review loop |
**Key insight:** Everything that was configured on the `Agent()` constructor now goes into either a top-level decorator parameter or `agent_params`. The `agent_params` dict is passed directly to pydantic-ai's `Agent` constructor.
**参数映射:**
| airflow-ai-sdk | common-ai提供者 | 说明 |
|----------------|-------------------|-------|
| `agent=Agent(model, ...)` | `llm_conn_id="..."` | 模型来自连接配置 |
| Agent的`system_prompt` | `system_prompt="..."` | 现在是装饰器参数 |
| Agent的`tools=[...]` | `agent_params={"tools": [...]}` | 通过agent_params字典配置工具 |
| Agent的`output_type` | `output_type=MyModel` | 现在是装饰器参数 |
| (无此参数) | `toolsets=[...]` | pydantic-ai 1.x Toolset对象 |
| (无此参数) | `durable=True` | 步骤级缓存 |
| (无此参数) | `enable_hitl_review=True` | 迭代式人工审核循环 |
**核心要点:** 之前在`Agent()`构造函数中配置的所有内容,现在都要放在顶层装饰器参数或`agent_params`中。`agent_params`字典会直接传递给pydantic-ai的`Agent`构造函数。@taskundefined@taskundefined
Note: The model is loaded on each task execution. For small workloads this is fine. For large batches, consider embedding all texts in a single task instead of using `.expand()`.
---
注意:模型会在每次任务执行时加载。对于小型工作负载,此方式可行。对于大规模批量任务,建议在单个任务中完成所有文本嵌入,而非使用`.expand()`。
---| Old import | New import |
|---|---|
| Remove entirely |
| |
| |
| |
| Remove if Agent was only used for |
| Remove (model config in connection now) |
@task.llm@task.agent@task.llm_branchfrom airflow.sdk import taskpydantic_aiBinaryContentpydantic-ai-slim>=1.34.0| 旧导入语句 | 新导入语句 |
|---|---|
| 完全移除 |
| |
| |
| |
| 若Agent仅用于 |
| 移除(模型配置现在在连接中) |
@task.llm@task.agent@task.llm_branchfrom airflow.sdk import taskpydantic_aiBinaryContentpydantic-ai-slim>=1.34.0pydanticai_default:
conn_type: pydanticai
password: <api-key>
extra:
model: "openai:gpt-5"pydanticai_cortex:
conn_type: pydanticai
password: <api-key>
host: https://my-endpoint.com/v1
extra:
model: "openai:llama3.1-8b"pydanticai_default:
conn_type: pydanticai
password: <api-key>
extra:
model: "openai:gpt-5"pydanticai_cortex:
conn_type: pydanticai
password: <api-key>
host: https://my-endpoint.com/v1
extra:
model: "openai:llama3.1-8b"pydanticaiOPENAI_API_KEY|OPENAI_BASE_URL|ANTHROPIC_API_KEY|GOOGLE_API_KEYOPENAI_API_KEYOPENAI_BASE_URL.envAIRFLOW_CONN_*pydanticaiOPENAI_API_KEY|OPENAI_BASE_URL|ANTHROPIC_API_KEY|GOOGLE_API_KEYOPENAI_API_KEYOPENAI_BASE_URL.envAIRFLOW_CONN_*airflow_ai_sdk|airflow-ai-sdk|ai_sdk\.BaseModel|from pydantic_ai import Agent|from pydantic_ai.modelsairflow_ai_sdkAgent()@task.agentmodel=llm_conn_id=@task.embed@taskpydanticai.envrequirements.txtapache-airflow-providers-common-ai[...]airflow-ai-sdk[...]airflow_ai_sdk|airflow-ai-sdk|ai_sdk\.BaseModel|from pydantic_ai import Agent|from pydantic_ai.modelsairflow_ai_sdk@task.agentAgent()model=llm_conn_id=@task.embed@task.envpydanticairequirements.txtapache-airflow-providers-common-ai[...]airflow-ai-sdk[...]| Feature | Parameter | Description |
|---|---|---|
| HITL approval | | Pause for human review before returning |
| HITL review loop | | Iterative review with regeneration |
| Durable execution | | Step-level caching for resilience |
| Tool logging | | INFO-level tool call logs (default: on) |
| Model override | | Override connection's model per-task |
| File analysis | | Analyze files/images via ObjectStoragePath |
| NL-to-SQL | | Generate SQL from natural language |
| 特性 | 参数 | 描述 |
|---|---|---|
| 人工审核 | | 返回结果前暂停以进行人工审核 |
| 人工审核循环 | | 带重新生成功能的迭代式审核 |
| 持久化执行 | | 用于恢复能力的步骤级缓存 |
| 工具日志 | | INFO级工具调用日志(默认开启) |
| 模型覆盖 | | 按任务覆盖连接中的模型 |
| 文件分析 | | 通过ObjectStoragePath分析文件/图片 |
| 自然语言转SQL | | 从自然语言生成SQL |