Communitygithub.com

cmcoffee/gohort

一个用 Go 编写的模块化 Agent 框架,用于构建具备 Web 仪表盘、工具执行和多提供商支持的 LLM 驱动应用程序。应用通过 init() 自动注册,框架在启动时自动发现能力——无需配置、无需框架修改。

gohort 是什么?

cmcoffee/gohort 是一个用 Go 语言编写的模块化智能体框架,旨在简化 LLM 驱动应用的构建过程。它支持多模型提供商(如 OpenAI、Anthropic 等),并提供内置 Web 仪表盘、工具执行和会话管理功能。该框架的核心创新在于其自动注册机制:应用模块通过 init() 函数自注册,框架在启动时自动发现所有能力,无需手动配置或修改框架代码。这类似于 Go 的插件架构,但更加轻量和自动化。gohort 适用于需要快速集成 LLM 能力、构建聊天机器人、Code Agent 或自动化工作流的开发者。它支持多种平台(如 Claude Code、Cursor 等),并且通过 Request/Response 模型实现工具调用与用户交互的无缝衔接。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add cmcoffee/gohort

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

gohort 是做什么的?

一个用 Go 编写的模块化 Agent 框架,用于构建具备 Web 仪表盘、工具执行和多提供商支持的 LLM 驱动应用程序。应用通过 init() 自动注册,框架在启动时自动发现能力——无需配置、无需框架修改。

特点

  • 模块化架构:每个应用是一个独立包,通过 init() 注册自己
  • 多提供商支持:支持 OpenAI、Anthropic 等 LLM 提供商
  • Web 仪表盘:内置仪表盘用于管理和监控 Agent
  • 工具执行:Agent 可以调用外部工具和 API
  • 会话管理:自动管理会话状态和历史
  • 无需配置:无需配置文件或手动注册

快速开始

package main

import (
    "context"
    "fmt"
    "github.com/cmcoffee/gohort"
)

func main() {
    // 初始化框架
    app := gohort.New()
    
    // 启动应用
    if err := app.Run(context.Background()); err != nil {
        fmt.Println("错误:", err)
    }
}

应用注册

package myapp

import (
    "github.com/cmcoffee/gohort"
    "github.com/cmcoffee/gohort/tool"
)

func init() {
    gohort.Register("myapp", &MyApp{})
}

type MyApp struct{}

func (m *MyApp) Execute(ctx context.Context, req *gohort.Request) (*gohort.Response, error) {
    // 处理请求
    return &gohort.Response{
        Text: "你好世界!",
    }, nil
}

工具定义

type GreetTool struct{}

func (g *GreetTool) Name() string { return "greet" }

func (g *GreetTool) Description() string { return "向用户打招呼" }

func (g *GreetTool) Execute(ctx context.Context, params map[string]interface{}) (string, error) {
    name, _ := params["name"].(string)
    return fmt.Sprintf("你好,%s!", name), nil
}

配置环境变量

  • OPENAI_API_KEY:OpenAI API 密钥
  • ANTHROPIC_API_KEY:Anthropic API 密钥
  • GOHORT_PORT:Web 仪表盘端口(默认 8080)
  • GOHORT_LOG_LEVEL:日志级别(debug, info, warn, error)

高级用法

中间件

func LoggingMiddleware(next gohort.Handler) gohort.Handler {
    return gohort.HandlerFunc(func(ctx context.Context, req *gohort.Request) (*gohort.Response, error) {
        fmt.Println("请求:", req.Text)
        resp, err := next.Handle(ctx, req)
        if err != nil {
            fmt.Println("错误:", err)
        }
        return resp, err
    })
}

自定义仪表盘

框架提供默认仪表盘,但您可以覆盖 UI 组件以匹配您的品牌。

支持平台

  • Claude Code:完全支持通过工具注册
  • Cursor:通过 HTTP API 集成
  • Codex CLI:支持通过标准输出/输入接口

许可证

MIT

相关技能