Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add agents/xt765/langchain-chinese-comment/openai_functionsgit clone --depth 1 https://github.com/xt765/LangChain-Chinese-CommentWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/agents/xt765/langchain-chinese-comment/openai_functions)<a href="https://agentmods.dev/agents/xt765/langchain-chinese-comment/openai_functions"><img src="https://agentmods.dev/badge/agents/xt765/langchain-chinese-comment/openai_functions.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.00837 |
| Opus 5 | $0.00000 | $0.00418 |
| Sonnet 5 | $0.00000 | $0.00167 |
| Haiku 4.5 | $0.00000 | $0.00084 |
Grade A, and why
openai_functions scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 88 lines — stays where its author put it; the contents beside it link to each section on GitHub.
OpenAI Functions Agent
OpenAIFunctionsAgent 是一种专门为支持 Function Calling(函数调用)能力的模型(如 OpenAI GPT-4)设计的 Agent。与依赖 Prompt 解析的 ReAct Agent 不同,它直接利用模型的 API 能力来决定调用哪个工具。
核心机制:Function Calling
该 Agent 不再通过 "Thought/Action" 的文本解析来工作,而是:
- 定义函数: 将工具(Tools)转换为 JSON Schema 格式的函数定义。
- 发送请求: 将用户输入和函数定义发送给模型。
- 模型响应: 模型直接返回一个结构化的函数调用请求(Function Call),包括函数名和参数。
- 执行与反馈: 执行对应工具,并将结果作为 "Function Message" 反馈给模型。
核心组件
1. OpenAIFunctionsAgent
经典实现类,封装了与 OpenAI 函数调用接口交互的逻辑。
- functions: 动态生成的函数定义列表。
- agent_scratchpad: 使用
MessagesPlaceholder存储中间步骤,并转换为 OpenAI 特有的消息格式。
2. create_openai_functions_agent
基于 LCEL 的现代工厂函数。它构建了一个 Runnable 序列,内部使用 llm.bind 来绑定函数。
执行逻辑 (Verbatim Snippet)
格式化中间步骤 (format_to_openai_function_messages)
Agent 需要将之前的行动和观察结果转换为模型理解的消息历史:
def format_to_openai_function_messages(
intermediate_steps: list[tuple[AgentAction, str]],
) -> list[BaseMessage]:
messages = []
for action, observation in intermediate_steps:
# 将 AgentAction 转换为 AIMessage (含 function_call)
messages.append(AIMessage(content="", additional_kwargs={"function_call": ...}))
# 将观察结果转换为 FunctionMessage
messages.append(FunctionMessage(name=action.tool, content=observation))
return messages
LCEL 构造逻辑 (create_openai_functions_agent)
llm_with_tools = llm.bind(functions=[convert_to_openai_function(t) for t in tools])
agent = (
RunnablePassthrough.assign(
agent_scratchpad=lambda x: format_to_openai_function_messages(
x["intermediate_steps"],
),
)
| prompt
| llm_with_tools
| OpenAIFunctionsAgentOutputParser()
)
迁移指南 (Tool Calling)
虽然 OpenAI Functions Agent 已经很高效,但现代 LangChain 推荐使用更通用的 Tool Calling Agent,它可以同时支持 OpenAI、Anthropic 和 Google 等多种模型。
经典方式 (initialize_agent)
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
现代方式 (create_tool_calling_agent)
from langchain.agents import create_tool_calling_agent
from langchain import hub
prompt = hub.pull("hwchase17/openai-tools-agent")
# 这里的 model 可以是任何支持 Tool Calling 的模型
agent = create_tool_calling_agent(model, tools, prompt)
# 配合 AgentExecutor 使用
from langchain.agents import AgentExecutor
agent_executor = AgentExecutor(agent=agent, tools=tools)
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 5d ago First seen · 88 lines · 0 tokens per session scan A 22406306744e
openai_functions is an agent published in the GitHub repository xt765/LangChain-Chinese-Comment (20 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 837 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
memory-keeper
Updates .claude/memory.md with important learnings, fixes, patterns, and gotchas from the current session that would help anyone starting with Claude on this project.
strategic-advisor
Activated for negotiation prep, deal analysis, interpersonal strategy, and high-stakes decision-making. Combines game theory with psychological awareness.
integration-reviewer
Runtime integration validator — read-only. Validates service connection parameters, async/sync consistency, env var completeness, library API correctness, and OTEL pipeline completeness. Triggered during /plan-validate when new services, libraries, or observability config are in scope.
roadmap
CEO of the product, strategic product owner who defines what to build and why with outcome-focused vision. Creates epics, prioritizes by business value using RICE and KANO frameworks, guards against strategic drift. Use when you need direction, outcomes over outputs, sequencing by dependencies, or user-value…
onboard-guide
Onboarding assistant that provides ongoing personalized guidance after initial /onboard. Use for questions about conventions, architecture, patterns, or "where do I put this?" — answers are tailored to the engineer's background.
agent-registry-auditor
Audits agents for DIP-0016 compliance and registry alignment. Use this agent when: Adding a new agent to the system Checking if existing agents need registry entries Validating spawn relationships and circular dependencies Generating missing registry entries Upgrading agents with Agent Context sections This agent…