13 Go Eino AI应用开发实战 | 简历分析 Agent

73 阅读4分钟

声明:本AI应用开发系列教程首发在同名公众号:王中阳,未经授权禁止转载。

image.png

简历分析 Agent 是 Go-Eino Interview Agent 平台中的一个先进 AI 组件,能够自动提取并分析上传的 PDF 简历中的候选人信息。这个智能 Agent 作为个性化面试准备的基础,通过将原始简历数据转化为结构化洞察和面试建议来发挥作用。

架构概览

简历分析 Agent 采用多层架构运行,结合了文档解析、AI 分析和数据持久化:

核心组件

Agent 实现

简历解析 Agent 在 backend/chatApp/agent/resume/resume.go 中使用 Eino 框架的 Agent 模式实现:

func NewResumeParserAgent(userId uint) (adk.Agent, error) {
    // 创建一个专用 Agent,具备:
    // - OpenAI 聊天模型集成
    // - PDF 解析工具能力
    // - 结构化提取指令
    // - 20 次迭代限制以处理复杂解析
}

该 Agent 配置了全面的指令,指导其进行系统性分析:

  1. PDF 解析:使用 pdf_to_text 工具提取原始文本内容
  2. 信息提取:识别关键类别,包括基本信息、教育背景、工作经验、技术栈、项目、技能和认证
  3. 背景分析:评估候选人的技术方向、行业经验和职业轨迹
  4. 面试建议:生成重点领域、建议问题和难度评估

PDF 处理工具

核心 PDF 解析功能在 backend/chatApp/tool/pdfParserTool.go 中实现。该工具使用 Eino 的 PDF 解析器组件将 PDF 文档转换为结构化文本:

type PDFToTextRequest struct {
    FilePath string `json:"file_path"`
    ToPages  bool   `json:"to_pages"`
}
 
type PDFToTextResult struct {
    Success    bool         `json:"success"`
    Content    string       `json:"content,omitempty"`
    Pages      []PDFPageText `json:"pages,omitempty"`
    TotalPages int          `json:"total_pages"`
    ErrorMsg   string       `json:"error_msg,omitempty"`
}

PDF 解析器仅支持基于文本的 PDF(不支持扫描文档或加密文件),并根据 ToPages 参数提供分页和合并文本输出选项。

服务层集成

backend/chatApp/agent/service/resume_service.go 中的服务层协调整个简历处理工作流:

func ParseResumeAndSave(ctx context.Context, userId uint, resumeFilePath string, fileSize int64) (uint64, *ResumeParseResult, error) {
    // 1. 创建简历解析 Agent
    // 2. 执行解析,超时时间为 120 秒
    // 3. 验证解析结果
    // 4. 将结构化数据保存到数据库
}

数据结构

Agent 输出一个由 ResumeParseResult 类型定义的综合 JSON 结构:

type ResumeParseResult struct {
    BasicInfo struct {
        Name      string `json:"name"`
        WorkYears string `json:"work_years"`
        Contact   string `json:"contact"`
    } `json:"basic_info"`
    Education []struct {
        School         string `json:"school"`
        Major          string `json:"major"`
        Degree         string `json:"degree"`
        GraduationYear string `json:"graduation_year"`
    } `json:"education"`
    WorkExperience []struct {
        Company          string `json:"company"`
        Position         string `json:"position"`
        Duration         string `json:"duration"`
        Responsibilities string `json:"responsibilities"`
    } `json:"work_experience"`
    TechStack                   []string `json:"tech_stack"`
    Projects                    []interface{} `json:"projects"`
    Skills                      []string `json:"skills"`
    Certifications              []string `json:"certifications"`
    Strengths                   string   `json:"strengths"`
    PotentialWeaknesses         string   `json:"potential_weaknesses"`
    RecommendedDifficulty       string   `json:"recommended_difficulty"`
    InterviewFocusAreas         []string `json:"interview_focus_areas"`
    SuggestedQuestionDirections []string `json:"suggested_questions_directions"`
}

数据库持久化

解析后的简历数据存储在 resume 表中,使用 backend/internal/model/resume.go 中定义的模型:

type Resume struct {
    ID        uint64    `json:"id" gorm:"primaryKey;autoIncrement"`
    UserID    uint      `json:"user_id" gorm:"index;not null"`
    Content   string    `json:"content" gorm:"type:longtext;not null"`
    FileName  string    `json:"file_name" gorm:"size:255"`
    FileSize  int64     `json:"file_size"`
    FileType  string    `json:"file_type" gorm:"size:50"`
    IsDefault int       `json:"is_default" gorm:"default:0"`
    Deleted   int       `json:"deleted" gorm:"default:0;index"`
    CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime:milli"`
    UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime:milli"`
}

Content 字段存储完整的 JSON 解析结果,无需重新处理原始 PDF 文件即可快速检索和分析。

错误处理和验证

系统实现了强大的错误处理和验证机制:

  1. 超时保护:120 秒超时防止无限期处理
  2. 结果验证:确保解析数据包含实际内容,而非空字段
  3. JSON 提取:处理 AI 响应中 JSON 周围包含额外文本的情况
  4. 文件验证:验证 PDF 可访问性和格式兼容性

集成点

简历分析 Agent 与多个系统组件集成:

  • 文件上传系统:通过上传端点接收 PDF 文件
  • 用户管理:将解析的简历与用户账户关联
  • 面试生成:为问题生成 Agent 提供结构化数据
  • 数据库层:使用 GORM ORM 持久化结果,具备适当索引

性能考虑

  • 处理时间:典型的简历解析在 30-60 秒内完成
  • 内存使用:通过流式 PDF 解析实现高效文本处理
  • 并发处理:支持多个同时进行的简历分析
  • 存储优化:数据库中的 JSON 压缩减少存储开销

简历分析 Agent 是面试准备流水线中的关键组件,将静态简历文档转化为动态、可操作的洞察,为个性化面试体验提供动力。

声明:本AI应用开发系列教程首发在同名公众号:王中阳,未经授权禁止转载。