🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
RoundRobinGroupChat.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "BaseGroupChat.hpp"
25#include "AstAI/ChatAgent.hpp"
26#include "AstAI/ChatMessages.hpp"
27#include "AstAI/TerminationCondition.hpp"
28#include <memory>
29
30AST_NAMESPACE_BEGIN
31
37class TerminationCondition;
38
41class AST_AI_API RoundRobinGroupChat : public BaseGroupChat
42{
43public:
44 RoundRobinGroupChat() = default;
45 ~RoundRobinGroupChat() = default;
46
47 // —— Agent管理 ——
48
50 void addAgent(ChatAgent* agent);
51
53 const std::vector<ChatAgent*>& agents() const { return agents_; }
54
55 // —— 终止条件 ——
56
58 void setTerminationCondition(std::unique_ptr<TerminationCondition> condition);
59
61 TerminationCondition* terminationCondition() const { return terminationCondition_.get(); }
62
63 // —— 消息历史 ——
64
66 ChatMessages& messages() { return messages_; }
67
69 const ChatMessages& messages() const { return messages_; }
70
71 // —— 配置 ——
72
74 void setMaxRounds(int maxRounds) { maxRounds_ = maxRounds; }
75
77 int maxRounds() const { return maxRounds_; }
78
79 // —— 执行 ——
80
81 errc_t run(const ChatMessage& message, ChatMessage& response) override;
82
83private:
84 std::vector<ChatAgent*> agents_;
85 ChatMessages messages_;
86 std::unique_ptr<TerminationCondition> terminationCondition_;
87 int maxRounds_ = 100;
88};
89
92AST_NAMESPACE_END
定义 BaseGroupChat.hpp:35
virtual errc_t run(const ChatMessage &message, ChatMessage &response)=0
运行一次聊天,返回最终的响应消息,过程中会处理工具调用、多个Agent交互等逻辑
聊天智能体抽象基类
定义 ChatAgent.hpp:40
聊天消息
定义 ChatMessage.hpp:52
聊天消息集合
定义 ChatMessages.hpp:39
轮询式群聊
定义 RoundRobinGroupChat.hpp:42
void setMaxRounds(int maxRounds)
设置最大轮次数(默认100,防止无限循环)
定义 RoundRobinGroupChat.hpp:74
const std::vector< ChatAgent * > & agents() const
获取所有Agent
定义 RoundRobinGroupChat.hpp:53
int maxRounds() const
获取最大轮次数
定义 RoundRobinGroupChat.hpp:77
const ChatMessages & messages() const
获取消息历史(只读)
定义 RoundRobinGroupChat.hpp:69
TerminationCondition * terminationCondition() const
获取终止条件
定义 RoundRobinGroupChat.hpp:61
ChatMessages & messages()
获取消息历史(可修改)
定义 RoundRobinGroupChat.hpp:66
终止条件
定义 TerminationCondition.hpp:37