agent

The core classes that let a language-model agent decide what to do and run tools in a loop. The loop plans an action, runs a tool, reads the result, and repeats until it has an answer or reaches a limit.

In plain words
What is it for?
Use it to build single-step or multi-step agents, connect them to tools, cap iterations or runtime, and control what happens when execution stops early.
Why use it?
It provides the runtime structure needed to connect model decisions with real tool calls. Limits and error handling help prevent endless runs and deal with badly formatted model output.

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/agent
Clone the repo
git clone --depth 1 https://github.com/xt765/LangChain-Chinese-Comment
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 765 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.00765
Opus 5 $0.00000 $0.00382
Sonnet 5 $0.00000 $0.00153
Haiku 4.5 $0.00000 $0.00076

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

Security

Grade A, and why

agent 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 3d 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/agent.md · 59 lines

What it actually says

libs\langchain\langchain_classic\agents\agent.py

此文档提供了 libs\langchain\langchain_classic\agents\agent.py 文件的详细中文注释。该模块定义了 LangChain 经典代理架构的基础抽象类和核心执行器 AgentExecutor

功能描述

该模块是代理系统的核心逻辑所在,负责定义代理如何决策(Planning)以及如何执行动作(Execution)。它支持单动作(Single Action)和多动作(Multi Action)代理,并提供了一个强大的执行环境。

核心类层级

1. 基础抽象类

  • BaseSingleActionAgent: 单操作代理的基类。每次决策产生一个 AgentActionAgentFinish
  • BaseMultiActionAgent: 多操作代理的基类。每次决策可以产生多个 AgentAction
  • LLMSingleActionAgent: 使用 LLMChain 实现的单操作代理。

2. 核心执行器 AgentExecutor

AgentExecutor 是驱动代理运行的容器。它负责管理“思考-行动-观察”循环:

  1. Plan: 调用代理决定下一步(Action 或 Finish)。
  2. Execute: 如果是 Action,则执行对应的工具。
  3. Observe: 将工具输出作为 Observation 反馈给代理。
  4. Repeat: 重复循环,直到代理返回 Finish 或触发限制。
关键参数表
参数 类型 描述
agent BaseSingleActionAgent | BaseMultiActionAgent | Runnable 负责决策的核心代理逻辑。
tools Sequence[BaseTool] 代理可以访问并调用的工具集合。
max_iterations int 最大循环步数(默认 15),防止代理进入死循环。
max_execution_time float 最大运行时间限制。
early_stopping_method str 强制停止时的行为:force (默认) 或 generate (尝试总结已有信息)。
handle_parsing_errors bool | str | Callable 解析错误处理逻辑。为 True 时会将错误反馈给 LLM 修复。
return_intermediate_steps bool 是否在结果中包含所有中间思考和工具调用过程。

3. Runnable 包装器

  • RunnableAgent: 将 LCEL 中的 Runnable 对象适配为单动作代理接口。
  • RunnableMultiActionAgent: 将 Runnable 适配为多动作代理接口。

核心方法

Agent.plan(intermediate_steps, **kwargs)

这是代理最核心的方法。

  • intermediate_steps: 包含之前的动作和对应的观察结果。
  • 返回值: 下一个要执行的动作或最终答案。

AgentExecutor.from_agent_and_tools(...)

用于快速创建执行器的类方法,会自动处理工具验证和配置。

弃用说明

Agent 类已被标记为弃用,并计划在 1.0 版本移除。建议开发者:

  1. 使用 create_tool_calling_agent 等工厂函数。
  2. 将复杂的代理逻辑迁移到 LangGraph,以获得更好的控制流和持久化支持。
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. 3d ago First seen · 59 lines · 0 tokens per session scan A aaa7ed9cff47

Subscribe to this mod's changes

agent 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 765 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

build-error-resolver

빌드 실패·타입 에러·컴파일 오류·import 에러·의존성 이슈를 최소 변경으로 그린 복구. 리팩토링·아키텍처 변경 절대 금지. Use proactively when CI/빌드가 빨간불이거나, 터미널에 타입 에러·컴파일 에러가 표시될 때 즉시. 런타임 로직 버그는 systematic-debugger, 아키텍처 변경은 architect 사용.

sangrokjung/claude-forge · 106 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

planner

Strategic planning agent — read-only exploration before implementation. Use to decompose tasks, analyze codebases, and produce a detailed plan. Never modifies files.

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

devops

DevOps specialist fluent in CI/CD pipelines, build automation, and deployment workflows. Thinks in reliability, security, and developer experience. Designs GitHub Actions, configures build systems, manages secrets. Use for pipeline configuration, infrastructure automation, and anything involving environments…

rjmurillo/ai-agents · 63 tokens

ticket-gate

Ticket readiness gate for actual-mcp-server (forge-kit ticket-gate v6). Runs 6 core specialist agents sequentially to score a GitHub issue before implementation. Each agent scores 1-10; ALL must score 10 to pass. An agent whose domain the ticket does not touch auto-scores 10 (N/A). Extra specialists are added by…

agigante80/actual-mcp-server · 228 tokens