openai_functions

openai_functions is an agent for coding agents from xt765/LangChain-Chinese-Comment. It costs 0 tokens per session (837 once invoked), scanned A, original, MIT.

An agent for models that support function calling, where the model returns a structured request naming a tool and its parameters.

In plain words
What is it for?
Use it to connect OpenAI function-calling models with tools, send tool results back as messages, and continue the agent’s work.
Why use it?
It avoids relying on the model to follow and the program to parse a free-form Thought/Action text format.

Agent

Install

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.

agentmods
npx agentmods add agents/xt765/langchain-chinese-comment/openai_functions
Clone the repo
git clone --depth 1 https://github.com/xt765/LangChain-Chinese-Comment

Wrote 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.

agentmods badge for openai_functions

README.md
[![agentmods](https://agentmods.dev/badge/agents/xt765/langchain-chinese-comment/openai_functions.svg)](https://agentmods.dev/agents/xt765/langchain-chinese-comment/openai_functions)
Your own site
<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>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 837 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 5d ago against content hash 22406306744e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

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.

code_comment/libs/langchain/langchain_classic/agents/openai_functions.md · 88 lines

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" 的文本解析来工作,而是:

  1. 定义函数: 将工具(Tools)转换为 JSON Schema 格式的函数定义。
  2. 发送请求: 将用户输入和函数定义发送给模型。
  3. 模型响应: 模型直接返回一个结构化的函数调用请求(Function Call),包括函数名和参数。
  4. 执行与反馈: 执行对应工具,并将结果作为 "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)

Read the full file on GitHub · 88 lines

Changes

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.

  1. 5d ago First seen · 88 lines · 0 tokens per session scan A 22406306744e

Subscribe to this mod's changes

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.

Related

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.

tinyhumansai/openhuman · 38 tokens

strategic-advisor

Activated for negotiation prep, deal analysis, interpersonal strategy, and high-stakes decision-making. Combines game theory with psychological awareness.

winstonkoh87/Athena-Public · 31 tokens

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.

FlorianBruniaux/claude-code-ultimate-guide · 57 tokens

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…

rjmurillo/ai-agents · 64 tokens

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.

smicolon/ai-kit · 46 tokens

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…

datacore-one/datacore · 84 tokens