🤖 代理¶
代理由 🧩 组件 组成,负责执行管道和一些附加逻辑。所有代理的基类是 BaseAgent
,它包含收集组件和执行协议所需的逻辑。
重要方法¶
BaseAgent
提供了任何代理正常工作所需的两个抽象方法:1. propose_action
:此方法负责根据代理的当前状态提出行动建议,它返回 ThoughtProcessOutput
。2. execute
:此方法负责执行建议的行动,返回 ActionResult
。
AutoGPT 代理¶
Agent
是 AutoGPT 提供的主要代理。它是 BaseAgent
的子类。它包含所有 内置组件。Agent
实现了 BaseAgent
中基本的抽象方法:propose_action
和 execute
。
构建自己的代理¶
构建自己的代理最简单的方法是扩展 Agent
类并添加额外的组件。这样可以复用现有的组件以及执行 ⚙️ 协议 的默认逻辑。
class MyComponent(AgentComponent):
pass
class MyAgent(Agent):
def __init__(
self,
settings: AgentSettings,
llm_provider: MultiProvider
file_storage: FileStorage,
app_config: AppConfig,
):
# Call the parent constructor to bring in the default components
super().__init__(settings, llm_provider, file_storage, app_config)
# Add your custom component
self.my_component = MyComponent()
如需更多定制,可以覆盖 propose_action
和 execute
方法,甚至直接继承 BaseAgent
类。这样您就可以完全控制代理的组件和行为。有关更多详细信息,请参阅 Agent 的实现。