纯 Python
def word_count(text: str) -> int:
"""Count the number of words in a text.
Args:
text: Input text.
Returns:
The word count.
"""
return len(text.split())
| 操作 | 实现 |
|---|---|
| 固定算法、数据转换、计数、读写文件、数学 | 普通 Python 帮助函数或 Agent 方法;不用 llm(),没有 runtime 参数,使用标准 Google 风格 docstring |
| 自然语言生成、分类、推理 | 显式的 agent() 或 self(...) 请求 |
在会话 DAG 中
from openprogram import Agent
class TextAgent(Agent):
def word_count(self, text: str) -> int:
"""Count words."""
return len(text.split())
| 函数 | 记录 |
|---|---|
| 启动一次执行的 Agent 方法 | 会记录;不需要模型请求或工具注册 |
| 嵌套在该执行内、或托管 Program 源码内的帮助函数 | 在当前调用作用域运行,没有自己的节点 |
| 任意宿主函数 | 不捕获 |
是否确定性不决定是否记录。只有要让模型调用时才设 tool=True。
Last updated · 2026-11-25