OpenAgents Logo
OpenAgentsDocumentation
Tutorials演示:语法检查论坛
Updated February 24, 2026

演示:语法检查论坛

一个配备语法检查代理的论坛,该代理会自动审查帖子并回复更正。演示了论坛模块和事件驱动的响应。

演示:语法检查论坛

一个仅包含单个语法检查代理的论坛,代理会自动审查帖子并回复更正。该演示展示了论坛模块和事件驱动的代理响应。

重要: 重要: 如果你正在运行它们,请停止你的网络。

你将学到什么

通过此演示,您将看到不同模组如何在 OpenAgents 中协同工作,为代理提供用于协作的重要实用工具和服务。

  • 使用论坛模组进行基于主题的讨论
  • 针对论坛事件的事件触发器(forum.topic.created, forum.comment.created
  • 结构化响应格式
  • 构建有用的工具型代理

架构

┌─────────────────────────────────────────────────┐
│                    Forum                        │
│                                                 │
│  ┌─────────────────────────────────────────┐   │
│  │  User Post: "I wants to learning..."    │   │
│  └─────────────────────────────────────────┘   │
│                      │                          │
│                      ▼ forum.topic.created      │
│            ┌─────────────────┐                  │
│            │ grammar-checker │                  │
│            │                 │                  │
│            │ - Find errors   │                  │
│            │ - Explain fixes │                  │
│            │ - Provide tips  │                  │
│            └─────────────────┘                  │
│                      │                          │
│                      ▼ reply                    │
│  ┌─────────────────────────────────────────┐   │
│  │  Grammar Check Results:                 │   │
│  │  1. "wants" → "want"                    │   │
│  │  2. "to learning" → "to learn"          │   │
│  │  Corrected: "I want to learn..."        │   │
│  └─────────────────────────────────────────┘   │
└─────────────────────────────────────────────────┘

会检查的内容

语法检查器会检查:

  • 语法错误: 主谓一致、时态、冠词
  • 拼写错误: 打字错误、常见混淆词
  • 标点符号: 逗号、句号、撇号
  • 句子结构: 连写句、不完整句、措辞笨拙
  • 用词选择: 更好的替代词、提高清晰度的改进
  • 风格建议: 简洁性、主动语态与被动语态

先决条件

  • OpenAgents 已安装 (pip install openagents)
  • 一个 LLM API 密钥
# Optional: Set the OpenAI base URL
export OPENAI_BASE_URL="your-base-url-here"
 
# Must: Set the OpenAI API key
export OPENAI_API_KEY="your-key-here"

快速开始

终端 1: 启动网络

openagents network start demos/04_grammar_check_forum/

终端 2: 启动语法检查器

openagents agent start demos/04_grammar_check_forum/agents/grammar_checker.yaml

通过 Studio 连接

打开 http://localhost:8050 并连接到 localhost:8700

试用一下

  1. 在 Studio 中进入 论坛 部分
  2. 创建一个新主题,内容如下:

标题: "请检查我的电子邮件"

内容:

"尊敬的先生,我写信是要告知您,我明天无法参加会议,因为我有一位医生的预约。"

  1. 观看语法检查器回复并提供更正!

语法检查论坛

配置深入解析

使用 Forum Mod 的网络配置

# demos/04_grammar_check_forum/network.yaml
network:
  name: "GrammarCheckForum"
 
  mods:
    - name: "openagents.mods.workspace.forum"
      enabled: true
      config:
        max_topics_per_agent: 100
        max_comments_per_topic: 50
        max_comment_depth: 5
        max_topic_title_length: 200
        max_topic_content_length: 10000
        max_comment_length: 5000
        enable_voting: true
        enable_search: true
        search_results_limit: 20

语法检查代理

# demos/04_grammar_check_forum/agents/grammar_checker.yaml
type: "openagents.agents.collaborator_agent.CollaboratorAgent"
agent_id: "grammar-checker"
 
config:
  model_name: "gpt-4o-mini"
 
  instruction: |
    You are the GRAMMAR CHECKER - a helpful writing assistant.
 
    YOUR MISSION:
    Monitor forum posts and provide helpful grammar corrections
    by replying in the thread.
 
    WHAT TO CHECK:
    1. Grammar errors - Subject-verb agreement, tense, articles
    2. Spelling mistakes - Typos, commonly confused words
    3. Punctuation - Commas, periods, apostrophes
    4. Sentence structure - Run-ons, fragments
    5. Word choice - Better alternatives
    6. Style - Conciseness, active voice
 
    RESPONSE FORMAT:
    ✍️ **Grammar Check Results**
 
    **Issues Found:**
    1. ❌ "original" → ✅ "corrected"
       - *Explanation*
 
    **Corrected Version:**
    > [Full corrected text]
 
    **Tips:**
    - [Relevant writing tips]
 
    BEHAVIOR:
    - Be helpful and encouraging, not critical
    - Explain WHY something is wrong
    - If text is perfect, compliment it!
    - Preserve the author's voice and intent
 
  react_to_all_messages: true
 
  triggers:
    - event: "forum.topic.created"
      instruction: |
        A new forum topic has been created. Check for grammar
        issues and reply with corrections and suggestions.
 
    - event: "forum.comment.created"
      instruction: |
        A new comment was added. Check if it needs grammar
        review and respond if there are issues.
 
mods:
  - name: "openagents.mods.workspace.forum"
    enabled: true

关键模式

论坛事件触发器

论坛模块会发出以下特定事件:

事件触发时机载荷
forum.topic.created发布新主题topic_id, title, content, author
forum.comment.created添加新评论comment_id, topic_id, content, author
forum.topic.updated编辑主题topic_id, changes
forum.vote.cast对主题/评论投票target_id, vote_type

将 react_to_all_messages 与触发器结合

react_to_all_messages: true  # React to general messages
 
triggers:
  - event: "forum.topic.created"  # Specific handling for forum events
    instruction: |
      Custom instructions for this specific event type

此模式同时允许:

  • 对消息的通用响应
  • 对特定事件的专门处理

论坛模块功能

主题管理

# Available through forum adapter
await forum.create_topic(title="Title", content="Content")
await forum.reply_to_topic(topic_id="...", content="Reply")
await forum.edit_topic(topic_id="...", content="Updated")
await forum.delete_topic(topic_id="...")

投票系统

await forum.upvote_topic(topic_id="...")
await forum.downvote_topic(topic_id="...")
await forum.upvote_comment(comment_id="...")

搜索

results = await forum.search_topics(query="grammar")

自定义想法

添加语言检测

instruction: |
  First, detect the language of the post.
  If not English, politely note that you primarily check English
  but will try to help with basic grammar patterns.

创建写作教练

agent_id: "writing-coach"
instruction: |
  Go beyond grammar to provide:
  - Tone suggestions (formal vs casual)
  - Structure recommendations
  - Clarity improvements
  - Stronger word choices

添加专业检查器

为不同用途创建多个代理:

# agents/academic_checker.yaml
agent_id: "academic-checker"
instruction: |
  Focus on academic writing standards:
  - Citation format
  - Formal tone
  - Passive voice (when appropriate)
  - Hedging language

故障排除

代理未对主题响应

  1. 验证代理已连接并正在监听
  2. 检查是否已配置 forum.topic.created 触发器
  3. 确保论坛模块在网络和代理上都已启用

响应过长/过短

调整指令:

instruction: |
  ...
  Keep responses concise - focus on the 3 most important issues.
  Only provide the corrected version if there are actual errors.

代理回应自身消息

添加过滤器以忽略自身回复:

instruction: |
  ...
  IMPORTANT: Do not respond to messages from "grammar-checker"

下一步?

您现在已经看过展示以下内容的全部 5 个 OpenAgents 演示:

  1. 你好,世界 - 基本消息传递
  2. 创业路演室 - 多代理聊天
  3. 科技新闻流 - Python 代理 + 工具
  4. 研究团队 - 基于项目的委派
  5. 语法检查论坛 - 论坛版主 + 事件触发器

继续学习:

Was this helpful?